''' 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 src.mailer import Mailer from src.cleaner import Cleaner from src.users import * import os from constant import GOOGLE_OWNER GOOGLE_CODE = os.environ['GOOGLE_CODE'] def main(clean_type, remove=False, notify=False): mailer = Mailer(GOOGLE_OWNER, GOOGLE_CODE) if clean_type == 'home': student_list = [] # find all student's path for student_type in ['master', 'phd', 'ra', 'extra']: func = globals()[f'get_{student_type}'] student_list += func() # start clean for index, student_dir in enumerate(student_list): print(f'{index+1}/{len(student_list)} {student_dir}') cleaner = Cleaner(student_dir, mailer) cleaner.run(remove=remove, notify=notify) elif clean_type == 'tmp': for main_dir in ['/tmp2', '/tmp3']: student_list = [] if os.path.isdir(main_dir): for user in os.listdir(f"{main_dir}/"): if os.path.isdir(f"{main_dir}/{user}/"): student_list.append(f"{main_dir}/{user}/") for index, student_dir in enumerate(student_list): print(f'{index+1}/{len(student_list)} {student_dir}') cleaner = Cleaner(student_dir, mailer) cleaner.run(remove=remove, notify=notify) if __name__ == "__main__": main('tmp', remove=False, notify=False)