From 21154e884f3358e744ec5df8bf840db215266c8c Mon Sep 17 00:00:00 2001 From: "beville@gmail.com" Date: Tue, 27 Nov 2012 18:55:31 +0000 Subject: [PATCH] First pass at file naming via CLI git-svn-id: http://comictagger.googlecode.com/svn/trunk@98 6c5673fe-1810-88d6-992b-cd32ca31540c --- comictagger.py | 68 +++++++++++++++++++++++++++++++++++++++++++++++--- options.py | 4 ++- 2 files changed, 68 insertions(+), 4 deletions(-) diff --git a/comictagger.py b/comictagger.py index 7e31f79..c9107e6 100755 --- a/comictagger.py +++ b/comictagger.py @@ -219,7 +219,7 @@ def process_file_cli( filename, opts, settings ): # ok, done building our metadata. time to save #HACK - #opts.dryrun = True + opts.dryrun = True #HACK if not opts.dryrun: @@ -229,8 +229,70 @@ def process_file_cli( filename, opts, settings ): print "dry-run option was set, so nothing was written, but here is the final set of tags:" print u"{0}".format(md) - elif opt.rename_file: - print "File renaming TBD" + elif opts.rename_file: + + md = GenericMetadata() + # First read in existing data, if it's there + if opts.data_style == MetaDataStyle.CIX and cix: + md = ca.readCIX() + elif opts.data_style == MetaDataStyle.CBI and cbi: + md = ca.readCBI() + + if md.isEmpty: + print "Comic archive contains no tags!" + + if opts.data_style == MetaDataStyle.CIX: + if cix: + md = ca.readCIX() + else: + print "Comic archive contains no ComicRack tags!" + + if opts.data_style == MetaDataStyle.CBI: + if cbi: + md = ca.readCBI() + else: + print "Comic archive contains no ComicBookLover tags!" + + # TODO move this to ComicArchive, or maybe another class??? + new_name = "" + if md.series is not None: + new_name += "{0}".format( md.series ) + else: + print "Can't rename without series name" + return + + if md.volume is not None: + new_name += " v{0}".format( md.volume ) + + if md.issue is not None: + new_name += " #{0}".format( md.issue ) + else: + print "Can't rename without issue number" + return + + if md.issueCount is not None: + new_name += " (of {0})".format( md.issueCount ) + + if md.year is not None: + new_name += " ({0})".format( md.year ) + + if ca.isZip: + new_name += ".cbz" + elif ca.isRar(): + new_name += ".cbr" + + #HACK + opts.dryrun = True + #HACK + + if not opts.dryrun: + # write out the new data + #ca.rename() + pass + else: + print "dry-run option was set, so nothing was changed, but here is the proposed filename:" + print "'{0}'".format(new_name) + diff --git a/options.py b/options.py index 457b371..6a17ad3 100644 --- a/options.py +++ b/options.py @@ -68,7 +68,7 @@ If no options are given, {0} will run in windowed mode escape an "=" or a ",", ash show in the example above Some names that can be used: series, issue, issueCount, year, publisher, title - -r, --rename Rename the file based on metadata as indicated. TBD! + -r, --rename Rename the file based on specified tag style. -a, --abort Abort save operation when online match is of low confidence TBD! -v, --verbose Be noisy when doing what it does -h, --help Display this message @@ -220,4 +220,6 @@ If no options are given, {0} will run in windowed mode if self.save_tags and self.data_style is None: self.display_help_and_quit( "Please specify the type to save with -t", 1 ) + if self.rename_file and self.data_style is None: + self.display_help_and_quit( "Please specify the type to use for renaming with -t", 1 )