forked from CondorLang/Condor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure
executable file
·135 lines (114 loc) · 3.52 KB
/
configure
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
#!/usr/bin/python
import optparse, os, string
parser = optparse.OptionParser()
parser.add_option('-f', '--internal-files',
action="store_true", dest="internalFiles",
help="Internal files", default=False)
parser.add_option('-r', '--update-readme',
action="store_true", dest="noUpdateReadme",
help="Update the readme file", default=False)
options, args = parser.parse_args()
def getBytes(name):
if os.path.isfile(name):
fh = open(name, 'rb')
ba = bytearray()
try:
ba = bytearray(fh.read())
finally:
fh.close
fh.close()
return ba;
def clean(name):
if os.path.isfile(name):
os.remove(name)
def getTodo(lines, file, i):
result = []
split = lines.split('\n')
for line in split:
if 'TODO: ' in line:
s = line.split('TODO: ')
result.append(file + ' ' + str(i) + ' - ' + s[1])
return result
def updateReadme():
rootdir = 'src/'
todos = []
output = ''
with open('readme.md','r+') as fout:
for root, subFolders, files in os.walk(rootdir):
for file in files:
if '.cc' in file or '.h' in file:
with open(os.path.join(root, file), 'r') as fin:
i = 0
for lines in fin:
i = i + 1
todos.extend(getTodo(lines, file, i))
found = False
for lines in fout:
if 'Todo:' in lines:
found = True
elif not found:
output += lines
if found:
break
output += 'Todo:\n------'
for todo in todos:
output += '\n - ' + todo
fout.close()
os.remove('readme.md')
f = open('readme.md', 'w+')
f.write(output)
def toFile(fName, s):
if string:
f = open(fName,'wb')
newFileByteArray = bytearray(s)
f.write(newFileByteArray) # python will convert \n to os.linesep
f.close() # you can omit in most cases as the destructor will call it
def toHex(s):
lst = []
for ch in s:
hv = hex(ord(ch)).replace('0x', '')
if len(hv) == 1:
hv = '0'+hv
lst.append(hv)
return reduce(lambda x,y:x+y, lst)
def toOutputFile(hex, className):
fileContents = '''
namespace Condor{
namespace internal{
static const char* '''
fileContents += className
fileContents += '''Bytes = "'''
fileContents += hex
fileContents += '''";
} // namespace internal
} // namespace Condor
'''
return fileContents.strip()
def getCbFiles():
rootdir = 'src/'
for root, subFolders, files in os.walk(rootdir):
for file in files:
if '.cb' in file:
name = file.split('.cb')[0]
name = name.capitalize()
start(os.path.join(root, file), name)
def start(name, className):
bytesname = string.replace(name, '.cb', '-bytes.h')
clean(string.replace(name, '.cb', '.o'))
clean(bytesname)
s = getBytes(name)
hexa = toHex(s.decode("utf-8"))
out = toOutputFile(hexa, className)
toFile(bytesname, out)
def checkFolders():
dirs = ['win32', 'linux', 'darwin']
for directory in dirs:
directory = 'build/' + directory
if not os.path.exists(directory):
os.makedirs(directory)
if __name__ == "__main__":
# if options.internalFiles:
# getCbFiles()
if options.noUpdateReadme:
updateReadme()
checkFolders()