def apply(theme_name): if os.path.exists(os.path.realpath(CONFIG_PATH + "/themes/" + theme_name)): info("Applying " + theme_name + " to Firefox...") with open(CONFIG_PATH + '/config', 'r') as f: yaml = YAML(typ='safe') config = yaml.load(f) profile_dir = config['active_profile'] if theme_name == config['active_theme']: error('That theme is already active!') exit(1) for file in tqdm(os.listdir( os.path.realpath(CONFIG_PATH + '/themes/' + theme_name)), ncols=35, smoothing=True, bar_format=Fore.LIGHTCYAN_EX + Style.BRIGHT + "[PROGRESS] " + Fore.RESET + Style.RESET_ALL + '{n_fmt}/{total_fmt} | {bar}'): if file != ".git": if os.path.isdir( os.path.join( os.path.realpath(CONFIG_PATH + '/themes/' + theme_name), file)): shutil.copytree( os.path.join( os.path.realpath(CONFIG_PATH + '/themes/' + theme_name), file), os.path.realpath(profile_dir + '/chrome/' + file)) else: shutil.copy( os.path.join( os.path.realpath(CONFIG_PATH + '/themes/' + theme_name), file), os.path.realpath(profile_dir + '/chrome/' + file)) success("Applied Theme Closing Firefox...") if check_for_process("firefox"): if platform == "linux" or platform == "linux2" or platform == "darwin": subprocess.call(['killall', 'firefox'], stdout=FNULL, stderr=subprocess.STDOUT) elif platform == "win32": subprocess.call(['taskkill', '/f', '/im', 'firefox.exe'], stdout=FNULL, stderr=subprocess.STDOUT) success("Closed Firefox! Re-open to see your new theme!") else: info( "Couldn't find a process for Firefox, if you are running it you may have to close it manually!" ) with open(CONFIG_PATH + '/config', 'r') as f: yaml = YAML(typ='safe') config = yaml.load(f) config['active_theme'] = theme_name with open(CONFIG_PATH + '/config', 'w') as f: yaml = YAML() yaml.default_flow_style = False yaml.dump(config, f) else: error("No Theme Found: " + theme_name) exit(1)
def onerror(func, path, exc_info): import stat if not os.access(path, os.W_OK): os.chmod(path, stat.S_IWUSR) func(path) else: error("Couldn't Remove The File!") exit(1)
def get_matches(self, arg): matches = process.extractBests(arg, self.accepted_args, limit=2) if not matches: error("Unknown Argument:", arg) else: m = [] for match in matches: m.append(match[0]) error("Unknown Argument:", arg) info("Possible Matches:", ', '.join(m))
def backup(): info("Backing Up Old Files") profile_dir = "" with open(CONFIG_PATH + '/config', 'r') as f: yaml = YAML(typ='safe') config = yaml.load(f) profile_dir = config['active_profile'] if profile_dir: try: if len( os.listdir( os.path.realpath(profile_dir + '/chrome_backup/'))) >= 1: warning("Removing Prior Backup...") for file in os.listdir( os.path.realpath(profile_dir + '/chrome_backup/')): if os.path.isdir( os.path.join( os.path.realpath(profile_dir + '/chrome_backup'), file)): shutil.rmtree( os.path.join( os.path.realpath(profile_dir + '/chrome_backup'), file)) else: os.remove( os.path.join( os.path.realpath(profile_dir + '/chrome_backup'), file)) for file in tqdm(os.listdir( os.path.realpath(profile_dir + '/chrome')), ncols=35, smoothing=True, bar_format=Fore.LIGHTCYAN_EX + Style.BRIGHT + "[PROGRESS] " + Fore.RESET + Style.RESET_ALL + '{n_fmt}/{total_fmt} | {bar}'): sleep(0.001) full_name = os.path.join( os.path.realpath(profile_dir + '/chrome'), file) if os.path.isdir(full_name): shutil.copytree( full_name, os.path.realpath(profile_dir + '/chrome_backup/' + file)) else: shutil.copy( full_name, os.path.realpath(profile_dir + '/chrome_backup/' + file)) success("Backed Up Files") except FileExistsError: error( "Please Run 'foxify backup-clear' and remove your old backup first!" )
def get_matches(tweak_name, path): matches = process.extractBests(tweak_name, os.listdir(path)) if not matches: error("Unknown Tweak Name:", tweak_name) else: m = [] for match in matches: m.append(match[0]) error("Unknown Tweak Name:", tweak_name) if len(m) > 0: info("Possible Matches:", ', '.join(m))
def remove(name): match = False for file in os.listdir(os.path.realpath(CONFIG_PATH + '/themes/')): if file == name: match = True if match: info("Removing:", name) shutil.rmtree(os.path.realpath(CONFIG_PATH + '/themes/' + name), onerror=onerror) success("Removed Theme") else: error( "No Theme By That Name Found. Run 'foxify themes' to see available themes!" )
def run_args(self): for arg in self.args: if "remove" == arg: remove(self.args[self.args.index('remove') + 1]) if "get" == arg: if self.args[self.args.index('get') + 1] == "tweaks": get_tweaks() else: if self.args[self.args.index('get') + 1] not in self.accepted_args: if self.args[self.args.index('get') + 1].startswith('http') or self.args[self.args.index('get') + 1].startswith('git'): if self.args[self.args.index('get') + 2] not in self.accepted_args: get(self.args[self.args.index('get') + 1], self.args[self.args.index('get') + 2]) else: get(self.args[self.args.index('get') + 1]) else: error("Malformed URL. Please Use An http(s):// or git:// URL") exit(1) else: error("Missing URL or Correct Commands Afterwards") if "clear" == arg: clear() if "tweaks" == arg: if self.args[self.args.index('tweaks') - 1] != 'get': tweaks() if "backup" == arg: backup() if "backup-clear" == arg: clear_backup() if "apply" == arg: if not "backup" in self.args: error("Please Prefix Apply with Backup in Order to Apply New Themes!") exit(1) if not self.args.index('backup') < self.args.index('apply'): error("Please Prefix Apply with Backup in Order to Apply New Themes!") exit(1) theme_name = self.args[self.args.index('apply') + 1] apply(theme_name) if "restore" == arg: restore() if "themes" == arg: themes() if "version" == arg: getversion() if "help" == arg: helpmenu() if "config" == arg: configpath() if "info" == arg: information() if "update" == arg: update()