102 lines
3.1 KiB
Python
102 lines
3.1 KiB
Python
'''
|
|
|
|
Clean the direction in CML Server (tmp2 or home directory)
|
|
|
|
|
|
Suppose that the CLEAN_PATH may seems like this.
|
|
And we will only check the directories & files under the user directory with "depth=1"
|
|
|
|
CLEAN_PATH
|
|
|
|
|
+---- user1 (user directory)
|
|
| |
|
|
| +--- file1 (depth=1, will be check)
|
|
| |
|
|
| +--- Project1 (depth=1, will be check)
|
|
| | |
|
|
| | +--- subset1-1 (depth=2, won't be check)
|
|
| |
|
|
| +--- Project2 (depth=1)
|
|
| |
|
|
| +--- subset2-1 (depth=2)
|
|
| |
|
|
| +--- subset2-2 (depth=2)
|
|
|
|
|
+---- user2 (user directory)
|
|
|
|
|
+--- Project1 (depth=1)
|
|
|
|
|
+--- subset1-1 (depth=2)
|
|
|
|
'''
|
|
|
|
from mailer import Mailer
|
|
from cleaner import Cleaner
|
|
import os
|
|
|
|
|
|
CLEAN_PATH = "/home/master/12"
|
|
KEEP_FILES = [".bashrc", ".bash_logout", ".bash_profile", "public-html", ".ssh", ".profile", "examples.desktop", ".bash_history", ".config", ".zshrc", ".vimrc", ".gnupg", ".oh-my-zsh", ".vim", ".viminfo", ".vscode-server", ".gitconfig", ".local", ".zsh_history", ".zsh_profile"]
|
|
WHITE_LIST = ["mysql", "unix_manager", "unixmanager215", "gangxing", "how083012", "yulunliu", "amie12349", "minliwu", "chenyuyang", "unixmanager5xx"]
|
|
|
|
DATE = '2024-02-01'
|
|
|
|
GOOGLE_OWNER = "snsd0805@cmlab.csie.ntu.edu.tw"
|
|
GOOGLE_CODE = os.environ['GOOGLE_CODE']
|
|
|
|
|
|
def get_master():
|
|
ans = []
|
|
for year in os.listdir(f'/home/master/'):
|
|
if os.path.isdir(f'/home/master/{year}'):
|
|
for user in os.listdir(f'/home/master/{year}'):
|
|
ans.append(f'/home/master/{year}/{user}')
|
|
return ans
|
|
|
|
def get_phd():
|
|
ans = []
|
|
for dir_name in os.listdir(f'/home/phd/'):
|
|
if dir_name.isnumeric():
|
|
year = dir_name
|
|
for user in os.listdir(f'/home/phd/{year}'):
|
|
ans.append(f'/home/phd/{year}/{user}')
|
|
else:
|
|
ans.append(f'/home/phd/{dir_name}')
|
|
return ans
|
|
|
|
def get_ra():
|
|
ans = []
|
|
for user in os.listdir(f'/home/ra/'):
|
|
ans.append(f'/home/ra/{user}')
|
|
return ans
|
|
|
|
def get_extra():
|
|
ans = []
|
|
for user in os.listdir(f'/home/extra/'):
|
|
ans.append(f'/home/extra/{user}')
|
|
return ans
|
|
|
|
|
|
def main(clean_type, test=True, send_mail=False):
|
|
mailer = Mailer(GOOGLE_OWNER, GOOGLE_CODE)
|
|
|
|
if clean_type == 'home':
|
|
student_list = []
|
|
for student_type in ['master', 'phd', 'ra', 'extra']:
|
|
func = globals()[f'get_{student_type}']
|
|
student_list += func()
|
|
|
|
for index, student_dir in enumerate(student_list):
|
|
print(f'{index+1}/{len(student_list)} {student_dir}')
|
|
cleaner = Cleaner(student_dir, "2024-02-01", mailer, WHITE_LIST, KEEP_FILES)
|
|
cleaner.run(test=test, send_mail=send_mail)
|
|
|
|
# mailer.send('unix_manager@cmlab.csie.ntu.edu.tw', 'snsd0805@cmlab.csie.ntu.edu.tw', '[測試郵件] test', 'Test mail')
|
|
|
|
# cleaner = Cleaner('/home/master/12', "2024/02/01", mailer, WHITE_LIST, KEEP_FILES)
|
|
# cleaner.run(test=test, send_mail=send_mail)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main('home', test=False, send_mail=True)
|