Package gavo :: Package helpers :: Module filestuff :: Class FileRenamer
[frames] | no frames]

Class FileRenamer

source code

object --+
         |
        FileRenamer

is a name mapper for file rename operations and the like.

Warning: This whole thing more or less pretends there are no symlinks.

Instance Methods
 
__init__(self, map, showOnly=False)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
getFileMap(self, path)
returns a dictionary old->new of renames within path.
source code
 
makeRenameProc(self, fileMap)
returns a sequence of (old,new) pairs that, when executed, keep any new from clobbering any existing old.
source code
 
renameInPath(self, path)
performs a name map below path.
source code
 
renameInPaths(self, pathList) source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Methods
 
loadFromFile(cls, inF, **kwargs)
returns a name map for whatever is serialized in the file inF.
source code
Properties

Inherited from object: __class__

Method Details

__init__(self, map, showOnly=False)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__
(inherited documentation)

loadFromFile(cls, inF, **kwargs)
Class Method

source code 

returns a name map for whatever is serialized in the file inF.

The format of fName is line-base, with each line being one of

  • empty -- ignored
  • beginning with a hash -- ignored
  • <old> -> <new> -- introducing a map

makeRenameProc(self, fileMap)

source code 

returns a sequence of (old,new) pairs that, when executed, keep any new from clobbering any existing old.

The function will raise an Error if there's a cycle in fileMap. fileMap will be destroyed by this procedure

renameInPath(self, path)

source code 

performs a name map below path.

The rules are:

  • extensions are ignored -- if we map foo to bar, foo.txt and foo.asc will be renamed bar.txt and foo.txt respectively
  • the order of statements in the source is irrelevant. However, we try not to clobber anything we've just renamed and will complain about cycles. Also, each file will be renamed not more than once.