Added actual file renaming

git-svn-id: http://comictagger.googlecode.com/svn/trunk@167 6c5673fe-1810-88d6-992b-cd32ca31540c
This commit is contained in:
beville 2012-11-30 03:21:05 +00:00
parent c445cdddd9
commit e776d2fd3b
4 changed files with 33 additions and 16 deletions

View File

@ -193,7 +193,7 @@ def process_file_cli( filename, opts, settings ):
if result == ii.ResultNoMatches:
pass
elif result == ii.ResultFoundMatchButBadCoverScore:
#low_confidence = True
low_confidence = True
found_match = True
elif result == ii.ResultFoundMatchButNotFirstPage :
found_match = True
@ -208,7 +208,7 @@ def process_file_cli( filename, opts, settings ):
if choices:
print "Online search: Multiple matches. Save aborted"
return
if low_confidence:
if low_confidence and opts.abortOnLowConfidence:
print "Online search: Low confidence match. Save aborted"
return
if not found_match:
@ -228,7 +228,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:
@ -293,17 +293,23 @@ def process_file_cli( filename, opts, settings ):
elif ca.isRar():
new_name += ".cbr"
if new_name == os.path.basename(filename):
print "Filename is already good!"
return
folder = os.path.dirname( os.path.abspath( filename ) )
new_abs_path = utils.unique_file( os.path.join( folder, new_name ) )
#HACK
opts.dryrun = True
#opts.dryrun = True
#HACK
if not opts.dryrun:
# write out the new data
#ca.rename()
pass
# rename the file
os.rename( filename, new_abs_path )
else:
print "dry-run option was set, so nothing was changed, but here is the proposed filename:"
print "'{0}'".format(new_name)
print "'{0}'".format(new_abs_path)
@ -324,9 +330,9 @@ def main():
signal.signal(signal.SIGINT, signal.SIG_DFL)
if not qt_available:
if not qt_available and not opts.no_gui:
opts.no_gui = True
print "QT is not available. Running in text mode"
print "QT is not available."
if opts.no_gui:
cli_mode( opts, settings )

View File

@ -69,7 +69,7 @@ If no options are given, {0} will run in windowed mode
Some names that can be used:
series, issue, issueCount, year, publisher, title
-r, --rename Rename the file based on specified tag style.
-a, --abort Abort save operation when online match is of low confidence TBD!
--noabort Don't abort save operation when online match is of low confidence
-v, --verbose Be noisy when doing what it does
-h, --help Display this message
"""
@ -85,6 +85,7 @@ If no options are given, {0} will run in windowed mode
self.delete_tags = False
self.search_online = False
self.dryrun = False
self.abortOnLowConfidence = True
self.save_tags = False
self.parse_filename = False
self.raw = False
@ -159,7 +160,8 @@ If no options are given, {0} will run in windowed mode
try:
opts, args = getopt.getopt( input_args,
"hpdt:fm:vonsr",
[ "help", "print", "delete", "type=", "parsefilename", "metadata=", "verbose", "online", "dryrun", "save", "rename" , "raw" ])
[ "help", "print", "delete", "type=", "parsefilename", "metadata=", "verbose",
"online", "dryrun", "save", "rename" , "raw", "noabort" ])
except getopt.GetoptError as err:
self.display_help_and_quit( str(err), 2 )
@ -188,6 +190,8 @@ If no options are given, {0} will run in windowed mode
self.parse_filename = True
if o in ("--raw"):
self.raw = True
if o in ("--noabort"):
self.abortOnLowConfidence = False
if o in ("-t", "--type"):
if a.lower() == "cr":
self.data_style = MetaDataStyle.CIX

View File

@ -16,10 +16,7 @@ Better volume icon for Mac
-----------------------------------------------------
Bugs
-----------------------------------------------------
Enable write and rename on command-line
Rename - check for existence, and add (#)
Fix QT not available message
Add abort/not abort
-----------------------------------------------------
Future

View File

@ -73,6 +73,16 @@ def removearticles( text ):
return newText
def unique_file(file_name):
counter = 1
file_name_parts = os.path.splitext(file_name) # returns ('/path/file', '.ext')
while 1:
if not os.path.lexists( file_name):
return file_name
file_name = file_name_parts[0] + '_' + str(counter) + file_name_parts[1]
counter += 1
# -o- coding: utf-8 -o-
# ISO639 python dict
# oficial list in http://www.loc.gov/standards/iso639-2/php/code_list.php