This page may contain false or misleading information.
The information contained in this page has not been verified and may include false, inaccurate, fabricated, or otherwise deceptive claims. In particular, it has been determined that this page may contain files in the repository containing malicious payloads.
forked from fuzzbunch/fuzzbunch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateReplay.py
158 lines (130 loc) · 4.37 KB
/
CreateReplay.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import glob
import os
import shutil
import sys
import xml.dom.minidom
#------------------------------------------------------------------------------------------
# DOM helper functions
#------------------------------------------------------------------------------------------
def getMatchingChildNodes(node, name):
l = list()
for item in node.childNodes:
if (item.nodeType == node.ELEMENT_NODE) and (item.nodeName == name):
l.append(item)
return l
def getText(nodelist):
rc = ""
for node in nodelist:
if node.nodeType == node.TEXT_NODE:
rc = rc + node.data
return rc
#------------------------------------------------------------------------------------------
def copyFiles(files):
for item in files:
src = item[0]
dst = item[1]
#print "%s -> %s" % (src, dst)
try:
os.makedirs(os.path.dirname(dst))
except:
pass
shutil.copy2(src, dst)
return True
#------------------------------------------------------------------------------------------
def handleDir(dirName, dstDir, root, recursive=False):
#print "handleDir: ENTER (%s)" % dirName
fileList = list()
fileNodes = getMatchingChildNodes(root, "File")
for fileNode in fileNodes:
name = getText(fileNode.childNodes)
if (fileNode.getAttribute("name")):
newName = fileNode.getAttribute("name")
else:
newName = None
files = glob.glob("%s/%s" % (dirName, name))
for item in files:
item = os.path.basename(item)
dstName = newName
if (dstName == None):
dstName = item
if (len(dirName) > 0):
if (os.path.isfile("%s/%s" % (dirName, item))):
fileList.append(("%s/%s" % (dirName, item), "%s/%s/%s" % (dstDir, dirName, dstName)))
else:
if (os.path.isfile(item)):
fileList.append((item, "%s/%s" % (dstDir, dstName)))
# handle any sub-dirs
if (recursive):
dirNodes = [root]
else:
dirNodes = getMatchingChildNodes(root, "Dir")
for dirNode in dirNodes:
if (recursive):
ignoreNodes = list()
if (len(dirName) > 0):
subDirName = "%s/*" % dirName
else:
subDirName = "*"
else:
ignoreNodes = getMatchingChildNodes(dirNode, "Ignore")
if (len(dirName) > 0):
subDirName = "%s/%s" % (dirName, dirNode.getAttribute("name"))
else:
subDirName = dirNode.getAttribute("name")
subRecursive = recursive
if (not subRecursive):
rStr = dirNode.getAttribute("recursive")
if ((rStr != None) and (rStr == "true")):
subRecursive = True
#print "RECURSIVE (%s)" % subDirName
#print "Checking for '%s'" % subDirName
names = glob.glob("%s" % subDirName)
for name in names:
if (os.path.basename(name) == ".svn"):
continue
# make sure it's not ignored
ignore = False
for ignoreNode in ignoreNodes:
ignoreName = getText(ignoreNode.childNodes)
#print "<----------------Checking '%s' for ignored '%s'" % (os.path.basename(name), ignoreName)
if (ignoreName == os.path.basename(name)):
ignore = True
if (ignore):
#print "IGNORING %s" % name
continue
if (os.path.isdir(name)):
dirList = handleDir(os.path.normpath(name), dstDir, dirNode, subRecursive)
for item in dirList:
fileList.append(item)
return fileList
#------------------------------------------------------------------------------------------
def main(argv):
# rootDir = os.path.dirname(argv[0])
# if (len(rootDir) == 0):
# rootDir = "."
# xmlName = "%s/replay.xml" % rootDir
rootDir = "."
xmlName = "%s/replay.xml" % rootDir
dom1 = xml.dom.minidom.parse(xmlName)
root = dom1.getElementsByTagName("ReplayFiles")
dstDir = None
while (dstDir == None):
dstDir = os.path.normpath("%s/../ReplayDisk" % rootDir)
sys.stdout.write("Enter the replay destination directory [%s]:" % dstDir)
dir = sys.stdin.readline().rstrip('\r\n')
if (len(dir) > 0):
dstDir = dir
fileCopyList = list()
rootList = handleDir(rootDir, dstDir, root[0])
for item in rootList:
fileCopyList.append(item)
if (not copyFiles(fileCopyList)):
return False
print "\n-----------------------------"
print "Replay disk creation complete"
print "-----------------------------"
return True
#------------------------------------------------------------------------------------------
if __name__ == '__main__':
if (main(sys.argv) != True):
sys.exit(-1);