""" Date Formatter Plugin ========================== Sample class which can be used as a plugin for Peter's Flexible Renaming Kit (PFrank) Just copy the class definition (no need to copy the other declarations or test code) to your PFrankUser.py file and add a reference to the class in the PFrankUser.py 'UserRenamerList' table. Or just rename this file as PFrankUser.py and move it to your PFrank install folder if you don't want any other plugins. More details can be found in the PFrankUser.py.template file that is included with the PFrank download. Dec 1, 2007 Initial Creation by Neil Harding 0.1 Feb 1, 2008 Modified to single class 0.2 """ ########################################## # list your imported modules here. # If you get import errors, then the modules are not # present in the environment. In this case you will have to # insert the required module in the PFrank install folder. ########################################## # start of user imported modules import re import datetime # end of user imported modules. ########################################## # The following modules must always be imported ########################################## # start of required imported modules try : from SearchRep_init import configurator from SearchRepBase import SearchRepBase from SearchRepConstants import * except : from SearchRep_initStubs import configurator from SearchRepBaseStubs import SearchRepBase # end of required imported modules debug = False class DateReFormatter (SearchRepBase) : """ This is a date renamer class. The SearchRepLower base class is mandatory. Dates will be converted to the format specified by the fixed or custom date formats specified by the PFrank Date Formatter options. The options are configured via the PFRank Options Window. """ def __init__ (self) : # call base class initializer. This is mandatory SearchRepBase.__init__(self) # This is the ID string that will appear in the pre-defined command # pull down list. It will also appear in the custom list when # inserted. The id will also be used in the scan summary # The name 'self.idstring' must not change. Set the assigned string # on the right-hand side of the assignment statement to whatever # name you want. self.idstring = "Convert dates using date formatter in" # This regular expression is "weak", it will let some non dates in # this is fine, because we do "strong" checks in code self.date = re.compile(r""" (?i)^(.*?) (\d\dst|\d\dnd|\d\drd|\d\dth|\d\d|\dst|\dnd|\drd|\dth| Jan[-uary. ]+Feb[ruary]*|Feb[-ruary. ]+Mar[ch]*| Mar[-ch. ]+Apr[il]*|Apr[-il. ]+May|May[-. ]+Jun[e]*| Jun[-e. ]+Jul[y]*|Jul[-y. ]+Aug[ust]*| Aug[-ust. ]+Sep[tember]*|Sep[-tember. ]+Oct[ober]*| Oct[-ober. ]+Nov[ember]*|Nov[-ember. ]+Dec[ember]*| Dec[-ember. ]+Jan[uary]*| Jan[uary]*|Feb[ruary]*|Mar[ch]*|Apr[il]*|May|Jun[e]*| Jul[y]*|Aug[ust]*|Sep[tember]*|Oct[ober]*|Nov[ember]*| Dec[ember]*|Spring[-. ]*Special*|Easter[-. ]*Special| Summer[-. ]*Special|Fall[-. ]*Special|Autumn[-. ]*Special| Winter[-. ]*Special|Christmas[-. ]*Special| X[-. ]*mas[-. ]*Special|Holiday[-. ]*Special|Spr[ing]*|Eas[ter]*| Sum[mer]*|Fall|Aut[-mn]*|Win[ter]*|Christmas|X[-. ]*mas|\d) ([-., ]*) (\d\dst|\d\dnd|\d\drd|\d\dth|\d\d|\dst|\dnd|\drd|\dth| Jan[-uary. ]+Feb[ruary]*|Feb[-ruary. ]+Mar[ch]*| Mar[-ch. ]+Apr[il]*|Apr[-il. ]+May|May[-. ]+Jun[e]*| Jun[-e. ]+Jul[y]*|Jul[-y. ]+Aug[ust]*| Aug[-ust. ]+Sep[tember]*|Sep[-tember. ]+Oct[ober]*| Oct[-ober. ]+Nov[ember]*|Nov[-ember. ]+Dec[ember]*| Dec[-ember. ]+Jan[uary]*| Jan[uary]*|Feb[ruary]*|Mar[ch]*|Apr[il]*|May|Jun[e]*| Jul[y]*|Aug[ust]*|Sep[tember]*|Oct[ober]*|Nov[ember]*| Dec[ember]*|Spring[-. ]*Special*|Easter[-. ]*Special| Summer[-. ]*Special|Fall[-. ]*Special|Autumn[-. ]*Special| Winter[-. ]*Special|Christmas[-. ]*Special| X[-. ]*mas[-. ]*Special|Holiday[-. ]*Special|Spr[ing]*|Eas[ter]*| Sum[mer]*|Fall|Aut[-mn]*|Win[ter]*|Christmas|X[-. ]*mas|\d) ([-., ]*) (\d\dst|\d\dnd|\d\drd|\d\dth|\d\d|\dst|\dnd|\drd|\dth| Jan[-uary. ]+Feb[ruary]*|Feb[-ruary. ]+Mar[ch]*| Mar[-ch. ]+Apr[il]*|Apr[-il. ]+May|May[-. ]+Jun[e]*| Jun[-e. ]+Jul[y]*|Jul[-y. ]+Aug[ust]*| Aug[-ust. ]+Sep[tember]*|Sep[-tember. ]+Oct[ober]*| Oct[-ober. ]+Nov[ember]*|Nov[-ember. ]+Dec[ember]*| Dec[-ember. ]+Jan[uary]*| Jan[uary]*|Feb[ruary]*|Mar[ch]*|Apr[il]*|May|Jun[e]*| Jul[y]*|Aug[ust]*|Sep[tember]*|Oct[ober]*|Nov[ember]*| Dec[ember]*|Spring[-. ]*Special*|Easter[-. ]*Special| Summer[-. ]*Special|Fall[-. ]*Special|Autumn[-. ]*Special| Winter[-. ]*Special|Christmas[-. ]*Special| X[-. ]*mas[-. ]*Special|Holiday[-. ]*Special|Spr[ing]*|Eas[ter]*| Sum[mer]*|Fall|Aut[-mn]*|Win[ter]*|Christmas|X[-. ]*mas|\d) ([-., ]*) (\d\dst|\d\dnd|\d\drd|\d\dth|\d\d|\dst|\dnd|\drd|\dth| Jan[-uary. ]+Feb[ruary]*|Feb[-ruary. ]+Mar[ch]*| Mar[-ch. ]+Apr[il]*|Apr[-il. ]+May|May[-. ]+Jun[e]*| Jun[-e. ]+Jul[y]*|Jul[-y. ]+Aug[ust]*| Aug[-ust. ]+Sep[tember]*|Sep[-tember. ]+Oct[ober]*| Oct[-ober. ]+Nov[ember]*|Nov[-ember. ]+Dec[ember]*| Dec[-ember. ]+Jan[uary]*| Jan[uary]*|Feb[ruary]*|Mar[ch]*|Apr[il]*|May|Jun[e]*| Jul[y]*|Aug[ust]*|Sep[tember]*|Oct[ober]*|Nov[ember]*| Dec[ember]*|Spring[-. ]*Special*|Easter[-. ]*Special| Summer[-. ]*Special|Fall[-. ]*Special|Autumn[-. ]*Special| Winter[-. ]*Special|Christmas[-. ]*Special| X[-. ]*mas[-. ]*Special|Holiday[-. ]*Special|Spr[ing]*|Eas[ter]*| Sum[mer]*|Fall|Aut[-mn]*|Win[ter]*|Chr[istmas]*|X[-. ]*mas|\d)? ($|[^0-9]+.*)$ # look for six or 8 digit number in middle of string # if ends with p, then it is page count and not date """, re.VERBOSE) self.number = re.compile(r"(\d\d\d\d|\d\d|\d).*") self.invalidSeperator = re.compile(r"\w.*") self.ordinal = re.compile(r"(.*[stndrdth]+.*)") self.prefixEnd = re.compile(r"[a-zA-Z#]") self.months = [ re.compile(r"(?i)^Jan[uary]*$"), re.compile(r"(?i)^Feb[ruary]*$"), re.compile(r"(?i)^Mar[ch]*$"), re.compile(r"(?i)^Apr[il]*$"), re.compile(r"(?i)^May$"), re.compile(r"(?i)^Jun[e]*$"), re.compile(r"(?i)^Jul[y]*$"), re.compile(r"(?i)^Aug[ust]*$"), re.compile(r"(?i)^Sep[tember]*$"), re.compile(r"(?i)^Oct[ober]*$"), re.compile(r"(?i)^Nov[ember]*$"), re.compile(r"(?i)^Dec[ember]*$"), re.compile(r"(?i)^Jan[-uary. ]+Feb[ruary]*$"), re.compile(r"(?i)^Feb[-ruary. ]+Mar[ch]*$"), re.compile(r"(?i)^Mar[-ch. ]+Apr[il]*$"), re.compile(r"(?i)^Apr[-il. ]+May$"), re.compile(r"(?i)^May[-. ]+Jun$"), re.compile(r"(?i)^Jun[-e. ]+Jul[y]*$"), re.compile(r"(?i)^Jul[-y. ]+Aug[ust]*$"), re.compile(r"(?i)^Aug[-ust. ]+Sep[tember]*$"), re.compile(r"(?i)^Sep[-tember. ]+Oct[ober]*$"), re.compile(r"(?i)^Oct[-ober. ]+Nov[ember]*$"), re.compile(r"(?i)^Nov[-ember. ]+Dec[ember]*$"), re.compile(r"(?i)^Dec[-ember. ]+Jan[uary]*$"), re.compile(r"(?i)^Spr[ing]*$"), re.compile(r"(?i)^Eas[ter]*$"), re.compile(r"(?i)^Sum[mer]*$"), re.compile(r"(?i)^Fall$|Aut[umn]*$"), re.compile(r"(?i)^Win[ter]*$"), re.compile(r"(?i)^Chr[istmas-]*$|X[-]*mas$"), re.compile(r"(?i)^Spring[-. ]*Special$"), re.compile(r"(?i)^Easter[-. ]*Special$"), re.compile(r"(?i)^Summer[-. ]*Special$"), re.compile(r"(?i)^Fall[-. ]*Special$|Autumn[-. ]Special$"), re.compile(r"(?i)^Winter[-. ]*Special$"), re.compile(r"(?i)^Christmas[-. ]*Special$|X[-]*mas[-. ]Special$"), re.compile(r"(?i)^Holiday[-. ]*Special$"), ] self.monthValues = [ 0,1,2,3,4,5,6,7,8,9,10,11, 0,1,2,3,4,5,6,7,8,9,10,11, 2,3,6,8,10,11, 2,3,6,8,10,11, ] self.monthNamesShort = [ "Jan","Feb","Mar","Apr","May","Jun", "Jul","Aug","Sep","Oct","Nov","Dec", "Jan-Feb","Feb-Mar","Mar-Apr","Apr-May","May-Jun","Jun-Jul", "Jul-Aug","Aug-Sep","Sep-Oct","Oct-Nov","Nov-Dec","Dec-Jan", "Spring","Easter","Summer","Fall","Winter","Xmas", "Spring Special","Easter Special","Summer Special", "Fall Special","Winter Special","Xmas Special","Holiday Special" ] self.monthNames = [ "January","February","March","April","May","June", "July","August","September","October","November","December", "January-February","February-March","March-April", "April-May","May-June","June-July","July-August", "August-September","September-October","October-November", "November-December","December-January", "Spring","Easter","Summer","Fall","Winter","Christmas", "Spring Special","Easter Special","Summer Special", "Fall Special","Winter Special","Christmas Special", "Holiday Special" ] self.dayNamesShort = [ "Mon","Tue","Wed","Thu","Fri","Sat","Sun" ] self.dayNames = [ "Monday","Tuesday","Wednesday","Thursday", "Friday","Saturday","Sunday" ] self.standardFormatFullYear = re.compile(r"YYYY") self.standardFormatYear = re.compile(r"YY") self.standardFormatMonth = re.compile(r"MM") self.standardFormatDay = re.compile(r"DD") # I have extended custom format, ? means ignore next field IF day is not defined self.customFormatRemove = re.compile(r"~[-. ]*[%]?.") self.customFormatClean = re.compile(r"~") self.customFormatEscape = re.compile(r"%%") self.customFormatWeekday = re.compile(r"%a") self.customFormatFullWeekday = re.compile(r"%A") self.customFormatRemoveExtendedMonth = re.compile(r"[- .]*%[bB]x") self.customFormatExtendedMonthNamesShort = re.compile(r"%bx") self.customFormatMonthNamesShort = re.compile(r"%b") self.customFormatExtendedMonthNames = re.compile(r"%Bx") self.customFormatMonthNames = re.compile(r"%B") self.customFormatDay = re.compile(r"%d") self.customFormatMonth = re.compile(r"%m") self.customFormatYear = re.compile(r"%y") self.customFormatFullYear = re.compile(r"%Y") self.customFormatWeek = re.compile(r"%W") def initforscan(self, VerificationTest=False) : """ This function is called whenever a new scan or rescan is made. Use it to reset anything that needs to be reinitialized before a scan. This function is mandatory. """ standardDateFormat = configurator.optionlist[SEARCHREP_OPTIONDATEFORMAT_ID] customDateFormat = configurator.optionlist[SEARCHREP_OPTIONCUSTOMDATE_ID] useCustomDate = configurator.optionlist[SEARCHREP_CUSTOMORFIXEDDATE_ID] == "Custom Format" def getInt(self,val) : """ This returns val as int or -1, if it isn't valid It allows for suffix, so 2nd, gives 2 """ num = self.number.findall(val) if num == [] : if debug : print "getInt",val," is -1" return -1 if debug : print "getInt",val," is ",num[0]," = ",int(num[0]) return int (num[0]) def getMonthDay(self,month,day) : """ Return month and day, if month > 12 then it must be day """ if month > 12 : return day-1,month else : return month-1,day def ZeroPadded(self,num) : """ Return 08 rather than 8 """ if num < 0 : return "01" if num < 10 : return "0" + str(num) else : return str(num) def reformatDate(self,day,month,year) : """ Format date according to rename rules For now just use (YYYY-MM-DD) """ dayStr = self.ZeroPadded(day) monthStr = self.ZeroPadded(self.monthValues[month]+1) yearStr = self.ZeroPadded(year % 100) fullYearStr = str(year) if useCustomDate : currDay = day if day <= 0 : currDay = 1 useDate = datetime.date(year,self.monthValues[month]+1,currDay) ignoreYear, week, dow = useDate.isocalendar() newDate = self.customFormatEscape.sub("%",customDateFormat) if day <= 0 : newDate = self.customFormatRemove.sub("",newDate) else : newDate = self.customFormatClean.sub("",newDate) newDate = self.customFormatWeekday.sub(self.dayNamesShort[dow-1],newDate) newDate = self.customFormatFullWeekday.sub(self.dayNames[dow-1],newDate) if month > 11: newDate = self.customFormatExtendedMonthNamesShort.sub(self.monthNamesShort[month],newDate) else : newDate = self.customFormatRemoveExtendedMonth.sub("",newDate) newDate = self.customFormatMonthNamesShort.sub(self.monthNamesShort[month],newDate) if month > 11: newDate = self.customFormatExtendedMonthNames.sub(self.monthNames[month],newDate) newDate = self.customFormatMonthNames.sub(self.monthNames[month],newDate) newDate = self.customFormatDay.sub(dayStr,newDate) newDate = self.customFormatMonth.sub(monthStr,newDate) newDate = self.customFormatYear.sub(yearStr,newDate) newDate = self.customFormatFullYear.sub(fullYearStr,newDate) newDate = self.customFormatWeek.sub(self.ZeroPadded(week),newDate) else : newDate = self.standardFormatFullYear.sub(fullYearStr,standardDateFormat) newDate = self.standardFormatYear.sub(yearStr,newDate) newDate = self.standardFormatDay.sub(dayStr,newDate) newDate = self.standardFormatMonth.sub(monthStr,newDate) newDate = self.standardFormatMonth.sub(monthStr,newDate) return newDate def checkIfMonth(self,month) : """ Gets index for the month Input: string to check to see if it is a month (or season) Output: index of the month (0-11,or season), -1 if not found """ if debug : print "checkIfMonth(", month, ")" if self.number.match(month) != None : if debug : print "Number, can't be month" return -1 for curr in range(len(self.months)) : if self.months[curr].match(month) : if debug : print month," ",curr return curr return -1 def fixnames(self, filename,VerificationTest=False) : if debug : return self.doFixnames(filename,VerificationTest) try : return self.doFixnames(filename,VerificationTest) except: print " in DateReFormatter :",filename return False, filename def doFixnames(self, filename,VerificationTest=False) : """ This function converts name of file to a new name. Input: string representing the old filename or portion (either All, Prefix, or Extension) The name does not include the path to the file. Output: change indicator True if change to input string occurred, otherwise False string representing the new filename When the old filename string is passed into this routine, then depending on where this user command is placed in the custom list, the string could be in the middle of a transformation. e.g. if the original filename was ABCDEF.jpg, and the first command of the custom list inserted a counter in front of the name, and the second command was this user command, then the filename string that is passed in could be something like 0010-ABCDEF.jpg. This name of course no longer looks like the original name. If you needed to extract meta data from the file, then you would not be able to use the passed in string. Therefore the global variable 'configurator.filename' is provided which has the full path to the filename. You can then just open that name, extract the meta data, and then close the file. """ # full path to original filename fullPathForFile = configurator.filename if debug : print "Checking ",fullPathForFile if debug : print "Name is ",filename ######################################################################### # Insert code to modify the filename here ######################################################################### day = 0 year = -1 month = -1 skip = False append2nd = False newname = filename groups = self.date.findall(filename) eightDigit = False if debug : print groups print "Testing date check in file" print filename # print standardDateFormat # print customDateFormat # print useCustomDate if groups != [] : prefix = groups[0][0] postfix = groups[0][8] arg1 = groups[0][1] sep1 = groups[0][2] arg2 = groups[0][3] sep2 = groups[0][4] arg3 = groups[0][5] sep3 = groups[0][6] arg4 = groups[0][7] if postfix == filename : return False, filename if self.invalidSeperator.match(postfix) != None : if (arg4 == '') & (sep3 == '') : postfix = arg3 + sep3 + arg4 + postfix arg3 = '' else : postfix = arg4 + postfix arg4 = '' if self.prefixEnd.match(prefix[-1:]) != None: if (len(arg1) == 2) & (len(arg2) == 2) & (len(arg3) == 2) & (len(arg4) == 2) & (sep1 == '') & (sep2 == '') & (sep3 == '') : eightDigit = True else : prefix = prefix + arg1 + sep1 arg1 = '' sep1 = '' if debug : print "<" + prefix + "> <" + arg1 + "> <" + sep1 + "> <" + arg2 + "> <" + sep2 + "> <" + arg3 + "> <" + sep3 + "> <" + arg4 + "> <" + postfix + ">" # Ok, it is potential date to get past regular expression # [0] group is prepender, it used only on replacement # although we should check if it ends with (, so we don't # change date to be ((1967-07-02)) # [1-7] groups are either YY,MM,DD or seperators # First we want to find the month (for named months & seasons) month = self.checkIfMonth(arg1) #if it starts with month, next is either, year or day if month >= 0 : if debug : print "[1=month] >=0",month day = self.getInt (arg2) # if day is more than 31, it must be a year if day > 31 : if debug : print "[3=day] >31",day year = 1900 + day day = 0 # if group 4 is [] then there is no seperator between # digits and it is year, unless day is ordinal (1st,2nd,3rd, etc) if debug : print arg2," is ordinal ",self.ordinal.match(arg2) if (sep2 == '') & (self.ordinal.match(arg2) == None) : if debug : print "groups[0][4] == ''",arg3 year = day * 100 + int (arg3) day = 0 else : year = int (arg3) if arg4 != '' : year = year * 100 + int (arg4) elif year < 20 : year = 2000 + year else : year = 1900 + year else : month = self.checkIfMonth(arg2) #if it month is 2nd, then day must be 1st and year last #OR we have case like Superman 20 Sept-71 if month >= 0: if debug: print "[1=month] >=0",month print "*" + sep2 + "*" print "*" + sep1 + "*" print self.ordinal.match(arg1) if (sep2 != sep1) & (self.ordinal.match(arg1) == None) : append2nd = True else : day = self.getInt (arg1) year = int (arg3) if arg4 != '' : if debug : print "[7] != ''",arg4 year = year * 100 + int (arg4) elif year < 20 : year = 2000 + year else : year = 1900 + year else : #It's either numeric, or YYYY Month #OR not valid if (len(sep1) > 0 ) & (len(sep2) > 0) & (sep1 != sep2) : skip = True if debug : print self.prefixEnd.match(prefix[-1:]) if (eightDigit == False) & (self.prefixEnd.match(prefix[-1:]) != None) : skip = True if skip == False : first = self.getInt(arg1) second = self.getInt(arg2) third = self.getInt(arg3) fourth = self.getInt(arg4) month = self.checkIfMonth(arg3) if month >= 0 : skip = True if (second > 31) | ((first == 20) & (second < 10)) : year = first * 100 + second day = fourth else : day = first if second < 10 : year = 2000 + second else : year = 1900 + second if (month > 11) & (day > 0) : month = -1 skip = False #it must be numeric format then, lets do sanity tests #1943 for example can appear as valid if debug : print "len([3])=",len(arg2) print "[4]=",sep2 if (len(arg2) == 1) & (sep2 == '') : skip = True # if (sep1 == '') & (sep2 == '-') & (sep3 == '') : # skip = True if (len(arg2) == 1) | (len(arg3) == 1) | (len(arg4) == 1) : skip = True if skip == False : if first > 31 : #Ok, we have YYMMDD, or YYDDMM, assume YYMMDD #unless month is >= 12 year = 1900 + first month , day = self.getMonthDay(second,third) #if month < 0 then we haven't found the format yet if month < 0 : if debug : print first,second,third,fourth #lets see if it is 8 digits if fourth >= 0 : #Ok, it's either YYYYMMDD, DDMMYYYY, MMDDYYYY #Check 1st, to see if it is 19 or 20 if (first >= 19) & (first <=20) : month , day = self.getMonthDay(third,fourth) year = first * 100 + second else : month , day = self.getMonthDay(first,second) year = third * 100 + fourth else : #ok we have 6 digits, year must be first or last #or possibly YYYYMM, MMYYYY #so lets see if that helps #if there is a seperator between year & month use that if (sep1 == '') & (sep2 != '') : #Must be YYYY MM year = first * 100 + second month = third - 1 elif (sep1 != '') & (sep2 == '') : #Must be MM YYYY year = second *100 + third month = first - 1 else : if first > 31 : year = 1900 + first month , day = self.getMonthDay(second,third) elif third > 31 : year = 1900 + third month , day = self.getMonthDay(first,second) elif (second > 31) | ((second < 10) & (first == 20)) : #must be YYYYMM year = first * 100 + second month = third - 1 else : #I guess we go we YYMMDD, no way of telling now #It's more likely year will be 2000-2010 range, #So we can check to see which is more likely if (first > 10) & (third <= 10) : year = 2000 + third month , day = self.getMonthDay(first,second) else : year = 2000 + first month , day = self.getMonthDay(second,third) # We are dealing with numeric format, so month can't be > 12 if month > 12 : month = -1 #Process all the other rules ignore, tailend = self.fixnames(postfix) #if we have a valid month, then assume date is valid if month >= 0 : if arg4 == '' : tailend = sep3 + tailend if append2nd : newname = prefix + arg1 + sep1 + self.reformatDate(day,month,year) + tailend else : newname = prefix + self.reformatDate(day,month,year) + tailend else : newname = prefix + arg1 + sep1 + arg2 + sep2 + arg3 + sep3 + arg4 + tailend ######################################################################### # these statements are mandatory ######################################################################### change = False if filename != newname : change = True return change, newname # end of the class definition for DateReFormatter ################################################################### # Create the Renamer Objects in a list. The list is mandatory. # The name of the list must not change. # You can list as many names in the list as you like. PFrank will try to # load all of them. Each name in the list must correspond to the # name of a user command renaming class. A name can only appear # once in the list. # # User Command Objects are created with the following syntax: # ClassName() # i.e. the name of the class followed by () ################################################################### UserRenamerList = [ # UserRenamer1(), # object created for first user renaming class # UserRenamer2(), # object created for second user renaming class # UserRenamer3(), # object created for third user renaming class DateReFormatter(), # format date as specified by PFrank Date Formatter Option ] if __name__ != '__main__' : standardDateFormat = configurator.optionlist[SEARCHREP_OPTIONDATEFORMAT_ID] customDateFormat = configurator.optionlist[SEARCHREP_OPTIONCUSTOMDATE_ID] useCustomDate = configurator.optionlist[SEARCHREP_CUSTOMORFIXEDDATE_ID] == "Custom Format" ###################################### # Code for testing the renamer objects ###################################### if __name__ == '__main__' : """ This is some test code to test the renaming objects. Test the code using the python IDLE tool to verify that things work. Then try importing the file to PFrank """ import os userpath = os.getcwd() userpath = os.path.normpath(userpath) print "Initializing Local Stubs" ################################################################### # Stubs for Local Testing. These are in addition to the # stubs imported earlier. # only perform this extra initialization for the create folder command # initialize current folder config option for testing Username3 # configurator.optionlist[SEARCHREP_COMMANDFILEDIRECTORY_ID] = os.getcwd() # print "current folder is: '%s'\n"%configurator.optionlist[SEARCHREP_COMMANDFILEDIRECTORY_ID] standardDateFormat = "YYYYMMDD" customDateFormat = "(%Y-%m~-%d %Bx)" useCustomDate = True print "Testing User Defined Renaming Classes" # this is a table of sample filenames for testing # Assume that the files are in the current folder. nameTable = [ # "TestFile.txt", # "TestFile1.jpg", # "Test32File3.mp3", # "Test1.mp3", # "33T.ogg", # Test Date Formating "Date 2nd July 1967 test", "Date July-2-1967 test", "Date Jul 1967 test", "september-5-43", "sep 1943", "5 sept 43", "Date 17-12-2007 test", "(1967-07-02) # What the end result should be", "171207", "1943 # Not a valid date", "1943 until 1945-11 # Not a valid date, followed by valid one", "198507 #YYYYMM", "July 1st 1961 to 2nd July 1967 # Multiple dates", "Superman 12 Sept-71 #If seperator between Month-Year is different than seperator between day-month add it as number", "198507 123-124 20030507 #if we have dddddd or dd dddddd detect it", "Tales of the Unexpected 03 28p(1956)", "Superman 200011 575", "From Beyond the Unknown 1969 10 # For general purpose use, we must detect this as a date", "From Beyond the Unknown 10 1969 # For general purpose use, we must detect this as a date", "From Beyond the Unknown 1969 011", "From Beyond the Unknown 011 1969", "Superman 200111 587", "Wonder Woman v1 164", "2000AD Prog #1234", "1940-12 Jungle_Comics_012__missing_pg_55_", "Futurama Comics 06 - Xmas Time Is Fear", "Warrior #15 November 1983", "Warrior #04 Summer Special 1982", "009. Marvel Spotlight - Mark Millar and Steve McNiven", "085. Winter Soldier - Winter Kills", "106. Fallen Son - Wolverine #01", "2000 AD 1048 - 22 ad page", "The Complete DC vs Marvel Vol.01 (1996 Marvel & DC) 265p", "STRANGE ADVENTURES 211 (1968.Apr.c2c.Flattermann)", "00362 All-Flash Quarterly 003", "Warrior #10 April-May 1983", "1951-10 Police Comics 108", "TvCentury21-028", "Judge Dredd Megazine 1992 20", "Action UK 17-09-77 (FF69Scan) (c2c)", "001 Shadow Comics (Volume 7, Number 7; October, 1947)", "dilbert20060205", # Now we test padding # "Superman 5", # "Superman 12", # "Superman 100", # "Superman Annual 1", # "Superman 1200", # Now we test volume splitting (seperate directories) # and directories based on Title name # "Action Comics v1 546", # "Action Comics v1 444", # "Action Comics v2 17", # "Action Comics Annual 1996", ] # run all the initializers for renamer in UserRenamerList : renamer.initforscan() # run all name fixers for renamer in UserRenamerList : print "*************Testing Renamer: ", renamer.idstring for name in nameTable : fullpath = os.path.join(os.getcwd(), name) configurator.filename = os.path.normpath(fullpath) change, newname = renamer.fixnames(name) print "Oldname is: ", name print "Newname is: ", newname assert (change == (not name == newname)) print ""