Ejemplo n.º 1
0
 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()
Ejemplo n.º 2
0
 def get_flags_as_string(self):
     if self._defunct:
         return term.red("[defunct]")
     if self.killed:
         return term.lightred("[killed]")
     if self.stopped:
         return term.lightblack("[done]")
     return ""
Ejemplo n.º 3
0
 def get_flags_as_string(self):
     if self._defunct:
         return term.red('[defunct]')
     if self.killed:
         return term.lightred('[killed]')
     if self.stopped:
         return term.lightblack('[done]')
     return ''
Ejemplo n.º 4
0
 def get_flags_as_string(self):
     if self._defunct:
         return term.red('[defunct]')
     if self.killed:
         return term.lightred('[killed]')
     if self.stopped:
         return term.lightblack('[done]')
     return ''
Ejemplo n.º 5
0
    def execute(self, command, *, cwd, shell=True):
        self.logger.info(
            term.bold(">>> %s") + " " + term.lightblack("(in %s)"), command,
            cwd)

        retval = subprocess.call(command, cwd=cwd, shell=shell)

        if retval:
            self.logger.error(term.red(term.bold("... ✖ failed")))
            raise RuntimeError('"{}" returned {}.'.format(command, retval))
        else:
            self.logger.info(term.green(term.bold("... ✓ ok")))
Ejemplo n.º 6
0
    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
Ejemplo n.º 7
0
 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()
Ejemplo n.º 8
0
 def _log_file(self, target, override, content=()):
     self.dispatcher.info(
         term.bold(term.red('W!') if override else term.green('W?')), target, '({} bytes)'.format(len(content))
     )
Ejemplo n.º 9
0
 def _log_file(self, target, override, content=()):
     self.dispatcher.info(
         term.bold(term.red("W!") if override else term.green("W?")), target, "({} bytes)".format(len(content))
     )
Ejemplo n.º 10
0
    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
Ejemplo n.º 11
0
 def _log_file(self, target, override, content=()):
     self.dispatcher.info(
         term.bold(term.red("W!") if override else term.green("W?")),
         target, "({} bytes)".format(len(content)))