Beispiel #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")
Beispiel #2
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!"
            )
Beispiel #3
0
def clear_backup():
    warning(
        "You are about to clear your backup! This means all backup files will be deleted.\nAre you sure you want to continue? Y\\n"
    )
    ans = input("> ")
    if ans.lower() == "y":
        warning("Starting Backup Deletion!")
        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))
        success("Deletion Complete.")
    else:
        warning("Skipping Backup Clearing")
Beispiel #4
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)
Beispiel #5
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!"
                )