-
Notifications
You must be signed in to change notification settings - Fork 0
/
Renamer.py~
81 lines (63 loc) · 2.32 KB
/
Renamer.py~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# Renamer.py
# class defining Renamer objects, as used by rn.py
import os
# TODO: implement error handling and checking for all setter methods
# TODO: use verbose regular expressions for better documentation
class Renamer():
# TODO: create _DEBUG flag and implement it
def __init__(self, fileList = (), dirPath = "", namingMask = {}, namingMaskString = "", renamingMaskString = "", namingMaskVariableSeparator = "||", namingMaskVariableTag = "%", debug = False):
# TODO: use setter functions for this init
self.fileList = fileList
self.dirPath = dirPath
self.namingMask = namingMask
self.namingMaskString = namingMaskString
self.renamingMaskString = renamingMaskString
self.renamingMask = {}
self.NAMING_MASK_VARIABLE_SEPARATOR = namingMaskVariableSeparator
self.NAMING_MASK_VARIABLE_TAG = namingMaskVariableTag
self._DEBUG = debug
def parseNamingMaskString(self, namingMaskString):
parselist = namingMaskString.split(self.NAMING_MASK_VARIABLE_SEPARATOR)
for varstring in parselist:
var, regex = varstring.split("=")
var = var.strip()
regex = regex.strip()
self.namingMask[var] = regex
if self._DEBUG:
self.printNamingMask()
def printNamingMask(self):
print "Printing namingMask ..."
for key in self.namingMask.keys():
print key + ' = ' + self.namingMask[key]
def setNamingMaskString(self, namingMaskString):
self.namingMaskString = namingMaskString
self.parseNamingMaskString(namingMaskString)
def getNamingMaskString():
return self.namingMaskString
def setNamingMask(self, namingMask):
self.namingMask = namingMask
def getNamingMask():
return self.namingMask
def setRenamingMask(self, renamingMask):
self.renamingMask = renamingMask
def getRenamingMask():
return self.renamingMask
def setFileList(self, fileList):
self.fileList = fileList
def getFileList():
return self.fileList
def setDirPath(self, dirPath):
self.dirPath = dirPath
def getDirPath():
return self.dirPath
# create dictionary of renamed files
def
# use namingMask dictionary to parse file name mask into variables
def parseFileNamingMask(self, filename):
pass
# TODO: implement appropriate error checking and handling
# for now, this assumes user knows what he is doing
def renameFiles(self):
print "renaming files ..."
for file in self.fileList:
os.rename(file, self.renamedFiles[file])