Compare commits

...

9 Commits

Author SHA1 Message Date
47d8da0e80 removed extra line
git-svn-id: http://comictagger.googlecode.com/svn/trunk@615 6c5673fe-1810-88d6-992b-cd32ca31540c
2013-04-22 02:37:13 +00:00
0f7e88e58c bump to 1.1.8-beta
git-svn-id: http://comictagger.googlecode.com/svn/trunk@614 6c5673fe-1810-88d6-992b-cd32ca31540c
2013-04-22 00:49:20 +00:00
65902a15b1 add-on script for renaming files based on transform list
git-svn-id: http://comictagger.googlecode.com/svn/trunk@613 6c5673fe-1810-88d6-992b-cd32ca31540c
2013-04-21 06:55:32 +00:00
a68b2babeb some reworking so scripts get passed all options after scriptname
git-svn-id: http://comictagger.googlecode.com/svn/trunk@612 6c5673fe-1810-88d6-992b-cd32ca31540c
2013-04-21 06:53:44 +00:00
4098802e43 sleep 1 sec before retrying after http 500 error
git-svn-id: http://comictagger.googlecode.com/svn/trunk@611 6c5673fe-1810-88d6-992b-cd32ca31540c
2013-04-21 06:51:43 +00:00
9c14258e9f verify need to check version in GUI
git-svn-id: http://comictagger.googlecode.com/svn/trunk@610 6c5673fe-1810-88d6-992b-cd32ca31540c
2013-04-17 18:10:08 +00:00
33bdbe8be8 verify need to check version in CLI
git-svn-id: http://comictagger.googlecode.com/svn/trunk@609 6c5673fe-1810-88d6-992b-cd32ca31540c
2013-04-17 18:09:43 +00:00
a76864c109 be a little smarted in colon replacement in renaming
git-svn-id: http://comictagger.googlecode.com/svn/trunk@608 6c5673fe-1810-88d6-992b-cd32ca31540c
2013-04-17 18:09:10 +00:00
cb68d07751 Added special handling of HTTP 500 error that Comic Vine seems to give occasionally.
git-svn-id: http://comictagger.googlecode.com/svn/trunk@607 6c5673fe-1810-88d6-992b-cd32ca31540c
2013-04-17 18:08:39 +00:00
8 changed files with 248 additions and 44 deletions

View File

@ -24,6 +24,7 @@ from pprint import pprint
import urllib2, urllib
import math
import re
import time
import datetime
import ctversion
import sys
@ -106,12 +107,28 @@ class ComicVineTalker(QObject):
return cv_response[ 'status_code' ] != 100
def getUrlContent( self, url ):
try:
resp = urllib2.urlopen( url )
return resp.read()
except Exception as e:
self.writeLog( str(e) )
raise ComicVineTalkerException("Network Error!")
# connect to server:
# if there is a 500 error, try a few more times before giving up
# any other error, just bail
for tries in range(3):
try:
resp = urllib2.urlopen( url )
return resp.read()
except urllib2.HTTPError as e:
if e.getcode() == 500:
self.writeLog( "Try #{0}: ".format(tries+1) )
time.sleep(1)
self.writeLog( str(e) + "\n" )
if e.getcode() != 500:
break
except Exception as e:
self.writeLog( str(e) + "\n" )
raise ComicVineTalkerException("Network Error!")
raise ComicVineTalkerException("Error on Comic Vine server")
def searchForSeries( self, series_name , callback=None, refresh_cache=False ):

View File

@ -1,3 +1,3 @@
# This file should contan only these comments, and the line below.
# Used by packaging makefiles and app
version="1.1.7-beta"
version="1.1.8-beta"

View File

@ -132,7 +132,9 @@ class FileRenamer:
# some tweaks to keep various filesystems happy
new_name = new_name.replace("/", "-")
new_name = new_name.replace(":", "-")
new_name = new_name.replace(" :", " -")
new_name = new_name.replace(": ", " - ")
new_name = new_name.replace(":", "-")
new_name = new_name.replace("?", "")
return new_name

View File

@ -25,6 +25,11 @@ import os
import traceback
import ctversion
import utils
try:
import argparse
except:
pass
from genericmetadata import GenericMetadata
from comicarchive import MetaDataStyle
from versionchecker import VersionChecker
@ -175,6 +180,41 @@ For more help visit the wiki at: http://code.google.com/p/comictagger/
#print md
return md
def launch_script(self, scriptfile):
# we were given a script. special case for the args:
# 1. ignore everthing before the -S,
# 2. pass all the ones that follow (including script name) to the script
script_args = list()
for idx, arg in enumerate(sys.argv):
if arg in [ '-S', '--script']:
#found script!
script_args = sys.argv[idx+1:]
break
sys.argv = script_args
if not os.path.exists(scriptfile):
print "Can't find {0}".format( scriptfile )
else:
# I *think* this makes sense:
# assume the base name of the file is the module name
# add the folder of the given file to the python path
# import module
dirname = os.path.dirname(scriptfile)
module_name = os.path.splitext(os.path.basename(scriptfile))[0]
sys.path = [dirname] + sys.path
try:
script = __import__(module_name)
# Determine if the entry point exists before trying to run it
if "main" in dir(script):
script.main()
else:
print "Can't find entry point \"main()\" in module \"{0}\"".format( module_name )
except Exception as e:
print "Script raised an unhandled exception: ", e
print traceback.format_exc()
sys.exit(0)
def parseCmdLineArgs(self):
if platform.system() == "Darwin" and hasattr(sys, "frozen") and sys.frozen == 1:
@ -183,6 +223,15 @@ For more help visit the wiki at: http://code.google.com/p/comictagger/
else:
input_args = sys.argv[1:]
# first check if we're launching a script:
for n in range(len(input_args)):
if ( input_args[n] in [ "-S", "--script" ] and
n+1 < len(input_args)):
# insert a "--" which will cause getopt to ignore the remaining args
# so they will be passed to the script
input_args.insert(n+2, "--")
break
# parse command line options
try:
opts, args = getopt.getopt( input_args,
@ -258,7 +307,7 @@ For more help visit the wiki at: http://code.google.com/p/comictagger/
print "ComicTagger {0}: Copyright (c) 2012-2013 Anthony Beville".format(ctversion.version)
print "Distributed under Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)"
new_version = VersionChecker().getLatestVersion("", False)
if new_version is not None:
if new_version is not None and new_version != ctversion.version:
print "----------------------------------------"
print "New version available online: {0}".format(new_version)
print "----------------------------------------"
@ -289,40 +338,8 @@ For more help visit the wiki at: http://code.google.com/p/comictagger/
self.display_msg_and_quit( "Must choose only one action of print, delete, save, copy, rename, export, or run script", 1 )
if self.script is not None:
# we were given a script. special case for the args:
# 1. ignore everthing before the -S,
# 2. pass all the ones that follow (including script name) to the script
script_args = list()
for idx, arg in enumerate(sys.argv):
if arg in [ '-S', '--script']:
#found script!
script_args = sys.argv[idx+1:]
break
sys.argv = script_args
if not os.path.exists(self.script):
print "Can't find {0}".format( self.script )
else:
# I *think* this makes sense:
# assume the base name of the file is the module name
# add the folder of the given file to the python path
# import module
dirname = os.path.dirname(self.script)
module_name = os.path.splitext(os.path.basename(self.script))[0]
sys.path = [dirname] + sys.path
try:
script = __import__(module_name)
# Determine if the entry point exists before trying to run it
if "main" in dir(script):
script.main()
else:
print "Can't find entry point \"main()\" in module \"{0}\"".format( module_name )
except Exception as e:
print "Script raised an unhandled exception: ", e
print traceback.format_exc()
sys.exit(0)
self.launch_script( self.script )
if len(args) > 0:
if platform.system() == "Windows":
# no globbing on windows shell, so do it for them

View File

@ -220,7 +220,8 @@ class TaggerWindow( QtGui.QMainWindow):
self.settings.send_usage_stats = True
self.settings.ask_about_usage_stats = False
self.checkLatestVersionOnline()
if self.settings.check_for_new_version:
self.checkLatestVersionOnline()
def sigint_handler(self, *args):
# defer the actual close in the app loop thread

View File

@ -1,3 +1,11 @@
---------------------------------
1.1.8-beta - 21-Apr-2013
---------------------------------
* Handle occasional error 500 from Comic Vine by retrying a few times
* Nicer handling of colon (":") in file rename
* Fixed command-line option parsing issue for add-on scripts
* Misc bug fixes
---------------------------------
1.1.7-beta - 12-Apr-2013
---------------------------------

151
scripts/name_fixer.py Executable file
View File

@ -0,0 +1,151 @@
#!/usr/bin/python
"""
fix the comic file names using a list of transforms
"""
"""
Copyright 2013 Anthony Beville
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
import sys
import os
import re
import argparse
import json
from comictaggerlib.comicarchive import *
from comictaggerlib.settings import *
from comictaggerlib.filerenamer import *
import comictaggerlib.utils
def parse_args():
input_args = sys.argv[1:]
parser = argparse.ArgumentParser(description='a script to rename comic files')
parser.add_argument('-t', '--transforms', metavar='xformfile', help="the file with transforms")
parser.add_argument('-n', '--noconfirm', action='store_true', help="don't confirm before rename")
parser.add_argument('paths', metavar='PATH', type=str, nargs='+', help='path to look for comic files')
parsed_args = parser.parse_args(input_args)
return parsed_args
def caclulate_rename(ca, md, settings):
new_ext = None # default
if settings.rename_extension_based_on_archive:
if ca.isZip():
new_ext = ".cbz"
elif ca.isRar():
new_ext = ".cbr"
renamer = FileRenamer( md )
renamer.setTemplate( "%series% V%volume% #%issue% (of %issuecount%) (%year%) %scaninfo%" )
renamer.setIssueZeroPadding( 0 )
renamer.setSmartCleanup( settings.rename_use_smart_string_cleanup )
return renamer.determineName( ca.path, ext=new_ext )
def perform_rename(filelist):
for old_name,new_name in filelist:
folder = os.path.dirname( os.path.abspath( old_name ) )
new_abs_path = utils.unique_file( os.path.join( folder, new_name ) )
os.rename( old_name, new_abs_path )
print u"renamed '{0}' -> '{1}'".format(os.path.basename(old_name), new_name)
def main():
default_xform_list = [
[ "^2000AD$", "2000 AD" ],
[ "^G\.{0,1}I\.{0,1}Joe$", "G.I. Joe" ],
]
utils.fix_output_encoding()
settings = ComicTaggerSettings()
style = MetaDataStyle.CIX
parsed_args = parse_args()
#parsed_args.noconfirm
if parsed_args.transforms is not None:
print "Reading in transforms from:", parsed_args.transforms
json_data=open(parsed_args.transforms).read()
data = json.loads(json_data)
xform_list = data['xforms']
else:
xform_list = default_xform_list
#pprint( xform_list, indent=4)
filelist = utils.get_recursive_filelist( parsed_args.paths )
#first find all comics
print "reading in all comics..."
comic_list = []
max_name_len = 2
fmt_str = ""
for filename in filelist:
ca = ComicArchive(filename, settings )
# do we care if it already has metadata?
if ca.seemsToBeAComicArchive() and not ca.hasMetadata( style ):
comic_list.append(ca)
max_name_len = max ( max_name_len, len(filename))
fmt_str = u"{{0:{0}}}".format(max_name_len)
print >> sys.stderr, fmt_str.format( filename ) + "\r",
sys.stderr.flush()
print >> sys.stderr, fmt_str.format( "" )
print "Found {0} comics.".format( len(comic_list))
modify_list = list()
# walk through the comic list fix the filenames
for ca in comic_list:
# 1. parse the filename into a MD object
md = ca.metadataFromFilename()
# 2. walk thru list of transforms
if md.series is not None and md.series != "":
for pattern, replacement in xform_list:
# apply each transform
new_series = re.sub( pattern, replacement, md.series )
if new_series != md.series:
md.series = new_series
new_name = caclulate_rename(ca, md, settings)
#found a match. add to proposed list, and bail on this file
modify_list.append( (ca.path, new_name ) )
break
print "{0} filenames to modify".format(len(modify_list))
if len(modify_list) > 0:
if parsed_args.noconfirm:
print "Not confirming before rename"
else:
for old_name, new_name in modify_list:
print u"'{0}' -> '{1}'".format(os.path.basename(old_name), new_name)
i = raw_input("Do you want to proceed with rename? [y/N] ")
if i.lower() not in ('y', 'yes'):
print "exiting without rename."
sys.exit(0)
perform_rename(modify_list)
if __name__ == '__main__':
main()

8
scripts/xforms Normal file
View File

@ -0,0 +1,8 @@
{
"_comment": "This file contains JSON data. Any backslashes should be escaped with another backslash",
"xforms":
[
[ "^2000AD$", "2000 AD" ],
[ "^G\\.{0,1}I\\.{0,1}Joe$", "G.I. Joe" ]
]
}