From 26199cf271d306ccf664594fbc4f6f9108132957 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 19 Mar 2019 20:31:00 -0600 Subject: [PATCH] Detect and update browsers in Install SW Bundle * Fixes issue #65 --- .bin/Scripts/functions/browsers.py | 21 +++++++++++++++++---- .bin/Scripts/functions/setup.py | 13 +++++++++++-- .bin/Scripts/install_sw_bundle.py | 10 +++++++--- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/.bin/Scripts/functions/browsers.py b/.bin/Scripts/functions/browsers.py index 7d042989..9f51b1e6 100644 --- a/.bin/Scripts/functions/browsers.py +++ b/.bin/Scripts/functions/browsers.py @@ -388,6 +388,12 @@ def install_adblock(indent=8, width=32, just_firefox=False): cmd=[exe_path, *urls], check=False) +def is_installed(browser_name): + """Checks if browser is installed based on exe_path, returns bool.""" + browser_name = browser_name.replace(' Chromium', '') + return bool(browser_data.get(browser_name, {}).get('exe_path', False)) + + def list_homepages(indent=8, width=32): """List current homepages for reference.""" browser_list = [k for k, v in sorted(browser_data.items()) if v['exe_path']] @@ -437,16 +443,23 @@ def reset_browsers(indent=8, width=32): other_results=other_results, profile=profile) -def scan_for_browsers(just_firefox=False, skip_ie=False): +def scan_for_browsers(just_firefox=False, silent=False, skip_ie=False): """Scan system for any supported browsers.""" for name, details in sorted(SUPPORTED_BROWSERS.items()): if just_firefox and details['base'] != 'mozilla': continue if skip_ie and details['base'] == 'ie': continue - try_and_print(message='{}...'.format(name), - function=get_browser_details, cs='Detected', - other_results=other_results, name=name) + if silent: + try: + get_browser_details(name) + except Exception: + # Ignore errors in silent mode + pass + else: + try_and_print(message='{}...'.format(name), + function=get_browser_details, cs='Detected', + other_results=other_results, name=name) if __name__ == '__main__': diff --git a/.bin/Scripts/functions/setup.py b/.bin/Scripts/functions/setup.py index 76fdc1db..7c2062ac 100644 --- a/.bin/Scripts/functions/setup.py +++ b/.bin/Scripts/functions/setup.py @@ -1,5 +1,6 @@ # Wizard Kit: Functions - Setup +from functions.browsers import * from functions.update import * from settings.setup import * from settings.sources import * @@ -239,10 +240,18 @@ def install_firefox_extensions(): run_program(cmd) -def install_ninite_bundle(mse=False, libreoffice=False): +def install_ninite_bundle(browsers_only=False, mse=False, libreoffice=False): """Run Ninite installer(s), returns list of Popen objects.""" popen_objects = [] - if global_vars['OS']['Version'] in ('8', '8.1', '10'): + if browsers_only: + installer_path = r'{BaseDir}\Installers\Extras\Web Browsers'.format( + **global_vars) + scan_for_browsers(skip_ie=True, silent=True) + for browser in ('Google Chrome', 'Mozilla Firefox', 'Opera Chromium'): + if is_installed(browser): + cmd = r'{}\{}.exe'.format(installer_path, browser) + popen_objects.append(popen_program(cmd)) + elif global_vars['OS']['Version'] in ('8', '8.1', '10'): # Modern selection popen_objects.append( popen_program(r'{BaseDir}\Installers\Extras\Bundles\Modern.exe'.format( diff --git a/.bin/Scripts/install_sw_bundle.py b/.bin/Scripts/install_sw_bundle.py index a12a3a00..25f45638 100644 --- a/.bin/Scripts/install_sw_bundle.py +++ b/.bin/Scripts/install_sw_bundle.py @@ -28,7 +28,7 @@ if __name__ == '__main__': answer_extensions = D7_MODE or ask('Install Extensions?') answer_vcr = D7_MODE or ask('Install Visual C++ Runtimes?') if D7_MODE: - answer_ninite = False + answer_ninite = True answer_mse = False else: answer_ninite = ask('Install Ninite Bundle?') @@ -42,9 +42,13 @@ if __name__ == '__main__': if answer_vcr: install_vcredists() if answer_ninite: - result = try_and_print(message='Ninite bundle...', + message='Ninite bundle...' + if D7_MODE: + message='Updating browsers...' + result = try_and_print(message=message, function=install_ninite_bundle, cs='Started', - mse=answer_mse, other_results=other_results) + browsers_only=D7_MODE, mse=answer_mse, + other_results=other_results) for proc in result['Out']: # Wait for all processes to finish proc.wait()