class Copy(Task): def __init__(self, source, destination): super(Copy, self).__init__() if isinstance(source, str): source = [source] self.__source = Lazy(source) self.__destination = Lazy(destination) @property def name(self): if self.__source.type() == list: src = self.__source()[0] else: src = self.__source.peek() return "Copy_{}_".format(os.path.basename(src)) def process(self, progress): if os.path.isabs(self.__destination()): full_destination = self.__destination() else: full_destination = os.path.join(self._context["build_path"], self.__destination()) for source in self.__source(): if not os.path.isabs(source): source = os.path.join(self._context["build_path"], source) if not os.path.exists(full_destination): os.makedirs(full_destination) if os.path.isfile(source): shutil.copy(source, full_destination) else: print "{} doesn't exist, Can't copy".format(source) return True
class Copy(Task): def __init__(self, source, destination): super(Copy, self).__init__() if isinstance(source, str): source = [source] self.__source = Lazy(source) self.__destination = Lazy(destination) @property def name(self): if self.__source.type() == list: return "Copy {}...".format(self.__source()[0]) else: return "Copy {}".format(self.__source.peek()) def process(self, progress): if os.path.isabs(self.__destination()): full_destination = self.__destination() else: full_destination = os.path.join(self._context["build_path"], self.__destination()) for source in self.__source(): if not os.path.isabs(source): source = os.path.join(self._context["build_path"], source) if not os.path.exists(full_destination): os.makedirs(full_destination) shutil.copy(source, full_destination) return True
class Run(Builder): def __init__(self, command, fail_behaviour=Task.FailBehaviour.FAIL, environment=None, working_directory=None, name=None): super(Run, self).__init__() self.__command = Lazy(command) self.__name = name self.__fail_behaviour = fail_behaviour self.__environment = Lazy(environment) self.__working_directory = Lazy(working_directory) @property def name(self): if self.__name: return "run {}".format(self.__name) else: return "run {}".format(self.__command.peek().split()[0]).replace( "\\", "/") def process(self, progress): if "build_path" not in self._context: logging.error( "source path not known for {}," " are you missing a matching retrieval script?".format( self.name)) soutpath = os.path.join(self._context["build_path"], "stdout.log") serrpath = os.path.join(self._context["build_path"], "stderr.log") with open(soutpath, "w") as sout: with open(serrpath, "w") as serr: environment = dict(self.__environment() if self.__environment( ) is not None else config["__environment"]) cwd = str( self.__working_directory() if self.__working_directory( ) is not None else self._context["build_path"]) sout.write("running {} in {}".format(self.__command(), cwd)) proc = Popen(self.__command(), env=environment, cwd=cwd, shell=True, stdout=sout, stderr=serr) proc.communicate() if proc.returncode != 0: logging.error( "failed to run %s (returncode %s), see %s and %s", self.__command(), proc.returncode, soutpath, serrpath) return False return True
class Run(Builder): def __init__(self, command, fail_behaviour=Task.FailBehaviour.FAIL, environment=None, working_directory=None, name=None): super(Run, self).__init__() self.__command = Lazy(command) self.__name = name self.__fail_behaviour = fail_behaviour self.__environment = Lazy(environment) self.__working_directory = Lazy(working_directory) @property def name(self): if self.__name: return "run {}".format(self.__name) else: return "run {}".format(self.__command.peek().split()[0]).replace("\\", "/") def process(self, progress): if "build_path" not in self._context: logging.error("source path not known for {}," " are you missing a matching retrieval script?".format(self.name)) soutpath = os.path.join(self._context["build_path"], "stdout.log") serrpath = os.path.join(self._context["build_path"], "stderr.log") with open(soutpath, "w") as sout: with open(serrpath, "w") as serr: environment = dict(self.__environment() if self.__environment() is not None else config["__environment"]) cwd = str(self.__working_directory() if self.__working_directory() is not None else self._context["build_path"]) sout.write("running {} in {}".format(self.__command(), cwd)) proc = Popen(self.__command(), env=environment, cwd=cwd, shell=True, stdout=sout, stderr=serr) proc.communicate() if proc.returncode != 0: logging.error("failed to run %s (returncode %s), see %s and %s", self.__command(), proc.returncode, soutpath, serrpath) return False return True
class Run_With_Output(Builder): def __init__(self, command, fail_behaviour=Task.FailBehaviour.FAIL, environment=None, working_directory=None, name=None): super(Run_With_Output, self).__init__() self.__command = Lazy(command) self.__name = name self.__fail_behaviour = fail_behaviour self.__environment = Lazy(environment) self.__working_directory = Lazy(working_directory) @property def name(self): if self.__name: return "run {}".format(self.__name) else: return "run {}".format(self.__command.peek().split()[0]).replace( "\\", "/") def process(self, progress): environment = dict(self.__environment() if self.__environment( ) is not None else config["__environment"]) cwd = str(self.__working_directory() if self.__working_directory( ) is not None else self._context["build_path"]) proc = Popen(self.__command(), env=environment, cwd=cwd, shell=True) proc.communicate() if proc.returncode != 0: if isinstance(proc.returncode, (str, unicode)): logging.error( "failed to run %s (returncode %s), see %s and %s", self.__command(), proc.returncode) return False else: logging.error("failed to run {} (returncode {})".format( self.__command(), proc.returncode)) return False return True