def _handle_continue(cls, pipeline, *, filename): if not os.path.exists(filename): raise FileNotFoundError( 'Pipeline “{}” not started, hence you cannot “continue” it. Are you looking for `medikit pipeline {name} start`?'. format(name=pipeline.name) ) # XXX TODO add a lock file during the step and unlock at the end. with open(filename) as f: pipeline.unserialize(f.read()) try: step = pipeline.next() name, current, size, descr = pipeline.name, pipeline.current, len(pipeline), str(step) logger.info( term.black(' » ').join( ( term.lightblue('{} ({}/{})'.format(name.upper(), current, size)), term.yellow('⇩ BEGIN'), term.lightblack(descr), ) ) ) step.run(pipeline.meta) if step.complete: logger.info( term.black(' » ') .join(( term.lightblue('{} ({}/{})'.format(name.upper(), current, size)), term.green('SUCCESS'), )) + '\n' ) else: logger.info( term.black(' » ') .join(( term.lightblue('{} ({}/{})'.format(name.upper(), current, size)), term.red('FAILED'), )) + '\n' ) return except StopIteration: return COMPLETE with open(filename, 'w+') as f: f.write(pipeline.serialize()) return CONTINUE
def _handle_continue(cls, pipeline, *, filename): if not os.path.exists(filename): raise FileNotFoundError( "Pipeline “{}” not started, hence you cannot “continue” it. Are you looking for `medikit pipeline {name} start`?".format( name=pipeline.name ) ) # XXX TODO add a lock file during the step and unlock at the end. with open(filename) as f: pipeline.unserialize(f.read()) try: step = pipeline.next() name, current, size, descr = pipeline.name, pipeline.current, len(pipeline), str(step) logger.info( term.black(" » ").join( ( term.lightblue("{} ({}/{})".format(name.upper(), current, size)), term.yellow("⇩ BEGIN"), term.lightblack(descr), ) ) ) step.run(pipeline.meta) if step.complete: logger.info( term.black(" » ").join( (term.lightblue("{} ({}/{})".format(name.upper(), current, size)), term.green("SUCCESS")) ) + "\n" ) else: logger.info( term.black(" » ").join( (term.lightblue("{} ({}/{})".format(name.upper(), current, size)), term.red("FAILED")) ) + "\n" ) return except StopIteration: return COMPLETE with open(filename, "w+") as f: f.write(pipeline.serialize()) return CONTINUE
def run(self, meta): if self.interractive: os.system(self.cmd) else: child = Process(self.cmd) events = multiprocessing.Queue() parent = multiprocessing.Process(name="task", target=child.run, args=(events, True)) parent.start() exit = False returncode = None while not exit: try: msg = events.get(timeout=0.1) except Empty: if exit: break else: if msg.type == "line": print(term.lightblack("\u2502"), msg.data.decode("utf-8"), end="") elif msg.type == "start": print("$ " + term.lightwhite(self.cmd) + term.black(" # pid=%s" % msg.data["pid"])) elif msg.type == "stop": returncode = msg.data["returncode"] if returncode: print(term.lightblack("\u2514" + term.red(" failed (rc={}). ".format(returncode)))) else: print(term.lightblack("\u2514" + term.green(" success. "))) exit = True if returncode: raise RuntimeError( '"{command}" exited with status {returncode}.'.format(command=self.cmd, returncode=returncode) ) self.set_complete()
def run(self, meta): if self.interractive: os.system(self.cmd) else: child = Process(self.cmd) events = multiprocessing.Queue() parent = multiprocessing.Process(name='task', target=child.run, args=(events, True)) parent.start() exit = False returncode = None while not exit: try: msg = events.get(timeout=0.1) except Empty: if exit: break else: if msg.type == 'line': print(term.lightblack('\u2502'), msg.data.decode('utf-8'), end='') elif msg.type == 'start': print('$ ' + term.lightwhite(self.cmd) + term.black(' # pid=%s' % msg.data['pid'])) elif msg.type == 'stop': returncode = msg.data['returncode'] if returncode: print( term.lightblack('\u2514' + term.red( ' failed (rc={}). '.format(returncode)))) else: print( term.lightblack('\u2514' + term.green(' success. '))) exit = True if returncode: raise RuntimeError( '"{command}" exited with status {returncode}.'.format( command=self.cmd, returncode=returncode)) self.set_complete()