From cc29a824e6d83164dab740cd98313a4795cf5e1f Mon Sep 17 00:00:00 2001 From: B Stack Date: Thu, 25 Feb 2021 17:02:46 -0500 Subject: improve generate.py * Add ability to choose subdir name format. * Add day (D) as a variable to use. * Add ability to use other exif date tags, and filename, to determine the date to use. Timestamp is a last-resort option only! * Change output of the cli equivalent actions to stdout (from stderr). --- generate.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'generate.py') diff --git a/generate.py b/generate.py index 49ed27f..22ff18e 100755 --- a/generate.py +++ b/generate.py @@ -7,19 +7,28 @@ # Usage: # ./generate.py -i /mnt/bgstack15/Backups/bgstack15/Images/Photos/camera/2018/ -o /mnt/public/www/gallery/my2018 -n -d2 -x 'October' -s --nr -from argparse import ArgumentParser +from argparse import ArgumentParser, RawDescriptionHelpFormatter from genlib import * -generate_version="2021-01-29a" +generate_version="2021-02-25a" # WORKHERE the if __main__ thing: -parser = ArgumentParser(description="Make symlink forest for images") # epilog="something" +parser = ArgumentParser(description="Make symlink forest for images", + formatter_class=RawDescriptionHelpFormatter, + epilog="""FORMATTING +Format string will be interpreted as a python f-string, so wrap variable +names with curly braces. +Default format is "{Y}/{M}" + + {Y} is 4-digit year + {M} is month (affected by padding) + {D} is day (affected by padding)""") parser.add_argument("-d","--debug",nargs='?', default=0, type=int, choices=range(0,11), help="Set debug level") parser.add_argument("-v","--version", action="version", version="%(prog)s " + generate_version) g_dryrun = parser.add_mutually_exclusive_group() g_dryrun.add_argument("-n","--dryrun", action="store_true", help="Make no changes (default)") g_dryrun.add_argument("-a","--apply", action="store_true", help="Actually make changes") g_zeropad = parser.add_mutually_exclusive_group() -g_zeropad.add_argument("-z","-0","--zeropad",action="store_true", help="Zero pad month directories (default)") +g_zeropad.add_argument("-z","-0","--zeropad",action="store_true", help="Zero pad month and day strings (default)") g_zeropad.add_argument("--nz","--nozeropad","--no-zeropad",action="store_true", help="Do not zero pad") g_action = parser.add_mutually_exclusive_group() g_action.add_argument("-c","--copy", action="store_true", help="Copy files instead of symlinks. Not recommended.") @@ -31,6 +40,7 @@ g_relative.add_argument("--nr","--norelative","--no-relative", action="store_tru parser.add_argument("-i","--indir",required=True) parser.add_argument("-o","--outdir",required=True) parser.add_argument("-x","--exclude",action="append",help="Exclude pathname matches. Can be used multiple times.") +parser.add_argument("-f","--format",action="store",default="{Y}/{M}",help="Subdirectories should follow this pattern. See FORMATTING heading.") # pull useful values out of the argparse entry args = parser.parse_args() @@ -58,6 +68,7 @@ try: except: # no exclusions pass +subdirformat=args.format if debuglevel >= 10: eprint(args) @@ -75,9 +86,10 @@ these_files = limit( ) print("FOUND FILE COUNT:",len(these_files)) -make_YM_forest( +make_forest( outdir, these_files, + subdirformat = subdirformat, action = action, dryrun = dryrun, debuglevel = debuglevel, -- cgit