This repository was archived by the owner on Aug 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjob_control.py
More file actions
55 lines (47 loc) · 1.87 KB
/
Copy pathjob_control.py
File metadata and controls
55 lines (47 loc) · 1.87 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
import json
import logging
class jobs():
def __init__(self, filename='./job_list.json'):
self.job_list = list()
self.filename = filename
with open(self.filename, 'r') as fp:
self.job_list = json.load(fp)
#
def add_job(self, job_id, server, user, work_dir, local, status, job_name='', hide=False):
self.job_list.insert(0, {"name": job_name,
"id": job_id,
"server": server,
"user": user,
"work_dir": work_dir,
"local": local,
"status": status,
"hide": hide})
with open(self.filename, 'w') as fp:
json.dump(self.job_list, fp)
#
def update_job_status(self, job_id, status):
for i in self.job_list:
if i['id'] == job_id:
i['status'] = status
break
with open(self.filename, 'w') as fp:
json.dump(self.job_list, fp)
#
def query_job_info(self, job_id):
for i in self.job_list:
if i['job_id'] == job_id:
return i
def hide(self, idx):
logging.debug("Change job visibility from {} to {}.".format(not self.job_list[idx]['hide'],
self.job_list[idx]['hide']))
self.job_list[idx]['hide'] = not self.job_list[idx]['hide']
with open(self.filename, 'w') as fp:
json.dump(self.job_list, fp)
def delete(self, idx):
logging.debug(f"Delete job {idx}.")
del self.job_list[idx]
with open(self.filename, 'w') as fp:
json.dump(self.job_list, fp)
def save(self):
with open(self.filename, 'w') as fp:
json.dump(self.job_list, fp)