def fail(self, msg=None): """Called to record a failed configuration.""" self.result = False if self.blocking: common.error("cannot configure %s: %s" % self.name, msg) else: self.ctx.print_action_failure(msg)
def makedir(path): """Build a directory if not existing, building possibly intermediate directories.""" path = str(path) if not os.path.isdir(path): try: os.makedirs(path) except os.error as e: common.error("cannot create '%s': %s" % (path, e))
def execute(self, ctx): for p in self.paths: try: ctx.print_command("remove '%s'" % p) if p.actual().is_dir(): shutil.rmtree(str(p)) else: os.remove(str(p)) except OSError as e: if not self.ignore_error: common.error(str(e))
def execute(self, ctx): try: ctx.print_action(self.signature()) path = self.install_path() lowlevel.makedir(path) shutil.copyfile(str(self.file), str(path / self.file.path.get_file())) ctx.print_action_success() except IOError as e: msg = str(e) ctx.print_action_failure(msg) common.error("installation failed")
def prepare(self): """Prepare the target to run the action.""" self.start_time = common.time() if self.target.recipe != None: for r in self.target.recipe.ress: ppath = r.actual().parent() if not r.is_phony and not ppath.exists(): try: os.makedirs(str(ppath)) except error != e: common.error(env.ElfError(str(e))) self.push_env()
def action(self, ctx): #ctx.print_info("Testing %s" % self.ress[0]) self.succeeded = 0 for test in self.tests: test.test(ctx) if self.succeeded == len(self.tests): ctx.out.write(io.BOLD + io.GREEN + "\tSUCCESS: all tests passed!\n" + io.NORMAL) else: ctx.out.write(io.BOLD + io.RED + "\tFAILURE: %d test(s) failed on %d\n" % (len(self.tests) - self.succeeded, len(self.tests)) + io.NORMAL) common.error("Test failed.")
def invoke(cmd, ctx, out=None, err=None): """Launch the given command in the current shell.""" if cmd == "None": cmd() # print command line = make_line(cmd) ctx.print_command(line) # prepare streams ins = [] if out == False: out_arg = subprocess.DEVNULL elif out == None: out_arg = subprocess.PIPE else: out_arg = out if err == False: err_arg = subprocess.DEVNULL elif err == None: err_arg = subprocess.PIPE else: err_arg = err # run the process proc = subprocess.Popen(line, shell=True, stdout=out_arg, stderr=err_arg) # manage outputs map = {} if out == None: map[proc.stdout] = ctx.out if err == None: map[proc.stderr] = ctx.err ins = list(map.keys()) while ins: useds, x, y = select.select(ins, [], []) for used in useds: line = used.readline() if line: map[used].write(line.decode(sys.getdefaultencoding())) else: ins.remove(used) # wait end of called process r = proc.wait() if r != 0: common.error("build failed")
def execute(self, ctx): try: invoke(self.cmd, ctx) except OSError as e: common.error(str(e))
def execute(self, ctx): # TODO try: pass except OSError as e: common.error(str(e))