-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_squeue_nodelist.py
More file actions
143 lines (122 loc) · 3.54 KB
/
parse_squeue_nodelist.py
File metadata and controls
143 lines (122 loc) · 3.54 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import re
import sys
import os
suffix=".frontera.tacc.utexas.edu"
def getThreeDigitFormat(num):
numStr = str(num)
newNumStr = ""
numZeros = 3 - len(numStr)
#print "numzero is "+ str(numZeros)
if(numZeros < 0):
sys.exit("4 digit number here!")
i=1
while(i <= numZeros):
newNumStr += "0";
i += 1
newNumStr += numStr
return newNumStr
def getLongMachName(base, string):
return base + "-" + string + suffix
def getSeparateList(base, nodelist):
list3=[]
list4 = nodelist.split(",")
for val in list4:
#print "val: " + val
if(val == ""):
continue
list5 = val.split("-")
#print list5
if(len(list5) == 1):
#print "1 sized list" + str(list5)
num1 = int(list5[0])
#print "number is " + str(num1)
#print "base is " + base + " string is "+ str(num1)
final = getLongMachName(base, getThreeDigitFormat(str(num1)))
#print "final string is " + final
finalList.append(final)
#list3.append(final)
elif(len(list5) == 2): #range
#print "range list" + str(list5)
num1 = int(list5[0])
num2 = int(list5[1])
#print "number is " + str(num1) + " and second number is " + str(num2)
#print "Item 1 is "+list5[1] + " and item 2 is "+list5[2]
for x in range(num1,num2 + 1):
#print "base is " + base + " string is "+ str(x)
final = getLongMachName(base, getThreeDigitFormat(str(x)))
#print "final string is " + final
finalList.append(final)
#list3.append(final)
else:
sys.exit("Incorrect parsing in getSeparate list, cannot have size>2")
return list3
n=len(sys.argv)
if(n < 2):
sys.exit("Too few arguments! Pass the nodelist which you want to split");
elif(n > 2):
sys.exit("Too many arguments! Pass the nodelist which you want to split");
else:
nodes=sys.argv[1]
finalList=[]
#pattern = "c\d+-\[?[\d,]+\]?"
pattern = "c[\[\],\d-]+"
#nodes = "c108-[053,121],c109-[053,163,193],c110-123,c111-174,c117-191,c119-181,c120-[063,091,123,133],c122-[043,072,153]"
#nodes = "c45-001,c67-009,c67-878,c87-[078-080]"
#nodes = "c45[,c78,c78,c76[,c70-[078-080]"
nodelist = re.findall(pattern, nodes)
#print "nodelist is " + str(nodelist)
#print nodelist
for nodeStr in nodelist:
#print "Node str is " + nodeStr
pattern1 = "^(c\d+)-\[?([-,\d]+)\]?"
regex1 = re.compile(pattern1)
m1 = regex1.search(nodeStr)
if m1:
#print "match one is " + m1.group(1)
#print "match two is " + m1.group(2)
getSeparateList(m1.group(1), m1.group(2))
else:
print "no match"
#print "computed finalList of size :"+ str(len(finalList))
#print finalList
for i in finalList:
print i+";",
#reSetOfNodes= "(\w+)-(\[[-,\w]+\])"
#getSeparateList("c161","002-004,011-014,021-024,031-034,041")
#c108-[053,121],c109-[053,163,193],c110-123,c111-174,c117-191,c119-181,c120-[063,091,123,133],c122-[043,072,153]
#list1 = nodes.split("c")
#print list1
#print "jobid is" + jobid
#jobQuery = "squeue -j "+ jobid + " -h -o %N"
#nodelist = os.system(jobQuery)
#print "nodelist is " + nodelist
#reSetOfNodes= "(\w+)-(\[[-,\w]+\])"
#p1 = reSetOfNodes.compile(reSetOfNodes)
#
#nodes="c161-[002-004,011-014,021-024,031-034,041],c787-[323]"
#list1 = nodes.split(,)
#
#for list2 in list1:
# print "Set of Nodes:" + list2
# m1 = p1.search(list2)
# if(m1):
# list3 = getSeparateList(m.group(1), m.group(2));
#
#
#
#getSeparateList(nodes)
#
#
#
#
#
#
#m = p.search(nodes)
#
#
#print "match is m"
#
#print "match one is " + m.group(1)
#print "match two is " + m.group(2)
#list3 = getSeparateList("c161","002-004,011-014,021-024,031-034,041")
#print list3