diff --git a/.bin/Scripts/functions/cleanup.py b/.bin/Scripts/functions/cleanup.py index c02e3665..f2986571 100644 --- a/.bin/Scripts/functions/cleanup.py +++ b/.bin/Scripts/functions/cleanup.py @@ -68,6 +68,73 @@ def cleanup_cbs(dest_folder): r'{}\CbsPersist*'.format(temp_folder)] run_program(cmd) +def cleanup_d7ii(): + """Sort d7II logs and remove temp items.""" + d7_path = r'{}\d7II'.format(global_vars['ClientDir']) + d7_reports = r'{}_Reports'.format(d7_path) + d7_temp = r'{}\Temp'.format(d7_path) + + # Logs & Reports + if os.path.exists(d7_reports): + for entry in os.scandir(d7_reports): + r = re.match(r'(\d+)-(\d+)-(\d+)', entry.name) + d7_date = '{}-{:02d}-{:02d}'.format( + r.group(1), int(r.group(2)), int(r.group(3))) + d7_mlogs = r'{}\Malware Logs'.format(entry.path) + log_dest = r'{SYSTEMDRIVE}\{prefix}\Info\{date}'.format( + prefix=KIT_NAME_SHORT, + date=d7_date, + **global_vars['Env']) + + # Remove empty folders + for f in ('Malware Logs', 'Screen Shots'): + try: + os.rmdir(r'{}\{}'.format(entry.path, f)) + except FileNotFoundError: + pass + except OSError: + pass + + # Malware Logs + if os.path.exists(d7_mlogs): + for m_entry in os.scandir(d7_mlogs): + prefix = '' + if m_entry.name == 'MalwareScan_Report.txt': + prefix = 'd7II_' + dest_path = r'{log_dest}\{prefix}{name}'.format( + log_dest=log_dest, + prefix=prefix, + name=m_entry.name) + dest_path = non_clobber_rename(dest_path) + shutil.move(entry.path, dest_path) + try: + os.rmdir(d7_mlogs) + except OSError: + pass + + # Other items + for o_entry in os.scandir(entry.path): + dest_path = r'{log_dest}\d7II_{name}'.format( + log_dest=log_dest, + name=m_entry.name) + dest_path = non_clobber_rename(dest_path) + shutil.move(entry.path, dest_path) + + # Remove folder if empty + try: + os.rmdir(entry.path) + except OSError: + pass + + # Temp items + if os.path.exists(d7_path): + if os.path.exists(d7_temp): + shutil.rmtree(d7_temp) + try: + os.rmdir(d7_path) + except OSError: + pass + def cleanup_desktop(): """Move known backup files and reports into the ClientDir.""" dest_folder = r'{ProgBackupDir}\{Date}\Desktop'.format(**global_vars) diff --git a/.bin/Scripts/d7_firefox_fix.py b/.bin/Scripts/post_d7.py similarity index 78% rename from .bin/Scripts/d7_firefox_fix.py rename to .bin/Scripts/post_d7.py index 7fe1f244..1bdfc4f3 100644 --- a/.bin/Scripts/d7_firefox_fix.py +++ b/.bin/Scripts/post_d7.py @@ -1,4 +1,4 @@ -# Wizard Kit: Install uBlock Origin for Firefox +# Wizard Kit: Post-d7II items import os import sys @@ -10,16 +10,15 @@ from functions.browsers import * from functions.cleanup import * from functions.setup import * init_global_vars() -os.system('title {}: User Checklist Tool'.format(KIT_NAME_FULL)) +os.system('title {}: Post-d7II Work'.format(KIT_NAME_FULL)) global_vars['LogFile'] = r'{LogDir}\User Checklist ({USERNAME}).log'.format( **global_vars, **global_vars['Env']) -D7_MODE = 'd7mode' in sys.argv if __name__ == '__main__': try: stay_awake() clear_screen() - print_info('{}: Firefox Fix for d7\n'.format(KIT_NAME_FULL)) + print_info('{}: Post-d7II Work\n'.format(KIT_NAME_FULL)) other_results = { 'Warning': { 'NotInstalledError': 'Not installed', @@ -34,6 +33,11 @@ if __name__ == '__main__': print_info('Installing uBlock Origin') install_adblock(just_firefox=True) + # Cleanup + print_info('Cleanup') + try_and_print(message='d7II...', + function=cleanup_d7ii, cs='Done') + # Done print_standard('\nDone.') pause('Press Enter to exit...')