-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeljob
More file actions
57 lines (50 loc) · 1.39 KB
/
deljob
File metadata and controls
57 lines (50 loc) · 1.39 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
#!/share/apps/miniconda3/bin/python
# by jtyang 2021 May 7th
# revised by jtyang 2021 Oct 23
# revised by jtyang 2022 Sep
import os
import time
import re
import sys
def get_job_list():
""" get job list"""
username = os.popen('whoami').readline()[:-1]
jobStr = os.popen("qstat -u `whoami` ").read()
job_list = []
lines= re.split('\n', jobStr)
for l in lines[5:-1]:
w_list = re.split('\s+', l)
#if w_list[-2] == 'R':
# job_list.append(w_list[0])
job_list.append(w_list[0])
return job_list
def str2slice(mystring):
# https://stackoverflow.com/questions/680826/python-create-slice-object-from-string by pprzemek
if not ':' in mystring:
res = int(mystring)
else:
res = slice(*map(lambda x: int(x.strip()) if x.strip() else None, mystring.split(':')))
return res
def test_stri2slice():
l = [0, 1, 2, 3]
x_l = [ "3", ":3", "2:", "1:3", "::2" ]
print("""sample:
3
[0, 1, 2]
[2, 3]
[1, 2]
[0, 2]""")
print("test:")
for x in x_l:
print(l[str2slice(x)])
def del_list(job_list):
for j in job_list:
stream = os.popen("qdel "+ j)
print(stream.read())
def test():
job_list = get_job_list()
print(job_list)
assert len(sys.argv) == 2, "Pls input a py formatted range to delete( a, a:, :b, a:b )"
del_list(job_list[str2slice(sys.argv[1])] )
test()
# test_stri2slice()