Ejemplo n.º 1
0
def get(url, name=None):
    url_split = url.split('/')
    if not name:
        name = url_split[-1].replace('.git', '')
    should_grab = True
    for file in os.listdir(os.path.realpath(CONFIG_PATH + '/themes/')):
        if file == name:
            warning(
                "You already have this theme installed! Would you like to overwrite it? Y\\n"
            )
            while True:
                ans = input("> ")
                if ans.lower() == "y":
                    info("Removing Old Theme...")
                    shutil.rmtree(os.path.realpath(CONFIG_PATH + '/themes/' +
                                                   name),
                                  onerror=onerror)
                    break
                elif ans.lower() == "n":
                    should_grab = False
                    break
    if should_grab:
        info('Attempting to Download Theme:', Fore.BLUE + name)
        Repo.clone_from(url, os.path.realpath(CONFIG_PATH + '/themes/' + name))
        success("Completed Theme Download")
Ejemplo n.º 2
0
def configpath():
    info("Config Directory:", CONFIG_PATH)
    with open(CONFIG_PATH + '/config', 'r') as f:
        yaml = YAML(typ='safe')
        config = yaml.load(f)
        for k, v in config.items():
            info(k.upper(), "|", v)
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
 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))
Ejemplo n.º 5
0
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!"
            )
Ejemplo n.º 6
0
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))
Ejemplo n.º 7
0
def update():
    with open(CONFIG_PATH + '/config', 'r') as f:
        yaml = YAML(typ='safe')
        config = yaml.load(f)
        if not config['check_for_updates']:
            res = requests.get(
                'https://raw.githubusercontent.com/M4cs/foxify-cli/master/version'
            ).text
            if config['version'] != res:
                info(
                    "Update Available! Run 'pip3 install --upgrade foxify-cli' to Update to Version: "
                    + res)
Ejemplo n.º 8
0
def tweak_apply(tweak_name):
    match = False
    for file in os.listdir(DEFAULT_TWEAK_PATH):
        if file == tweak_name:
            if os.path.isdir(
                    os.path.realpath(DEFAULT_TWEAK_PATH + "/" +
                                     tweak_name)) and os.path.exists(
                                         os.path.realpath(DEFAULT_TWEAK_PATH +
                                                          "/" + tweak_name)):
                match = True
    if not match:
        get_matches(tweak_name, os.path.realpath(DEFAULT_TWEAK_PATH))
        exit(1)
    info("Applying Tweak")
Ejemplo n.º 9
0
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!"
        )
Ejemplo n.º 10
0
def tweaks():
    tweaks = []
    for file in os.listdir(os.path.realpath(CONFIG_PATH + "/tweaks")):
        if os.path.isdir(os.path.realpath(CONFIG_PATH + "/tweaks/" + file)):
            tweaks.append(file)
    info("Tweak Directory:", os.path.realpath(CONFIG_PATH + "/tweaks"))
    if len(tweaks) > 0:
        info("Available Tweaks:", ', '.join(tweaks))
    else:
        info(
            "Currently No Tweaks. Get Some By Using The 'foxify get tweaks' Command!"
        )
Ejemplo n.º 11
0
def information():
    print(Fore.BLUE + """\
███████╗ ██████╗ ██╗  ██╗██╗███████╗██╗   ██╗
██╔════╝██╔═══██╗╚██╗██╔╝██║██╔════╝╚██╗ ██╔╝
█████╗  ██║   ██║ ╚███╔╝ ██║█████╗   ╚████╔╝ 
██╔══╝  ██║   ██║ ██╔██╗ ██║██╔══╝    ╚██╔╝  
██║     ╚██████╔╝██╔╝ ██╗██║██║        ██║   
╚═╝      ╚═════╝ ╚═╝  ╚═╝╚═╝╚═╝        ╚═╝""")
    info("Version:", version)
    info("Created by Max Bridgland <https://github.com/M4cs>")
    info("Find More FirefoxCSS Themes At These Links:")
    print("https://www.reddit.com/r/FirefoxCSS/")
    print("https://github.com/Timvde/UserChrome-Tweaks")
    print("https://github.com/MrOtherGuy/firefox-csshacks")
    print(Fore.RESET + Style.RESET_ALL)
Ejemplo n.º 12
0
def startup():
    if not os.path.exists(CONFIG_PATH):
        info("Foxify Directory Missing! Creating One For You...")
        os.makedirs(CONFIG_PATH)
    if not os.path.exists(DEFAULT_THEME_PATH):
        os.makedirs(DEFAULT_THEME_PATH)
    if not os.path.exists(DEFAULT_TWEAK_PATH):
        os.makedirs(DEFAULT_TWEAK_PATH)
    if not os.path.exists(DEFAULT_CONFIG):
        while True:
            info("If you have not yet setup userChrome CSS Cusotmization\nPlease Open Up Your Firefox Browser and Follow These Steps:")
            print("""\
1. Go to "about:support" by typing it into your Address Bar

2. Copy the File Path for your Profile Folder

3. Enter it below""")
            filepath = input("> ")
            print("You Entered:", filepath.strip())
            print("Is this correct? Y\\n")
            ans = input("> ")
            if ans.lower() == "y":
                DCONF['active_profile'] = os.path.realpath(filepath.strip())
                info("Writing Default Configuration...")
                with open(DEFAULT_CONFIG, 'w') as f:
                    yaml = YAML()
                    yaml.default_flow_style = False
                    yaml.dump(DCONF, f)
                info("Checking If userChrome CSS Customization is Enabled")
                with open(DCONF['active_profile'] + '/prefs.js', 'r') as f:
                    match = False
                    deact_match = False
                    for line in f.readlines():
                        if line == '"user_pref("toolkit.legacyUserProfileCustomizations.stylesheets", true);"':
                            match = True
                        if line == '"user_pref("toolkit.legacyUserProfileCustomizations.stylesheets", false);"':
                            deact_match = True
                if not match:
                    info('Enabling userChrome CSS Customization')
                    with open(DCONF['active_profile'] + '/prefs.js', 'a') as f:
                        f.write('user_pref("toolkit.legacyUserProfileCustomizations.stylesheets", false);')
                if not match and deact_match:
                    info('Enabling userChrome CSS Customization')
                    with open(DCONF['active_profile'] + '/prefs.js', 'w') as f:
                        content = f.read()
                        content = content.replace('user_pref("toolkit.legacyUserProfileCustomizations.stylesheets", false);', 'user_pref("toolkit.legacyUserProfileCustomizations.stylesheets", true);')
                        f.write()
                info('Checking For Chrome and Backup Directory')
                if not os.path.exists(DCONF['active_profile'] + '/chrome'):
                    os.makedirs(DCONF['active_profile'] + '/chrome')
                if not os.path.exists(DCONF['active_profile'] + '/chrome_backup'):
                    os.makedirs(DCONF['active_profile'] + '/chrome_backup')
                info('Chrome Directory and Backup Directory Created')
                break
            else:
                pass
    else:
        with open(DEFAULT_CONFIG, 'r') as f:
            yaml = YAML(typ='safe')
            config = yaml.load(f)
        if not config.get('config_version'):
            for k, v in DCONF.items():
                if not config.get(k):
                    config[k] = v
            with open(DEFAULT_CONFIG, 'w') as f:
                yaml = YAML()
                yaml.default_flow_style = False
                yaml.dump(config, f)
        if config['config_version'] != CONFIG_VERSION:
            for k, v in DCONF.items():
                if not config.get(k):
                    config[k] = v
            with open(DEFAULT_CONFIG, 'w') as f:
                yaml = YAML()
                yaml.default_flow_style = False
                yaml.dump(config, f)
        if config['check_for_updates']:
            res = requests.get('https://raw.githubusercontent.com/M4cs/foxify-cli/master/version').text
            if res == version:
                config['version'] = version
                with open(DEFAULT_CONFIG, 'w') as f:
                    yaml = YAML()
                    yaml.default_flow_style = False
                    yaml.dump(config, f)
            else:
                info("Update Available! Run 'pip3 install --upgrade foxify-cli' to Update to Version: " + res)
Ejemplo n.º 13
0
def getversion():
    info("Foxify v" + version)
    exit(0)
Ejemplo n.º 14
0
def themes():
    themes = ""
    for file in os.listdir(os.path.realpath(CONFIG_PATH + "/themes")):
        themes = themes + file + ", "
    info("Theme Directory:", os.path.realpath(CONFIG_PATH + "/themes"))
    info("Available Themes:", themes[:-2])
Ejemplo n.º 15
0
def clear():
    while True:
        warning(
            "You are about to remove your current theme. Would you like to back it up? Y\\n"
        )
        ans = input("> ")
        if ans.lower() == "y":
            warning("Backing Up Files!")
            with open(CONFIG_PATH + '/config', 'r') as f:
                yaml = YAML(typ='safe')
                config = yaml.load(f)
                profile_dir = config['active_profile']
                for file in tqdm(os.listdir(
                        os.path.realpath(profile_dir + '/chrome_backup')),
                                 ncols=35,
                                 smoothing=True,
                                 bar_format=Fore.LIGHTCYAN_EX + Style.BRIGHT +
                                 "[PROGRESS] " + Fore.RESET + Style.RESET_ALL +
                                 '{n_fmt}/{total_fmt} | {bar}'):
                    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))
            backup()
            warning("Starting Theme Removal!")
            with open(CONFIG_PATH + '/config', 'r') as f:
                yaml = YAML(typ='safe')
                config = yaml.load(f)
                profile_dir = config['active_profile']
                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}'):
                    if os.path.isdir(
                            os.path.join(
                                os.path.realpath(profile_dir + '/chrome'),
                                file)):
                        shutil.rmtree(
                            os.path.join(
                                os.path.realpath(profile_dir + '/chrome'),
                                file))
                    else:
                        os.remove(
                            os.path.join(
                                os.path.realpath(profile_dir + '/chrome'),
                                file))
            break
        elif ans.lower() == "n":
            warning("Starting Theme Removal!")
            with open(CONFIG_PATH + '/config', 'r') as f:
                yaml = YAML(typ='safe')
                config = yaml.load(f)
                profile_dir = config['active_profile']
                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}'):
                    if os.path.isdir(
                            os.path.join(
                                os.path.realpath(profile_dir + '/chrome'),
                                file)):
                        shutil.rmtree(
                            os.path.join(
                                os.path.realpath(profile_dir + '/chrome'),
                                file))
                    else:
                        os.remove(
                            os.path.join(
                                os.path.realpath(profile_dir + '/chrome'),
                                file))
            break
        else:
            warning("Unknown Option Please Try Again!")
    info("Attempting to Kill 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!")
    else:
        info(
            "Couldn't find a process for Firefox, if you are running it you may have to close it manually!"
        )
    config = {}
    with open(CONFIG_PATH + '/config', 'r') as f:
        yaml = YAML(typ='safe')
        config = yaml.load(f)
        config['active_theme'] = 'default'
    with open(CONFIG_PATH + '/config', 'w') as f:
        yaml = YAML()
        yaml.default_flow_style = False
        yaml.dump(config, f)
Ejemplo n.º 16
0
def get_tweaks():
    info("Attempting To Open: https://github.com/Timvde/UserChrome-Tweaks")
    open_new_tab("https://github.com/Timvde/UserChrome-Tweaks")
Ejemplo n.º 17
0
def restore():
    warning(
        "You are about to restore from your backup! This means all current custom files will be restored with older ones.\nAre you sure you want to continue? Y\\n"
    )
    ans = input("> ")
    if ans.lower() == "y":
        with open(CONFIG_PATH + '/config', 'r') as f:
            yaml = YAML(typ='safe')
            config = yaml.load(f)
            profile_dir = config['active_profile']
            info("Deleting Current Customization Files...")
            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}'):
                if os.path.isdir(
                        os.path.join(os.path.realpath(profile_dir + '/chrome'),
                                     file)):
                    shutil.rmtree(
                        os.path.join(os.path.realpath(profile_dir + '/chrome'),
                                     file))
                else:
                    os.remove(
                        os.path.join(os.path.realpath(profile_dir + '/chrome'),
                                     file))
            info("Starting Restore Process...")
            for file in tqdm(os.listdir(
                    os.path.realpath(profile_dir + '/chrome_backup')),
                             ncols=35,
                             smoothing=True,
                             bar_format=Fore.LIGHTCYAN_EX + Style.BRIGHT +
                             "[PROGRESS] " + Fore.RESET + Style.RESET_ALL +
                             '{n_fmt}/{total_fmt} | {bar}'):
                if os.path.isdir(
                        os.path.join(
                            os.path.realpath(profile_dir + '/chrome_backup'),
                            file)):
                    shutil.copytree(
                        os.path.join(
                            os.path.realpath(profile_dir + '/chrome_backup'),
                            file),
                        os.path.realpath(profile_dir + '/chrome/' + file))
                else:
                    shutil.copy(
                        os.path.join(
                            os.path.realpath(profile_dir + '/chrome_backup'),
                            file),
                        os.path.realpath(profile_dir + '/chrome/' + file))
            success("Completed Restore Process, Killing 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!"
                )