Skip to content

Commit f778f7a

Browse files
committed
update init and callback interface
1 parent 5513f41 commit f778f7a

File tree

4 files changed

+35
-23
lines changed

4 files changed

+35
-23
lines changed

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def version(self):
5454
self.version_file = os.path.join(self.source_dir, f)
5555
break
5656
if not os.path.isfile(self.version_file):
57-
raise OSError("version not found")
57+
raise IOError("version not found")
5858
with open(self.version_file) as fi:
5959
c = fi.read()
6060
exec(compile(c, self.version_file, "exec"), v)

src/job.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ def __init__(self, jobfile, mode=None, workdir=os.getcwd(), config=None):
365365
jobfile = tmp_jobfile
366366
self._path = abspath(jobfile)
367367
if not exists(self._path):
368-
raise OSError("No such file: %s" % self._path)
368+
raise IOError("No such file: %s" % self._path)
369369
self._pathdir = self.temp and self.workdir or dirname(self._path)
370370
self.logdir = join(self._pathdir, "log")
371371
self.mode = self.has_sge and (mode or "sge") or "localhost"

src/jobstat.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,11 @@ def main():
169169
elif isdir(jobfile):
170170
logdir = abspath(jobfile)
171171
else:
172-
raise OSError("No such file or directory %s." % jobfile)
172+
raise IOError("No such file or directory %s." % jobfile)
173173

174174
if not isdir(logdir):
175175
return
176-
#raise OSError("No such log_dir %s" % logdir)
176+
#raise IOError("No such log_dir %s" % logdir)
177177
if submit == 0:
178178
submit = len([i for i in os.listdir(
179179
logdir) if i.endswith(".log")])

src/run.py

+31-19
Original file line numberDiff line numberDiff line change
@@ -196,26 +196,38 @@ def check_already_success(self):
196196
job.status = "wait"
197197

198198
def init_callback(self):
199-
for name in ["init", "call_back"]:
200-
cmd = self.conf.rget("args", name)
201-
if not cmd:
202-
continue
199+
self.add_init(self.conf.rget("args", "init"))
200+
self.add_callback(self.conf.rget("args", "call_back"))
201+
202+
def add_init(self, init=""):
203+
if init:
204+
if "init" in self.totaljobdict:
205+
job = self.totaljobdict["init"]
206+
return self.logger.error("init '%s' exists", job.rawstring)
203207
job = Job(self.conf)
204-
job = job.from_cmd(self.jfile, linenum=-1, cmd=cmd)
205-
job.to_local(jobname=name, removelog=False)
206-
self.totaljobdict[name] = job
207-
if name == "init":
208-
self.jobs.insert(0, job)
209-
f = self.jobsgraph.ind_nodes()
210-
self.jobsgraph.add_node_if_not_exists(job.jobname)
211-
for j in f:
212-
self.jobsgraph.add_edge(name, j)
213-
else:
214-
self.jobs.append(job)
215-
f = self.jobsgraph.end_nodes()
216-
self.jobsgraph.add_node_if_not_exists(job.jobname)
217-
for j in f:
218-
self.jobsgraph.add_edge(j, name)
208+
job = job.from_cmd(self.jfile, linenum=-1, cmd=init)
209+
job.to_local(jobname="init", removelog=False)
210+
self.totaljobdict["init"] = job
211+
self.jobs.insert(0, job)
212+
ind_nodes = self.jobsgraph.ind_nodes()
213+
self.jobsgraph.add_node_if_not_exists(job.jobname)
214+
for j in ind_nodes:
215+
self.jobsgraph.add_edge("init", j)
216+
217+
def add_callback(self, callback=""):
218+
if callback:
219+
if "callback" in self.totaljobdict:
220+
job = self.totaljobdict["callback"]
221+
return self.logger.error("callback '%s' exists", job.rawstring)
222+
job = Job(self.conf)
223+
job = job.from_cmd(self.jfile, linenum=-1, cmd=callback)
224+
job.to_local(jobname="callback", removelog=False)
225+
self.totaljobdict["callback"] = job
226+
self.jobs.append(job)
227+
end_nodes = self.jobsgraph.end_nodes()
228+
self.jobsgraph.add_node_if_not_exists(job.jobname)
229+
for j in end_nodes:
230+
self.jobsgraph.add_edge(j, "callback")
219231

220232
def log_status(self, job):
221233
name = job.jobname

0 commit comments

Comments
 (0)