-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtools.py
51 lines (44 loc) · 1.6 KB
/
tools.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
from authorized import cg_list, cluster_list
# extract all given cgs in authorized into a regex id pattern
def generateCgRegexPattern():
regex_pattern = '('
for cg in cg_list:
cg = bracketize(cg)
regex_pattern += cg + '|'
regex_pattern = rreplace(regex_pattern, '|', ')', 1)
return regex_pattern
# extract all given clusters in authorized into a regex id pattern
def generateClusterRegexPattern():
regex_pattern = '('
for cluster in cluster_list:
regex_pattern += cluster + '|'
regex_pattern = rreplace(regex_pattern, '|', ')', 1)
return regex_pattern
# extract all given clusters and cgs in authorized into a regex id pattern
def generateCgAndClusterRegexPattern():
regex_pattern = '('
for cg in cg_list:
regex_pattern += cg + '|'
for cluster in cluster_list:
regex_pattern += cluster + '|'
regex_pattern = rreplace(regex_pattern, '|', ')', 1)
return regex_pattern
# Replaces substrings within text, from the back
def rreplace(s, old, new, occurrence):
li = s.rsplit(old, occurrence)
return new.join(li)
def getTime():
return datetime.datetime.fromtimestamp(time.time()).strftime('%H:%M:%S, %d %B %Y ')
def groupArg2List(groupList):
if '+' not in groupList:
return [groupList]
else:
return re.split('\s*+\s*', groupList)
# This function prepends '\' to '(' or ')' for regex matching of CGs with brackets in name.
def bracketize(cg):
if '(' in cg or ')' in cg:
bracketOpenIndex = cg.find('(')
bracketCloseIndex = cg.find(')')
cg = cg[:bracketOpenIndex] + '\\' + cg[bracketOpenIndex:]
cg = cg[:bracketCloseIndex+1] + '\\' + cg[bracketCloseIndex+1:]
return cg