コード例 #1
0
ファイル: cli.py プロジェクト: aaronkollasch/photomanager
def _stats(db: Union[str, PathLike]):
    config_logging()
    database = Database.from_file(db)
    num_uids, num_photos, num_stored_photos, total_file_size = database.get_stats(
    )
    print(f"Total items:        {num_photos}")
    print(f"Total unique items: {num_uids}")
    print(f"Total stored items: {num_stored_photos}")
    print(f"Total file size:    {sizeof_fmt(total_file_size)}")
コード例 #2
0
ファイル: cli.py プロジェクト: aaronkollasch/photomanager
def _create(
    db: Union[str, PathLike],
    hash_algorithm: str = DEFAULT_HASH_ALGO,
    timezone_default: str = "local",
    debug: bool = False,
):
    config_logging(debug=debug)
    try:
        database = Database.from_file(db)
    except FileNotFoundError:
        database = Database()
    database.hash_algorithm = HashAlgorithm(hash_algorithm)
    database.db["timezone_default"] = timezone_default
    database.save(path=db, argv=sys.argv, force=True)
コード例 #3
0
ファイル: cli.py プロジェクト: aaronkollasch/photomanager
def _import(
    db: Union[str, PathLike],
    destination: Union[str, PathLike],
    source: Optional[Union[str, PathLike]] = None,
    file: Optional[Union[str, PathLike]] = None,
    paths: Iterable[Union[str, PathLike]] = tuple(),
    exclude: Iterable[str] = tuple(),
    skip_existing: bool = False,
    debug: bool = False,
    dry_run: bool = False,
    priority: int = 10,
    timezone_default: Optional[str] = None,
    storage_type: str = "HDD",
    collect_db: bool = False,
):
    config_logging(debug=debug)
    database = Database.from_file(db, create_new=True)
    skip_existing = set(database.sources) if skip_existing else set()
    filtered_files = fileops.list_files(
        source=source,
        file=file,
        exclude=exclude,
        exclude_files=skip_existing,
        paths=paths,
    )
    index_result = actions.index(
        database=database,
        files=filtered_files,
        priority=priority,
        timezone_default=timezone_default,
        storage_type=storage_type,
    )
    collect_result = actions.collect(
        database=database,
        destination=destination,
        dry_run=dry_run,
        filter_uids=index_result["changed_uids"] if skip_existing else None,
    )
    if not dry_run:
        database.save(path=db,
                      argv=sys.argv,
                      collect_db=collect_db,
                      destination=destination)
    click_exit(1 if index_result["num_error_photos"]
               or collect_result["num_missed_photos"]
               or collect_result["num_error_photos"] else 0)
コード例 #4
0
ファイル: cli.py プロジェクト: aaronkollasch/photomanager
def _clean(
    db: Union[str, PathLike],
    destination: Union[str, PathLike],
    subdir: Union[str, PathLike] = "",
    debug: bool = False,
    dry_run: bool = False,
):
    config_logging(debug=debug)
    database = Database.from_file(db)
    result = actions.clean(
        database=database,
        destination=destination,
        subdir=subdir,
        dry_run=dry_run,
    )
    if not dry_run:
        database.save(path=db, argv=sys.argv)
    click_exit(1 if result["num_missing_photos"] else 0)
コード例 #5
0
ファイル: cli.py プロジェクト: aaronkollasch/photomanager
def _verify(
    db: Union[str, PathLike],
    destination: Union[str, PathLike],
    subdir: Union[str, PathLike] = "",
    storage_type: str = "HDD",
    random_fraction: Optional[float] = None,
    debug: bool = False,
):
    config_logging(debug=debug)
    database = Database.from_file(db)
    result = actions.verify(
        database=database,
        directory=destination,
        subdir=subdir,
        storage_type=storage_type,
        random_fraction=random_fraction,
    )
    click_exit(1 if result["num_incorrect_photos"]
               or result["num_missing_photos"] else 0)
コード例 #6
0
ファイル: cli.py プロジェクト: aaronkollasch/photomanager
def _collect(
    db: Union[str, PathLike],
    destination: Union[str, PathLike],
    debug: bool = False,
    dry_run: bool = False,
    collect_db: bool = False,
):
    config_logging(debug=debug)
    database = Database.from_file(db)
    collect_result = actions.collect(database=database,
                                     destination=destination,
                                     dry_run=dry_run)
    if not dry_run:
        database.save(path=db,
                      argv=sys.argv,
                      collect_db=collect_db,
                      destination=destination)
    click_exit(1 if collect_result["num_missed_photos"]
               or collect_result["num_error_photos"] else 0)
コード例 #7
0
ファイル: cli.py プロジェクト: aaronkollasch/photomanager
def _index(
    db: Union[str, PathLike],
    source: Optional[Union[str, PathLike]] = None,
    file: Optional[Union[str, PathLike]] = None,
    paths: Iterable[Union[str, PathLike]] = tuple(),
    exclude: Iterable[str] = tuple(),
    skip_existing: bool = False,
    debug: bool = False,
    dry_run: bool = False,
    priority: int = 10,
    timezone_default: Optional[str] = None,
    storage_type: str = "HDD",
):
    if not source and not file and not paths:
        print("Nothing to index")
        print(click.get_current_context().get_help())
        click_exit(1)
    config_logging(debug=debug)
    database = Database.from_file(db, create_new=True)
    skip_existing = set(database.sources) if skip_existing else set()
    filtered_files = fileops.list_files(
        source=source,
        file=file,
        exclude=exclude,
        exclude_files=skip_existing,
        paths=paths,
    )
    index_result = actions.index(
        database=database,
        files=filtered_files,
        priority=priority,
        timezone_default=timezone_default,
        storage_type=storage_type,
    )
    if not dry_run:
        database.save(path=db, argv=sys.argv)
    click_exit(1 if index_result["num_error_photos"] else 0)