Ejemplo n.º 1
0
 def test_list_files_file(self, datafiles, caplog):
     """
     list_files will return a file provided with the file argument
     """
     caplog.set_level(logging.DEBUG)
     files = fileops.list_files(file=str(datafiles / "img1.png"))
     print(files)
     assert set(files.keys()) == {
         str(datafiles / "img1.png"),
     }
Ejemplo n.º 2
0
 def test_list_files_source(self, datafiles, caplog):
     """
     list_files lists a directory in the source argument
     """
     caplog.set_level(logging.DEBUG)
     files = fileops.list_files(source=str(datafiles / "A"))
     print(files)
     assert set(files.keys()) == {
         str(datafiles / "A" / "img1.jpg"),
         str(datafiles / "A" / "img1.png"),
         str(datafiles / "A" / "img2.jpg"),
         str(datafiles / "A" / "img4.jpg"),
     }
Ejemplo n.º 3
0
 def test_list_files_stdin_file(self, datafiles, caplog):
     """
     list_files accepts multiple files piped to stdin when file == "-"
     """
     caplog.set_level(logging.DEBUG)
     runner = CliRunner()
     with runner.isolation(
             input=f"{datafiles / 'img1.png'}\n{datafiles / 'img1.jpg'}\n"):
         files = fileops.list_files(file="-")
     print(files)
     assert set(files.keys()) == {
         str(datafiles / "img1.jpg"),
         str(datafiles / "img1.png"),
     }
Ejemplo n.º 4
0
 def test_list_files_paths_exclude(self, datafiles, caplog):
     """
     The list_files exclude argument removes filenames matching the patterns
     """
     caplog.set_level(logging.DEBUG)
     files = fileops.list_files(paths=[str(datafiles)],
                                exclude=["img1", ".tiff"])
     print(files)
     assert set(files.keys()) == {
         str(datafiles / "A" / "img2.jpg"),
         str(datafiles / "A" / "img4.jpg"),
         str(datafiles / "B" / "img2.jpg"),
         str(datafiles / "B" / "img4.jpg"),
     }
Ejemplo n.º 5
0
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)
Ejemplo n.º 6
0
 def test_list_files_stdin_source(self, datafiles, caplog):
     """
     list_files accepts multiple directories piped to stdin when source == "-"
     """
     caplog.set_level(logging.DEBUG)
     runner = CliRunner()
     with runner.isolation(input=str(datafiles / "A") + "\n" +
                           str(datafiles / "B") + "\n"):
         files = fileops.list_files(source="-")
     print(files)
     assert set(files.keys()) == {
         str(datafiles / "A" / "img1.jpg"),
         str(datafiles / "A" / "img1.png"),
         str(datafiles / "A" / "img2.jpg"),
         str(datafiles / "A" / "img4.jpg"),
         str(datafiles / "B" / "img1.jpg"),
         str(datafiles / "B" / "img2.jpg"),
         str(datafiles / "B" / "img4.jpg"),
     }
Ejemplo n.º 7
0
 def test_list_files_exclude_files(self, datafiles, caplog):
     """
     list_files excludes files with exact paths provided to exclude_files
     """
     caplog.set_level(logging.DEBUG)
     files = fileops.list_files(
         source=str(datafiles / "A"),
         exclude_files=[
             str(datafiles) + "/A/img1.jpg",
             datafiles / "A" / "img4.jpg",
             "A/img1.png",
             "img2.jpg",
         ],
     )
     print(files)
     assert set(files.keys()) == {
         str(datafiles / "A" / "img1.png"),
         str(datafiles / "A" / "img2.jpg"),
     }
Ejemplo n.º 8
0
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)