-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutilsLib.py
60 lines (47 loc) · 1.54 KB
/
utilsLib.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
import os
import re
def loadText(f_path):
f = open(f_path, "r")
textModel = f.read()
f.close()
return textModel
# Carica il file facendo di ogni linea una lista, e ogni 'tab' nella linea
# una sotto lista, considera '#' e '/' a inizio riga come commento
def loadDoubleList(f_path, minColon=0):
f = open(f_path, "r")
repLists = []
for line in f:
repLine = line.strip('\n')
if len(repLine) > 0:
if repLine[0] == "/" or repLine[0] == "#":
continue
repLine = repLine.replace("\n", "")
line_list = repLine.split("\t")
if len(line_list) >= minColon or minColon == 0:
repLists.append(line_list)
f.close()
return repLists
def saveString(path_write, outStr):
text_file = open(path_write, "w")
n = text_file.write(outStr)
text_file.close()
if (len(outStr) != n):
print("ATTENTION, not all string was saving in the '" + path_write + "' file")
def generateBlock(textModel, repLists):
out = ""
for repLine in repLists:
newText = textModel
for i in range(len(repLine)):
repStr = "<rep{index}>".format(index=i)
newText = newText.replace(repStr, repLine[i])
out = out + newText
print(out)
return out
def generateFindReplace(textToReplace, frLists):
out = textToReplace
for sList in frLists:
out = out.replace(sList[0], sList[1])
return out
def get_trailing_number(s):
m = re.search(r'\d+$', s)
return int(m.group()) if m else None