-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete_user.py
More file actions
61 lines (50 loc) ยท 2.05 KB
/
delete_user.py
File metadata and controls
61 lines (50 loc) ยท 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import os
import pickle
import argparse
import shutil
import subprocess
# ๊ฒฝ๋ก ์ค์
DATA_DIR = r'D:\DATA'
train_emb_file = 'train_embeddings.pkl'
val_emb_file = 'val_embeddings.pkl'
label_to_id_file = 'label_to_id.pkl'
def delete_user(pid, remove_folder=False):
# ํ์ผ ๋ก๋ฉ
try:
with open(train_emb_file, 'rb') as f: train_emb = pickle.load(f)
with open(val_emb_file, 'rb') as f: val_emb = pickle.load(f)
with open(label_to_id_file, 'rb') as f: label2id = pickle.load(f)
except FileNotFoundError:
print("[์ค๋ฅ] ์๋ฒ ๋ฉ ๋๋ ๋ผ๋ฒจ ํ์ผ์ด ์กด์ฌํ์ง ์์ต๋๋ค.")
return
if pid not in label2id:
print(f"[์ค๋ฅ] ์ฌ์ฉ์ '{pid}' ๋ ๋ฑ๋ก๋์ด ์์ง ์์ต๋๋ค.")
return
print(f"[์ญ์ ] ์ฌ์ฉ์ '{pid}' ๋ฐ์ดํฐ ์ ๊ฑฐ ์ค...")
# ์ญ์
label2id.pop(pid, None)
train_emb.pop(pid, None)
val_emb.pop(pid, None)
# ์ ์ฅ
with open(train_emb_file, 'wb') as f: pickle.dump(train_emb, f)
with open(val_emb_file, 'wb') as f: pickle.dump(val_emb, f)
with open(label_to_id_file, 'wb') as f: pickle.dump(label2id, f)
# ํด๋ ์ญ์ (์ต์
)
user_dir = os.path.join(DATA_DIR, pid)
if remove_folder and os.path.exists(user_dir):
shutil.rmtree(user_dir)
print(f"[์ญ์ ] ์ฌ์ฉ์ ํด๋๋ ์ ๊ฑฐ๋จ: {user_dir}")
# ์๋ ์ฌํ์ต
print("[์ฌํ์ต] ์ฌ์ฉ์ ์ ๊ฑฐ ๋ฐ์ ์ค...")
try:
subprocess.run(['python', 'train_arcface.py'], check=True)
print("โ
๋ถ๋ฅ๊ธฐ ์ฌํ์ต ์๋ฃ.")
except subprocess.CalledProcessError:
print("โ ๏ธ ๋ถ๋ฅ๊ธฐ ์ฌํ์ต ์ค ์ค๋ฅ ๋ฐ์!")
print(f"โ
์ฌ์ฉ์ '{pid}' ๋ฐ์ดํฐ ์ญ์ ์๋ฃ.")
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--pid', type=str, required=True, help='์ญ์ ํ ์ฌ์ฉ์ ID')
parser.add_argument('--remove_folder', action='store_true', help='ํด๋น ํด๋๊น์ง ์ญ์ ํ ๊ฒฝ์ฐ ์ง์ ')
args = parser.parse_args()
delete_user(args.pid, args.remove_folder)