Passed
Push — master ( 816317...cc1553 )
by John
03:01
created

bbarchivist.scripts.filehasher   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 36
dl 0
loc 51
rs 10
c 0
b 0
f 0
wmc 2

1 Function

Rating   Name   Duplication   Size   Complexity  
A filehasher_main() 0 31 2
1
#!/usr/bin/env python3
2
"""Applies hash functions to files."""
3
4
import os  # path operations
5
import sys  # load arguments
6
7
from bbarchivist import argutils  # arguments
8
from bbarchivist import hashutils  # main program
9
from bbarchivist import utilities  # input validation
10
11
__author__ = "Thurask"
12
__license__ = "WTFPL v2"
13
__copyright__ = "2015-2018 Thurask"
14
15
16
def filehasher_main():
17
    """
18
    Parse arguments from argparse/questionnaire.
19
20
    Invoke :func:`bbarchivist.hashutils.verifier` with those arguments.
21
    """
22
    hashdict = hashutils.verifier_config_loader()
23
    hashutils.verifier_config_writer(hashdict)
24
    if len(sys.argv) > 1:
25
        parser = argutils.default_parser("bb-filehasher", "Hash files")
26
        parser.add_argument(
27
            "folder",
28
            help="Working directory, default is local",
29
            nargs="?",
30
            default=None,
31
            type=argutils.file_exists)
32
        parser.add_argument(
33
            "-s",
34
            "--selective",
35
            dest="selective",
36
            help="Filter out files generated by this package",
37
            default=False,
38
            action="store_true")
39
        parser.set_defaults()
40
        args = parser.parse_args(sys.argv[1:])
41
        args.folder = utilities.dirhandler(args.folder, os.getcwd())
42
        hashutils.verifier(args.folder, hashdict)
43
    else:
44
        folder = os.getcwd()
45
        print(" ")
46
        hashutils.verifier(folder, hashdict)
47
48
49
if __name__ == "__main__":
50
    filehasher_main()
51