82 lines
2.5 KiB
Python
82 lines
2.5 KiB
Python
import sys
|
|
import logging
|
|
import docopt
|
|
|
|
|
|
usage = '''
|
|
Usage:
|
|
autoimport copy SRC_PATH DST_PATH [options]
|
|
autoimport move SRC_PATH DST_PATH [options]
|
|
autoimport placeholders
|
|
autoimport select SRC_PATH [options]
|
|
|
|
Options:
|
|
-t <specifer> --path-template=<specifer> The template for creating the new directory structure
|
|
[default: <DateTime.year>/<DateTime.month>/<DateTime.day>]
|
|
-n --no-select-stop-on-error Do not stop selecting files when an error occurs.
|
|
-w --walk Walk the directory tree when selecting files.
|
|
-p <postfix> --postfix=<postfix> Comma separated list of postfixes for files to look for when
|
|
selecting files [default: JPG,NEF].
|
|
-d --dry-run Do not write changes.
|
|
-v --verbose Generate more output.
|
|
-D --debug Turn on debug messages.
|
|
-i <dbtype> --implementation=<dbtype> Internal database type (mem|disk) [default: mem]
|
|
|
|
|
|
|
|
'''
|
|
|
|
from .commands import copy, move, placeholders, select
|
|
from .tmpdb import get_temporary_db
|
|
|
|
args = docopt.docopt(usage)
|
|
|
|
if(args["--verbose"]):
|
|
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.INFO)
|
|
if(args["--debug"]):
|
|
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG)
|
|
|
|
logging.debug("ARGUMENTS:")
|
|
for k,v in args.items():
|
|
logging.debug("\t{}: \t{}".format(k,v))
|
|
|
|
try:
|
|
db = get_temporary_db(args["--implementation"])
|
|
except Exception as e:
|
|
print(e)
|
|
sys.exit(1)
|
|
|
|
if(args["placeholders"]):
|
|
result = placeholders()
|
|
elif(args["copy"]):
|
|
result = copy(db
|
|
, args["SRC_PATH"]
|
|
, args["DST_PATH"]
|
|
, args["--path-template"]
|
|
, not args["--no-select-stop-on-error"]
|
|
, args["--walk"]
|
|
, args["--postfix"]
|
|
, args["--dry-run"])
|
|
|
|
elif(args["move"]):
|
|
result = move(db
|
|
, args["SRC_PATH"]
|
|
, args["DST_PATH"]
|
|
, args["--path-template"]
|
|
, not args["--no-select-stop-on-error"]
|
|
, args["--walk"]
|
|
, args["--postfix"]
|
|
, args["--dry-run"])
|
|
elif(args["select"]):
|
|
result = select(db
|
|
, args["SRC_PATH"]
|
|
, not args["--no-select-stop-on-error"]
|
|
, args["--walk"]
|
|
, args["--postfix"]
|
|
, args["--dry-run"])
|
|
|
|
|
|
|
|
db.close()
|
|
sys.exit(result)
|