-
Notifications
You must be signed in to change notification settings - Fork 1
/
generator.py
executable file
·56 lines (39 loc) · 1.25 KB
/
generator.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
#!/usr/bin/env python
import os, sys
if len(sys.argv) == 4 and sys.argv[1] == "--list":
outPath = sys.argv[2]
fileWithNumber = sys.argv[3]
with open(fileWithNumber) as f:
numFiles = int(f.read().strip())
print(os.path.join(outPath, "server.h"))
for num in range(numFiles):
print(os.path.join(outPath, "method%s.h" % num))
sys.exit(0)
if len(sys.argv) == 3:
outPath = sys.argv[1]
fileWithNumber = sys.argv[2]
with open(fileWithNumber) as f:
numFiles = int(f.read().strip())
if not os.path.exists(outPath):
os.makedirs(outPath)
else:
print("Incorrect args. Use ./generator.py [--list] /path/to/output numFiles")
with open(os.path.join(outPath, "server.h"), "w") as serverFile:
for num in range(numFiles):
serverFile.write('#include "method%s.h"\n' % num)
serverFile.write("""
class Server {
public:
""")
for num in range(numFiles):
serverFile.write(' Method%s* call%s() { return new Method%s; }\n' % (num, num, num))
serverFile.write("""};
""")
for num in range(numFiles):
with open(os.path.join(outPath, "method%s.h" % num), "w") as methodFile:
methodFile.write("""
#include <QObject>
class Method%s : public QObject {
Q_OBJECT
};
""" % num)