Run BleachBit cleaners directly and allow cleaning

* Using the cleaner names to ensure desired cleanup
  * Using the --preset option could lead to unintended deletions
* Cleaning is automatic in D7_MODE
This commit is contained in:
2Shirt 2018-08-19 15:18:29 -07:00
parent 9c1c8b90be
commit 6f3a1ee55f
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C
2 changed files with 104 additions and 24 deletions

View file

@ -368,23 +368,38 @@ def run_aida64():
'/TEXT', '/SILENT', '/SAFEST']
run_program(cmd, check=False)
def run_bleachbit():
def run_bleachbit(cleaners=None, preview=True):
"""Run BleachBit preview and save log.
This is a preview so no files should be deleted."""
if not os.path.exists(global_vars['LogDir']+r'\BleachBit.log'):
debug_path = r'{}\BleachBit.debug'.format(global_vars['LogDir'])
error_path = debug_path.replace('debug', 'err')
log_path = debug_path.replace('debug', 'log')
extract_item('BleachBit', silent=True)
cmd = [global_vars['Tools']['BleachBit'], '--preview', '--preset']
# Safety check
if not cleaners:
# Disable cleaning and use preset config
cleaners = ['--preset']
preview = True
# Run
cmd = [
global_vars['Tools']['BleachBit'],
'--preview' if preview else '--clean',
'--debug-log="{}"'.format(debug_path)]
cmd.extend(cleaners)
out = run_program(cmd, check=False)
# Save stderr
if out.stderr.decode().splitlines():
with open(global_vars['LogDir']+r'\BleachBit.err', 'a',
encoding='utf-8') as f:
with open(error_path, 'a', encoding='utf-8') as f:
for line in out.stderr.decode().splitlines():
f.write(line.strip() + '\n')
# Save stdout
with open(global_vars['LogDir']+r'\BleachBit.log', 'a',
encoding='utf-8') as f:
with open(log_path, 'a', encoding='utf-8') as f:
for line in out.stdout.decode().splitlines():
f.write(line.strip() + '\n')

View file

@ -18,6 +18,65 @@ global_vars['LogFile'] = r'{LogDir}\System Diagnostics.log'.format(
D7_MODE = 'd7mode' in sys.argv
ERRORS = 0
# Static Variables
BLEACH_BIT_CLEANERS = {
'Applications': (
'adobe_reader.cache',
'adobe_reader.tmp',
'amule.tmp',
'flash.cache',
'gimp.tmp',
'hippo_opensim_viewer.cache',
'java.cache',
'libreoffice.cache',
'liferea.cache',
'miro.cache',
'openofficeorg.cache',
'pidgin.cache',
'secondlife_viewer.Cache',
'thunderbird.cache',
'vuze.backup_files',
'vuze.cache',
'vuze.tmp',
'yahoo_messenger.cache',
),
'Browsers': (
'chromium.cache',
'chromium.current_session',
'chromium.history',
'firefox.cache',
'firefox.download_history',
'firefox.session_restore',
'firefox.url_history',
'google_chrome.cache',
'google_chrome.history',
'google_chrome.session',
'google_earth.temporary_files',
'google_toolbar.search_history',
'internet_explorer.history',
'internet_explorer.temporary_files',
'opera.cache',
'opera.current_session',
'opera.download_history',
'opera.url_history',
'safari.cache',
'safari.history',
'seamonkey.cache',
'seamonkey.download_history',
'seamonkey.history',
),
'System': (
'system.clipboard',
'system.tmp',
'winapp2_windows.jump_lists',
'winapp2_windows.ms_search',
'windows_explorer.run',
'windows_explorer.search_history',
'windows_explorer.thumbnails',
),
}
def check_result(result, other_results):
"""Check result for warnings and errors."""
if not result['CS']:
@ -93,12 +152,18 @@ if __name__ == '__main__':
print_info('Scanning for browsers')
scan_for_browsers()
# Run BleachBit cleaners
print_info('BleachBit Cleanup')
for k, v in sorted(BLEACH_BIT_CLEANERS.items()):
try_and_print(message=' {}...'.format(k),
function=run_bleachbit,
cs='Done', other_results=other_results,
cleaners=v, preview=bool(not D7_MODE))
# Export system info
print_info('Backup System Information')
try_and_print(message='AIDA64 reports...',
function=run_aida64, cs='Done', other_results=other_results)
try_and_print(message='BleachBit report...',
function=run_bleachbit, cs='Done', other_results=other_results)
if not D7_MODE:
backup_browsers()
try_and_print(message='File listing...',