ascmitc / mhl

ASC Media Hash List
MIT License
58 stars 8 forks source link

Remove requirement for root folder when verifying / adding single files #118

Open jmccdev opened 2 years ago

jmccdev commented 2 years ago

The data used for this is under /sources/104_verification_types/104n/ within the dataset on the G-Drive: https://drive.google.com/drive/folders/1PrAPczRFBQsVfjakbX-fqnDVHsAD-kd1

I created the ASC MHL History with: ascmhl create -h md5 16421225_Day001/

Using the verify command on a single file in that dataset results in a Missing ASC MHL History error:

$ ascmhl verify 16421225_Day001/Camera_Media/A007_0124J4/A007_0124J4.RDM/A007_C001_0124UA.RDC/A007_C001_0124UA_001.R3D 
Error: Missing ASC MHL history at path /Users/jmccormick/Documents/knowledgebase/asc-mhl/ascmhl_dataset_20220208/expected_results/104/104n/16421225_Day001/Camera_Media/A007_0124J4/A007_0124J4.RDM/A007_C001_0124UA.RDC/A007_C001_0124UA_001.R3D

Using the create command on a single file in that dataset, in order to verify it AND create a new MHL generation to record that verification, results in a NotADirectoryError:

$ ascmhl create -h md5 16421225_Day001/Camera_Media/A007_0124J4/A007_0124J4.RDM/A007_C001_0124UA.RDC/A007_C001_0124UA_001.R3D 
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/bin/ascmhl", line 11, in <module>
    sys.exit(mhltool_cli())
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ascmhl/commands.py", line 96, in create
    create_for_folder_subcommand(root_path, verbose, hash_format, no_directory_hashes, ignore_list, ignore_spec_file)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ascmhl/commands.py", line 137, in create_for_folder_subcommand
    for folder_path, children in post_order_lexicographic(root_path, session.ignore_spec.get_path_spec()):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ascmhl/traverse.py", line 27, in post_order_lexicographic
    names = os.listdir(top)
NotADirectoryError: [Errno 20] Not a directory: '/Users/jmccormick/Documents/knowledgebase/asc-mhl/ascmhl_dataset_20220208/expected_results/104/104n/16421225_Day001/Camera_Media/A007_0124J4/A007_0124J4.RDM/A007_C001_0124UA.RDC/A007_C001_0124UA_001.R3D'

Maybe it is unreasonable for the ascmhl tool to transverse up the directory tree until it finds an ascmhl directory, so maybe the tool could allow you to specify the location of the appropriate ASC MHL History when trying to verify a single file, or a subset of data.

ptrpfn commented 2 years ago

Both the verify and the create commands have an option -sf PATH or --single_file PATH to verify or add single files (you can have multiple -sf PATH options in one call). These options are implemented as additional options of the verify and the create commands which require also a root path of the ASC MHL History to be passed in.

This is not the most elegant solution, but the current command line parsing framework Click does not allow to make the root path mandatory for some options and optional for other options (such as the -sf PATH option). We looked at this already, but it would have been a major refactoring and/or redesign of the commands in order to fix this.

So to verify a single file use..

% ascmhl verify -v -sf /path/to/root-folder/and/file.txt /path/to/root-folder

... and add a single file use...

% ascmhl create -v -sf /path/to/root-folder/and/file.txt /path/to/root-folder

As this is more a design question (and the feature works for now as described above and documented with the --help option) I would propose to add a "postpone" tag to this issue for now. I also refined the title of the issue.