def error_check_items(self): """Run stand-alone error check on all items,""" main.bad = [] main.warn = [] main.errorLog = [] main.ec = 0 self.items_ren = [] progressDialog = classes.ProgressDialog( main, self.prefs, main.items, _(u"Error chekcing %%% names, please wait ...")) for item in main.toRename: original = item[0][0] new = os.path.split(item[1][0])[1] newPath = os.path.split(item[1][0])[0] # create the new name renamedItem, newPath = self.errorCheck(new, original, newPath) newItem = os.path.join(newPath, renamedItem) # add to list of renamed items (for dupe checking) self.items_ren.append(newItem) main.ec += 1 # for error/warn assignment if progressDialog.update(main.ec) == False: break self.items_ren = map(self.addStatus, self.items_ren) main.toRename = zip(main.items, self.items_ren) progressDialog.destroy() self.setStatusMessage()
def rename(self, event): """ Write undo files first (safety first !), then attemp to perform the renaming operation. """ itemsRenamed = 0 error = False main.currentItem = None main.bottomWindow.display.mode = 'rename' utils.set_busy(True) main.picker.view.path.SetEditable(False) # adjust and sort items when recursively renaming folders if app.recursiveFolderOn and event != u'undo': main.set_status_msg( _(u"Adjusting %s recursive paths, please wait ...") % len(main.toRename), u'wait') progressDialog = classes.ProgressDialog( main, app.prefs, main.items, _(u"Adjusting %%% recursive paths, please wait ...")) if app.showTimes: t = time.time() def sort_test(n): return -n[1][0].count(os.sep) main.toRename.sort(key=sort_test) progressDialog.destroy() if app.showTimes: print("%s items recursive adjust : %s" % (len(main.toRename), (time.time() - t))) if not error: main.set_status_msg(_(u"Renaming in progress, please wait ..."), u'wait') # open undo files for writing try: self.originalFile = codecs.open( utils.get_user_path(u'undo/original.bak'), 'w', "utf-8") self.renamedFile = codecs.open( utils.get_user_path(u'undo/renamed.bak'), 'w', "utf-8") except IOError as (n, strerror): msg = strerror + _( u"\nMake sure 'undo' directory exists and is read/write\n\nYou will not be able to undo!!\nDo you want to continue??" ) title = _(u"Problem with undo!") if not utils.make_yesno_dlg(msg, title): error = 'cancelled' dlg.Destroy()
def run(self, operations): """ Parse user settings, go through each item to be renamed and apply renaming operations. Results are stored in the dictionary 'self.toRename' which is used by the rename function to rename. """ main.Update() main.set_status_msg( _(u"Generating %s new names, please wait ...") % len(main.items), u'wait') if app.showTimes: t = time.time() main.counter = 0 main.bad = [] main.warn = [] main.ec = 0 main.errorLog = [] self.items_ren = [] app.REmsg = False # regular expression warn message # define here for faster processing def split(item): return os.path.split(item) def splitext(item): return os.path.splitext(item) def join(newPath, renamedItem): return unicode(os.path.join(newPath, renamedItem)) # test for numbering panel hasNumbering = False for op in operations: if hasattr(op, 'numberingPanel'): hasNumbering = True break # set some numbering globals if hasNumbering: main.lastDir = False main.lastName = '\n\t\r' # no item should ever have this name! main.curName = False progressDialog = classes.ProgressDialog( main, self.prefs, main.items, _(u"Generating %%% new names, please wait ...")) # define here for faster access onlyShowChangedItems = app.prefs.get('onlyShowChangedItems') for itemToRename, isFile in main.items: # clear stuff out splitPath = split(itemToRename) newPath = splitPath[0] # split name & extension renamedItem = splitPath[1] if isFile: splitName = splitext(renamedItem) newName = splitName[0] newExt = splitName[1][1:] else: newName = renamedItem newExt = False app.debug_print(itemToRename) if hasNumbering: main.curDir = newPath # go through each operation for i in range(len(operations)): op = operations[i] newPath, newName, newExt = op.rename_item( newPath, newName, newExt, itemToRename) if newExt is not False: renamedItem = newName + '.' + newExt else: renamedItem = newName # get name as it is before the last operation # use to reset numbering based on duplicate names if hasNumbering and len(operations) - 2 == i: main.curName = renamedItem renamedItem, newPath = self.errorCheck(renamedItem, itemToRename, newPath) # add to list of renamed items newItem = join(newPath, renamedItem) if not onlyShowChangedItems: self.items_ren.append(newItem) elif newItem != itemToRename or main.ec in main.bad or\ main.ec in main.warn: self.items_ren.append(newItem) app.debug_print("%s\n" % newItem) # increment item position counters main.ec += 1 # for error/warn assignment if progressDialog.update(main.ec) == False: break # for reseting numbering if hasNumbering: main.lastDir = main.curDir # by directory main.lastName = main.curName # by name progressDialog.destroy() items_ren = map(self.addStatus, self.items_ren) # make new dict with original and renamed files: main.toRename = zip(main.items, items_ren) del items_ren main.menuFile.SaveLog.Enable(True) # output time taken if set if app.showTimes: print("%s items preview : %s" % (len(main.toRename), (time.time() - t))) self.setStatusMessage()