-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextendSupport.py
86 lines (39 loc) · 1.13 KB
/
extendSupport.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
#
# work on this was canceled
#
import re
import pathlib
mySupport = 'mySupport'
newLine = '\n'
def addMySupportToFile(filename, mySupportFilename):
mySupportFilename = pathlib.Path(mySupportFilename).stem
lines = readSupportFileLines(filename)
#if linesAlreadyChanged(lines, mySupportFilename):
# print('File already changed.')
# return()
lines = addImport(lines, mySupportFilename)
def readSupportFileLines(filename):
with open(filename) as f:
lines = f.readlines()
return(lines)
def linesAlreadyChanged(lines, mySupportFilename):
pattern = ''.join(('import.*', mySupportFilename))
for s in lines:
x = re.search(pattern, s)
if x != None:
return True
return False
def addImport(lines, mySupportFilename):
# find index of first import line
pattern = '^import'
for ind, s in enumerate(lines):
x = re.search(pattern, s)
if x != None:
break
# add my import to next line
shlp = ''.join(('import ', mySupportFilename, ' as ', mySupport, newLine))
a = lines.insert(ind+1, shlp)
return lines
if __name__ == '__main__':
addMySupportToFile('main_support.py', 'pokus.py')
debug = 1