예제 #1
0
def maybe_first_time_setup():
    """
    Set up the user's notes directory/folder the first time they run
    NoteBag.

    Returns False if it failed, or needs to try again; returns True if
    it succeeds, or doesn't need to happen at all.
    """

    if not os.path.isfile(get_config_path(CONFIG_FILENAME)):
        shutil.copy2(get_config_path(TEMPLATE_CONFIG_FILENAME),
                     get_config_path(CONFIG_FILENAME))

    config = read_config(CONFIG_FILENAME)
    if config.get("NoteBag", "Notes Directory"):
        return True

    if not messagebox.askokcancel(
            "NoteBag Setup",
            "Hi! It looks like this is your first time running NoteBag!\n"
            "Please choose the folder where you would like NoteBag to keep your notes."
    ):
        return False

    notes_dir = filedialog.askdirectory(title="Notes Folder")
    print(notes_dir)
    if not notes_dir:
        return False

    config.set("NoteBag", "Notes Directory", notes_dir)
    save_config(config, CONFIG_FILENAME)
    return True
예제 #2
0
def maybe_first_time_setup():
    """
    Set up the user's notes directory/folder the first time they run
    NoteBag.

    Returns False if it failed, or needs to try again; returns True if
    it succeeds, or doesn't need to happen at all.
    """

    if not os.path.isfile(get_config_path(CONFIG_FILENAME)):
        shutil.copy2(get_config_path(TEMPLATE_CONFIG_FILENAME),
                     get_config_path(CONFIG_FILENAME))

    config = read_config(CONFIG_FILENAME)
    if config.get("NoteBag", "Notes Directory"):
       return True

    if not messagebox.askokcancel(
            "NoteBag Setup",
            "Hi! It looks like this is your first time running NoteBag!\n"
            "Please choose the folder where you would like NoteBag to keep your notes."
            ):
        return False

    notes_dir = filedialog.askdirectory(title="Notes Folder")
    print(notes_dir)
    if not notes_dir:
        return False

    config.set("NoteBag", "Notes Directory", notes_dir)
    save_config(config, CONFIG_FILENAME)
    return True
예제 #3
0
def main(inventory_file, deployment_file, api_key):
    key = getattr(constants, api_key)
    print('API key gathered')

    inventory = helpers.parse_yaml(inventory_file)
    print('Inventory file "{}" parsed.'.format(inventory_file))

    deployment = helpers.parse_yaml("deployments/" + deployment_file)
    print('Deployment file "{}" parsed.'.format(deployment_file))

    for device, details in deployment.items():
        generated_config = helpers.generate_cfg_from_template(
            "templates/" + details['template'], details['data'])
        print('\n\tConfig for "{}" generated.'.format(device))

        prepared_config = helpers.prep_config(generated_config, key)
        print('\tConfig prepared.')

        print('\tPushing config to "{}"'.format(device))
        r = helpers.post_config(inventory[device]['address'], prepared_config)

        print('\tReturned result is "{}"'.format(r.text))

        print('\tSaving configuration...')
        r = helpers.save_config(inventory[device]['address'], key)
        print('\tReturned result is "{}"'.format(r.text))
예제 #4
0
    def save_config(self):
        """
        Save NoteBag's current configuration to its config file.
        """

        save_config(self.config, CONFIG_FILENAME)
예제 #5
0
    def save_config(self):
        """
        Save NoteBag's current configuration to its config file.
        """

        save_config(self.config, CONFIG_FILENAME)