Exemplo n.º 1
0
def index_local(paths):
    """
    Index all local files.

    Indexing files enables analyses on them such as statistics and dupe detection.
    The given paths must be configured paths in the user's .backuper/config.json
    If no paths are given, then all configured paths are indexed.
    """
    path_set = set(paths)

    tsv_file_path = cfg.get_relative_to_config_path('local.index.tsv')
    print(tsv_file_path)

    config = cfg.load()
    base_path = config['base_path']
    base_excludes = config['excludes']

    with open(tsv_file_path, 'w', newline='') as fp:
        writer = csv.writer(fp, delimiter='\t')
        writer.writerow(['config_path', 'rel_path'])

        for (path_spec, _, dir_path, _) in iter_sync_dirs():
            cur_cfg_path = path_spec['path']

            # not paths means include all paths
            if not paths or cur_cfg_path in path_set:
                for abs_path in files.scan_files(dir_path, excludes=base_excludes):
                    writer.writerow([cur_cfg_path, os.path.relpath(abs_path, start=dir_path)])
Exemplo n.º 2
0
def iter_sync_dirs(single_select=False):
    """
    :param single_select: if True prompts user to select a single path_spec from those configured in their
    .backuper/config.json

    :return: a generator of tuples (path_spec, base_excludes, local_path, dest) where:
      - path_spec is the current entry in the user's .backuper/config.json:paths
      - base_excludes is a list of aws s3 sync ['--exclude', 'pattern', '--exclude', 'pattern', ,,,] arguments
      - dir_path is the local computed absolute path of the current path_spec
      - dest is the remote s3 destination prefix of the current path_spec
    """
    config = cfg.load()

    base_buckey = config['dest']['base_buckey']

    base_excludes = []
    for exclude in config['excludes']:
        base_excludes.extend(['--exclude', exclude])

    base_path = config['base_path']
    paths = config['paths']

    if single_select:
        for index, path_spec in enumerate(paths):
            print(index, path_spec)
        selected = input('Which path would you sync? Enter number. ')
        paths = [paths[int(selected)], ]

    for path_spec in paths:
        path_segment = path_spec['path']
        dir_path = base_path + path_segment
        # The base_path is not included in the dest key.
        dest = base_buckey + path_segment

        yield (path_spec, base_excludes, dir_path, dest)
Exemplo n.º 3
0
def validate_config():
    """
    Validate and print configuration.
    """
    log.err('Config at', cfg.CONFIG_PATH)
    print(json.dumps(cfg.load(), indent=2))