def check_dockerfile_dependencies(self) -> Union[TaskError, bool]: """Verify task file dependencies against computed file dependencies.""" error_tplt = ('Missing Dockerfile file dependencies in' ' build target: \n{dockerfile}:\n\t{errors}') deps = self.load_deps_from_dockerfile() errors: List[str] = [] for dep in deps: errors.extend(dep.verify(self.file_dep)) if errors: error_message = error_tplt.format(dockerfile=self.dockerfile, errors='\n\t'.join(errors)) return TaskError(msg=error_message) return None
def update_gist(file): if is_continuous_integration() and check_cmd('gist') is not TaskFailed: gist_id = 'a9ada04ad9ee0b1920994b7a55f22774' command = shlex.split('gist -u {} {}'.format(gist_id, file)) p = subprocess.Popen(command, stdin=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) out, err = p.communicate() if p.poll() > 0: return TaskError("Command '{}' failed.\n{}".format( " ".join(command), out))
def cmd_with_animation(cmd="", path=".", log_file=None): current_path = os.getcwd() os.chdir(path) p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) subprocess_wait_animation(p) out, err = p.communicate() if not log_file: print(out.strip()) else: with open(log_file, 'w') as f: f.write(out) if p.poll() > 0: return TaskError("Command '{}' failed.\n{}".format(" ".join(cmd), err)) os.chdir(current_path)
def make_install(): current_path = os.getcwd() os.chdir(source_path) command = shlex.split( 'make install -j{}'.format(multiprocessing.cpu_count() + 1)) try: p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) except FileNotFoundError as e: raise e subprocess_wait_animation(p) os.chdir(current_path) nonlocal log_path system = platform.system() if system == 'Darwin': system = 'osx' elif system == 'Linux': system = 'linux' elif system == 'Windows': system = 'windows' log_path = os.path.join(source_path, 'make_install-{}.log'.format(system)) print('Make install log written to {}'.format(log_path)) out, err = p.communicate() with open(log_path, 'w') as f: f.write(out) update_gist(log_path) if p.poll() > 0: return TaskError("Command '{}' failed.\n{}".format( " ".join(command), err))
def configure(): current_path = os.getcwd() os.chdir(source_path) command = shlex.split( './configure -prefix {} -static -release -nomake examples'.format( config['qt-static-dir'])) try: p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) except FileNotFoundError as e: raise e subprocess_wait_animation(p) os.chdir(current_path) nonlocal log_path system = platform.system() if system == 'Darwin': system = 'osx' elif system == 'Linux': system = 'linux' elif system == 'Windows': system = 'windows' log_path = os.path.join(source_path, 'configure-{}.log'.format(system)) print('Configure log written to {}'.format(log_path)) out, err = p.communicate() with open(log_path, 'w') as f: f.write(out) update_gist(log_path) if p.poll() > 0: return TaskError("Command '{}' failed.\n{}".format( " ".join(command), err))
def execute(self, out=None, err=None): """Execute command action both stdout and stderr from the command are captured and saved on self.out/err. Real time output is controlled by parameters :param out: None - no real time output a file like object (has write method) :param err: idem :return failure: see CmdAction.execute """ # set std stream old_stdout = sys.stdout output = StringIO() out_writer = Writer() # capture output but preserve isatty() from original stream out_writer.add_writer(output, old_stdout.isatty()) if out: out_writer.add_writer(out) sys.stdout = out_writer old_stderr = sys.stderr errput = StringIO() err_writer = Writer() err_writer.add_writer(errput, old_stderr.isatty()) if err: err_writer.add_writer(err) sys.stderr = err_writer kwargs = self._prepare_kwargs() # execute action / callable try: returned_value = self.py_callable(*self.args, **kwargs) except Exception as exception: return TaskError("PythonAction Error", exception) finally: # restore std streams /log captured streams sys.stdout = old_stdout sys.stderr = old_stderr self.out = output.getvalue() self.err = errput.getvalue() # if callable returns false. Task failed if returned_value is False: return TaskFailed("Python Task failed: '%s' returned %s" % (self.py_callable, returned_value)) elif returned_value is True or returned_value is None: pass elif isinstance(returned_value, six.string_types): self.result = returned_value elif isinstance(returned_value, dict): self.values = returned_value self.result = returned_value elif isinstance(returned_value, TaskFailed) \ or isinstance(returned_value, TaskError): return returned_value else: return TaskError( "Python Task error: '%s'. It must return:\n" "False for failed task.\n" "True, None, string or dict for successful task\n" "returned %s (%s)" % (self.py_callable, returned_value, type(returned_value)))
def error_sample(): return TaskError("so sad") ye_olde_action = action.PythonAction(error_sample)
def decorated_task(*args: Any, **kwargs: Any) -> Optional[TaskError]: try: task_func(*args, **kwargs) except expected_exn as err: return TaskError(handler(err)) return None
def error_sample(): return TaskError("so sad")