def start(name, called=None): """Start a task.""" if name not in tasks: logger.log(logger.red("Task '%s' not in your pylpfile" % name)) else: task = tasks[name] runner = TaskRunner(name, task[0], task[1], called) running.append(runner) return runner
def task(name, deps=None, fn=None): """Define a new task.""" if callable(deps): fn = deps deps = None if not deps and not fn: logger.log(logger.red("The task '%s' is empty" % name)) else: tasks[name] = [fn, deps]
def run(path, tasks): """Run a pylpfile.""" # Test if the pylpfile exists readable_path = make_readable_path(path) if not os.path.isfile(path): logger.log(logger.red("Can't read pylpfile "), logger.magenta(readable_path)) sys.exit(-1) else: logger.log("Using pylpfile ", logger.magenta(readable_path)) # Run the pylpfile try: runpy.run_path(path, None, "pylpfile") except Exception as e: traceback.print_exc(file=sys.stdout) logger.log(logger.red("\nAn error has occurred during the execution of the pylpfile")) sys.exit(-1) # Start the tasks for name in tasks: pylp.start(name) # Wait until all task are executed loop = asyncio.get_event_loop() loop.run_until_complete(wait_and_quit(loop))
def log_finished(self): """Log that this task is done.""" delta = time.perf_counter() - self.start_time logger.log("Finished '", logger.cyan(self.name), "' after ", logger.magenta(time_to_text(delta)))
def log_starting(self): """Log that the task has started.""" self.start_time = time.perf_counter() logger.log("Starting '", logger.cyan(self.name), "'...")