-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.py
executable file
·64 lines (48 loc) · 1.2 KB
/
build.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
#!/usr/bin/env python3
import sys
import os.path
file="source.txt"
if len(sys.argv) >= 2:
file = sys.argv[1]
if not os.path.exists(file):
print("File not found: ", file)
print("USAGE:\n %s [source.txt]\n" % sys.argv[0])
exit(1)
replace_char = None
replace_with = None
with open(file) as f:
while True:
line = f.readline()
if not line:
break
line = line.strip()
if len(line) == 0:
continue
if line.startswith('#:config '):
# remove config
line = line[9:]
if line.startswith('replace '):
# remove replace
line = line[9:]
(char, sep, wit) = line.partition(' with ')
if not char or not sep or not wit:
continue
if len(char) > 1:
char = char.strip('"').strip("'")
replace_char = char
replace_with = []
for i in wit.split(','):
if len(i) > 1:
i = i.strip('"').strip("'")
replace_with.append(i)
print('Replace Char "%s"' % replace_char, file=sys.stderr)
print('\tWith', replace_with, file=sys.stderr)
continue
elif line[0] == '#':
continue
# Adding list
print(line)
# Replace chars
if replace_char and line.find(replace_char) >= 0:
for char in replace_with:
print( line.replace(replace_char, char) )