Updated browsers.py
This commit is contained in:
parent
18b13cf506
commit
7f7c220073
1 changed files with 72 additions and 19 deletions
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
from functions.common import *
|
from functions.common import *
|
||||||
|
|
||||||
|
from operator import itemgetter
|
||||||
|
|
||||||
# Define other_results for later try_and_print
|
# Define other_results for later try_and_print
|
||||||
browser_data = {}
|
browser_data = {}
|
||||||
other_results = {
|
other_results = {
|
||||||
|
|
@ -101,16 +103,63 @@ SUPPORTED_BROWSERS = {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def archive_all_users():
|
||||||
|
"""Create backups for all browsers for all users."""
|
||||||
|
users_root = r'{}\Users'.format(global_vars['Env']['SYSTEMDRIVE'])
|
||||||
|
user_envs = []
|
||||||
|
|
||||||
|
# Build list of valid users
|
||||||
|
for user_name in os.listdir(users_root):
|
||||||
|
valid_user = True
|
||||||
|
if user_name in ('Default', 'Default User'):
|
||||||
|
# Skip default users
|
||||||
|
continue
|
||||||
|
user_path = os.path.join(users_root, user_name)
|
||||||
|
appdata_local = os.path.join(user_path, r'AppData\Local')
|
||||||
|
appdata_roaming = os.path.join(user_path, r'AppData\Roaming')
|
||||||
|
valid_user &= os.path.exists(appdata_local)
|
||||||
|
valid_user &= os.path.exists(appdata_roaming)
|
||||||
|
if valid_user:
|
||||||
|
user_envs.append({
|
||||||
|
'USERNAME': user_name,
|
||||||
|
'USERPROFILE': user_path,
|
||||||
|
'APPDATA': appdata_roaming,
|
||||||
|
'LOCALAPPDATA': appdata_local})
|
||||||
|
|
||||||
|
# Backup browsers for all valid users
|
||||||
|
print_info('Backing up browsers')
|
||||||
|
for fake_env in sorted(user_envs, key=itemgetter('USERPROFILE')):
|
||||||
|
print_standard(' {}'.format(fake_env['USERNAME']))
|
||||||
|
for b_k, b_v in sorted(SUPPORTED_BROWSERS.items()):
|
||||||
|
if b_k == 'Mozilla Firefox Dev':
|
||||||
|
continue
|
||||||
|
source_path = b_v['user_data_path'].format(**fake_env)
|
||||||
|
if not os.path.exists(source_path):
|
||||||
|
continue
|
||||||
|
source_items = source_path + '*'
|
||||||
|
archive_path = r'{BackupDir}\Browsers ({USERNAME})\{Date}'.format(
|
||||||
|
**global_vars, **fake_env)
|
||||||
|
os.makedirs(archive_path, exist_ok=True)
|
||||||
|
archive_path += r'\{}.7z'.format(b_k)
|
||||||
|
cmd = [
|
||||||
|
global_vars['Tools']['SevenZip'],
|
||||||
|
'a', '-aoa', '-bso0', '-bse0', '-mx=1',
|
||||||
|
archive_path, source_items]
|
||||||
|
try_and_print(message='{}...'.format(b_k),
|
||||||
|
function=run_program, cmd=cmd)
|
||||||
|
print_standard(' ')
|
||||||
|
|
||||||
def archive_browser(name):
|
def archive_browser(name):
|
||||||
"""Create backup of Browser saved in the BackupDir."""
|
"""Create backup of Browser saved in the BackupDir."""
|
||||||
source = '{}*'.format(browser_data[name]['user_data_path'])
|
source = '{}*'.format(browser_data[name]['user_data_path'])
|
||||||
dest = r'{BackupDir}\Browsers ({USERNAME})'.format(
|
dest = r'{BackupDir}\Browsers ({USERNAME})\{Date}'.format(
|
||||||
**global_vars, **global_vars['Env'])
|
**global_vars, **global_vars['Env'])
|
||||||
archive = r'{}\{}.7z'.format(dest, name)
|
archive = r'{}\{}.7z'.format(dest, name)
|
||||||
os.makedirs(dest, exist_ok=True)
|
os.makedirs(dest, exist_ok=True)
|
||||||
cmd = [
|
cmd = [
|
||||||
global_vars['Tools']['SevenZip'],
|
global_vars['Tools']['SevenZip'],
|
||||||
'a', '-aoa', '-bso0', '-bse0', '-mx=1',
|
'a', '-aoa', '-bso0', '-bse0', '-mx=1',
|
||||||
|
'-mhe=on', '-p{}'.format(ARCHIVE_PASSWORD),
|
||||||
archive, source]
|
archive, source]
|
||||||
run_program(cmd)
|
run_program(cmd)
|
||||||
|
|
||||||
|
|
@ -332,9 +381,11 @@ def get_mozilla_profiles(search_path, dev=False):
|
||||||
|
|
||||||
return profiles
|
return profiles
|
||||||
|
|
||||||
def install_adblock(indent=8, width=32):
|
def install_adblock(indent=8, width=32, just_firefox=False):
|
||||||
"""Install adblock for all supported browsers."""
|
"""Install adblock for all supported browsers."""
|
||||||
for browser in sorted(browser_data):
|
for browser in sorted(browser_data):
|
||||||
|
if just_firefox and browser_data[browser]['base'] != 'mozilla':
|
||||||
|
continue
|
||||||
exe_path = browser_data[browser].get('exe_path', None)
|
exe_path = browser_data[browser].get('exe_path', None)
|
||||||
function=run_program
|
function=run_program
|
||||||
if not exe_path:
|
if not exe_path:
|
||||||
|
|
@ -444,9 +495,11 @@ def reset_browsers(indent=8, width=32):
|
||||||
indent=indent, width=width, function=function,
|
indent=indent, width=width, function=function,
|
||||||
other_results=other_results, profile=profile)
|
other_results=other_results, profile=profile)
|
||||||
|
|
||||||
def scan_for_browsers():
|
def scan_for_browsers(just_firefox=False):
|
||||||
"""Scan system for any supported browsers."""
|
"""Scan system for any supported browsers."""
|
||||||
for name in sorted(SUPPORTED_BROWSERS):
|
for name, details in sorted(SUPPORTED_BROWSERS.items()):
|
||||||
|
if just_firefox and details['base'] != 'mozilla':
|
||||||
|
continue
|
||||||
try_and_print(message='{}...'.format(name),
|
try_and_print(message='{}...'.format(name),
|
||||||
function=get_browser_details, cs='Detected',
|
function=get_browser_details, cs='Detected',
|
||||||
other_results=other_results, name=name)
|
other_results=other_results, name=name)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue