-
Notifications
You must be signed in to change notification settings - Fork 13
/
simplefilejoiner.py
72 lines (51 loc) · 1.79 KB
/
simplefilejoiner.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
if __name__ == '__main__':
output_files = [
'./simple/secs.py',
'./example/secs.py'
]
target = 'secs'
files = [
'secs2body.py',
'smlparser.py',
'secsmessage.py',
'hsmsssmessage.py',
'secs1message.py',
'secscommunicator.py',
'hsmssscommunicator.py',
'hsmsssactivecommunicator.py',
'hsmssspassivecommunicator.py',
'secs1communicator.py',
'secs1ontcpipcommunicator.py',
'secs1onpyserialcommunicator.py',
'gem.py'
]
try:
bf_imports = list()
bf_lines = list()
for fn in [('./' + target + '/' + f) for f in files]:
with open(fn, mode='r') as fp:
print('read file: ' + fn)
for line in [l.rstrip() for l in fp.readlines()]:
if line.startswith('import '):
s = line[7:].strip()
if s != target:
bf_imports.append(line)
else:
bf_lines.append(line)
targetpath = target + '.'
for output_file in output_files:
print('try-write: ' + output_file)
with open(output_file, mode='w') as fp:
for line in set(bf_imports):
fp.write(line)
fp.write('\n')
for line in bf_lines:
s = line.rstrip().replace(targetpath, '')
fp.write(s)
fp.write('\n')
fp.write('\n\n')
fp.write("if __name__ == '__main__':\n")
fp.write(" print('write here')\n")
print('wrote: ' + output_file)
except Exception as e:
print(e)