def _test(self, *args, **kwargs): po = PackageOpration() ret = po.test(self.config) if not ret: Log.fatal(Status["STAT_TEST_ERROR"] % self.config.name) else: Log.success(Status["STAT_TEST_SUCCESS"] % self.config.name)
def opt_parser(args, obj): optlist, args = getopt.getopt(args, obj._OPTS["shortcut"], obj._OPTS["name"]) _dict = {} func = None for opt in optlist: opt_name, opt_type = get_opt_name(opt[0]) if opt_name and opt_type is True: if opt_name in obj._OPTS["name"]: index = obj._OPTS["name"].index(opt_name) else: index = -1 elif opt_name and opt_type is False: index = obj._OPTS["shortcut"].find(opt_name) else: index = -1 if index == -1: Log.fatal(Status["STAT_OPT_INVALID"]) func_name = obj._OPTS["action"][index] if func_name is None: _dict[obj._OPTS["name"][index]] = opt[1] or True else: func = obj.__getattribute__(func_name) return func, _dict, args
def __parser(process, ret=True, output=False, *args, **kwargs): res = False process.wait() code = process.poll() if not isinstance(code, int): Log.fatal(Status["STAT_EXEC_ERROR"]) out_strs = [str_decode(line) for line in process.stdout.readlines()] err_strs = [str_decode(line) for line in process.stderr.readlines()] if ret: if code != 0: res = False else: res = out_strs or True if output: if code != 0: puts("\n".join(err_strs)) res = res or False else: puts("\n".join(out_strs)) res = res or True return res
def clone(self, url=None, to_path=None, branch=None): Log.info(Status["STAT_GET_PACKAGE"] % url) g = Git(to_path) g.clone(url or self.github_url) if branch: g.checkout(branch) return True
def __parser(process, ret = True, output = False, *args, **kwargs): res = False process.wait() code = process.poll() if not isinstance(code, int): Log.fatal(Status["STAT_EXEC_ERROR"]) out_strs = [str_decode(line) for line in process.stdout.readlines()] err_strs = [str_decode(line) for line in process.stderr.readlines()] if ret: if code != 0: res = False else: res = out_strs or True if output: if code != 0: puts("\n".join(err_strs)) res = res or False else: puts("\n".join(out_strs)) res = res or True return res
def dep(self, config = None): self.set(config) ret = False if not self.__config: return False gc = GitClient(self.__config) deps = self.__config.dep for dep in deps: dep_name = GitURL2Name(dep) Log.info(Status["STAT_INSTALL_DEP"] % dep_name) if self.find(dep_name, show = False): #dep exist Log.info(Status["STAT_PACKAGE_EXIST"] % dep_name) continue dep_url, dep_tag = DepURL2Git(dep) ret = gc.clone(dep_url, GPM_SRC, dep_tag) if not ret: return ret #install dep dep_path = os.path.join(GPM_SRC, dep_name) conf_path = os.path.join(dep_path, GPM_YML) conf = GPMConf(conf_path) pkg = PackageOpration() pkg.set(conf, dep_path) ret = pkg.install(save=False) if not ret: return False return ret
def publish(self): gc = GitClient(self.__config) ret = gc.publish() if ret: Log.success(Status["STAT_PUBLISH_SUCCESS"]) else: Log.fatal(Status["STAT_PUBLISH_FAILED"])
def _mods(): mods = {} for loader, module_name, is_pkg in pkgutil.walk_packages(__path__): mod = loader.find_module(module_name).load_module(module_name) try: mods[module_name] = mod._MOD except: Log.warn(Status["STAT_LOAD_MOD_ERROR"] % module_name) return mods
def _install(self, *args, **kwargs): if not kwargs.get("yes"): if not confirm("Is install %s ?" % self.config.name): return ret = PackageOpration().install(self.config) if not ret: Log.fatal(Status["STAT_INSTALL_ERROR"] % self.config.name) else: Log.success(Status["STAT_INSTALL_SUCCESS"] % self.config.name)
def run(args): _init() mods = _mods() sub_cmd, sub_arg = _sub_cmd(args) try: mods[sub_cmd]()._run(sub_arg) except KeyboardInterrupt: Log.puts(Status["STAT_EXIT"]) except KeyError: from gpm.cli.default import CLIDefault CLIDefault._help() except Exception as e: Log.fatal(str(e))
def __exec(cls, cmd, cwd = None, *args, **kwargs): if "&&" in cmd: cmds = cmd.split("&&") ret = False path = None for cmd in cmds: if not path: path = cls.__cd_to_path(cwd) if path: continue ret = cls.__exec(cmd, cwd=path or cwd, *args, **kwargs) if not ret: return ret return ret cmd_args = shlex.split(cmd) Log.debug(cmd) p = Popen(cmd_args, cwd = cwd, stderr=PIPE, stdout=PIPE, shell=False) return LocalOperation.__parser(p, *args, **kwargs)
def __exec(cls, cmd, cwd=None, *args, **kwargs): if "&&" in cmd: cmds = cmd.split("&&") ret = False path = None for cmd in cmds: if not path: path = cls.__cd_to_path(cwd) if path: continue ret = cls.__exec(cmd, cwd=path or cwd, *args, **kwargs) if not ret: return ret return ret cmd_args = shlex.split(cmd) Log.debug(cmd) p = Popen(cmd_args, cwd=cwd, stderr=PIPE, stdout=PIPE, shell=False) return LocalOperation.__parser(p, *args, **kwargs)
def install(self, config = None, save = True): self.set(config) Log.info(Status["STAT_INSTALLING_PKG"] % self.__config.name) ret = False if not self.__config: return False cmds = self.__config.install for cmd in cmds: Log.info(Status["STAT_RUN_CMD"] % cmd) ret = LocalOperation.run(cmd, path = self.__path) if not ret: break if ret and not self.__save_src(save): ret = False return ret
def generate(self): #key prompt default verify sections = [("author", "user name", self.author or LocalOperation.get_user(), VerifyName), ("email", "user email", self.email, VerifyEmail), ("git_url", "git url[[email protected]:name]", self.git_url, VerifyGit)] for section in sections: while(1): self._content[section[0]] = gets("Input %s" % section[1], section[2]) if section[3] and not self._content[section[0]]: Log.warn(Status["STAT_INPUT_EMPTY"] % section[0]) continue elif section[3] and not section[3](self._content[section[0]]): Log.warn(Status["STAT_INPUT_INVALID"] % section[0]) continue else: break self.write(self._path, self._content)
def generate(self): sysConf = SYSConf() if self.path and LocalOperation.exist(self.path): Log.fatal(Status["STAT_GPM_CONF_EXIST"]) #key prompt default verify sections = [("name", "project name", self.name or None, VerifyName), ("language", "project language", self.language or None, VerifyName), ("author", "author name", self.author or sysConf.author, None), ("version", "initial version", self.version or 0.1, None), ("email", "author email", self.email or sysConf.email, VerifyEmail), ("description", "project description", self.description or "", None), ("git_url", "git url[[email protected]:name/project.git]", sysConf.git_url or None, None)] for section in sections: while(1): self._content[section[0]] = gets("Input %s" % section[1], section[2]) if section[3] and not self._content[section[0]]: Log.warn(Status["STAT_INPUT_EMPTY"] % section[0]) continue elif section[3] and not VerifyName(self._content[section[0]]): Log.warn(Status["STAT_INPUT_INVALID"] % section[0]) continue else: break pkg_path = os.path.join(LocalOperation.pwd(), self.name) self._path = os.path.join(pkg_path, GPM_YML) self.write(self._path, self._content)
def generate(self): sysConf = SYSConf() if self.path and LocalOperation.exist(self.path): Log.fatal(Status["STAT_GPM_CONF_EXIST"]) #key prompt default verify sections = [("name", "project name", self.name or None, VerifyName), ("language", "project language", self.language or None, VerifyName), ("author", "author name", self.author or sysConf.author, None), ("version", "initial version", self.version or 0.1, None), ("email", "author email", self.email or sysConf.email, VerifyEmail), ("description", "project description", self.description or "", None), ("git_url", "git url[[email protected]:name/project.git]", sysConf.git_url or None, None)] for section in sections: while (1): self._content[section[0]] = gets("Input %s" % section[1], section[2]) if section[3] and not self._content[section[0]]: Log.warn(Status["STAT_INPUT_EMPTY"] % section[0]) continue elif section[3] and not VerifyName(self._content[section[0]]): Log.warn(Status["STAT_INPUT_INVALID"] % section[0]) continue else: break pkg_path = os.path.join(LocalOperation.pwd(), self.name) self._path = os.path.join(pkg_path, GPM_YML) self.write(self._path, self._content)
def generate(self): #key prompt default verify sections = [("author", "user name", self.author or LocalOperation.get_user(), VerifyName), ("email", "user email", self.email, VerifyEmail), ("git_url", "git url[[email protected]:name]", self.git_url, VerifyGit)] for section in sections: while (1): self._content[section[0]] = gets("Input %s" % section[1], section[2]) if section[3] and not self._content[section[0]]: Log.warn(Status["STAT_INPUT_EMPTY"] % section[0]) continue elif section[3] and not section[3](self._content[section[0]]): Log.warn(Status["STAT_INPUT_INVALID"] % section[0]) continue else: break self.write(self._path, self._content)
def github(self): if not self._github: self._github = Github(self.__username, self.__password) if not self.__verify_login(self._github): Log.fatal(Status["STAT_LOGIN_GITHUB_FAILED"]) return self._github