Beispiel #1
0
    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)
Beispiel #2
0
 def write(self, path, data):
     LocalOperation.mkdir(os.path.dirname(path))
     with open(path, "w+") as stream:
         yaml.dump(data,
                   stream,
                   allow_unicode=True,
                   default_flow_style=False)
Beispiel #3
0
    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)
Beispiel #4
0
    def find(cls, name, show = True):
        ret = LocalOperation.find(GPM_SRC, name)
        if show:
            cls.__show_pkgs(ret)

        if ret:
            conf_path = os.path.join(ret[0], GPM_YML)
            return GPMConf(conf_path), ret[0]
        return None
Beispiel #5
0
    def test(self, config = None):
        self.set(config)
        ret = False
        if not self.__config:
            return False

        cmds = self.__config.test
        for cmd in cmds:
            ret = LocalOperation.run(cmd, path = self.__path)
            if not ret:
                break

        return ret
Beispiel #6
0
    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
Beispiel #7
0
    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)
Beispiel #8
0
    def remove(self, config=None, path=None):
        self.set(config, path)
        ret = True
        if not self.__config:
            return False

        # if self.find(self.__config.name, show = False):         #pkg exist
        #     Log.info(Status["STAT_PACKAGE_EXIST"] % self.__config.name)
        #     return False

        cmds = self.__config.remove
        for cmd in cmds:
            ret = LocalOperation.run(cmd, path = self.__path)
            if not ret:
                break

        if ret and not self.__remove_src():
            ret = False

        return ret
Beispiel #9
0
    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)
Beispiel #10
0
 def read(self):
     if LocalOperation.exist(self._path):
         with open(self._path, "r") as stream:
             self._content = yaml.load(stream)
Beispiel #11
0
 def __init__(self, path=None):
     path = LocalOperation.rel2abs(path or SYS_CONF)
     _Conf.__init__(self, path)
Beispiel #12
0
 def __save_src(self, save = True):
     if save:
         return LocalOperation.cp(self.__path, GPM_SRC)
     else:
         return True
Beispiel #13
0
def _init():
    if not LocalOperation.exist(GPM_SRC):
        LocalOperation.mkdir(GPM_SRC)
 def create_gitignore(self):
     language = self._config.language
     if language:
         content = self.github.get_gitignore_template(language)
         LocalOperation.add_file(self._GITIGNORE_NAME, content)
Beispiel #15
0
 def __init__(self, path=None):
     if path and not GPM_YML in path:
         path = os.path.join(path, GPM_YML)
     path = LocalOperation.rel2abs(path or GPM_YML)
     _Conf.__init__(self, path)
Beispiel #16
0
 def __init__(self, path = None):
     if path and not GPM_YML in path:
         path = os.path.join(path, GPM_YML)
     path = LocalOperation.rel2abs(path or GPM_YML)
     _Conf.__init__(self, path)
Beispiel #17
0
 def write(self, path, data):
     LocalOperation.mkdir(os.path.dirname(path))
     with open(path, "w+") as stream:
         yaml.dump(data, stream, allow_unicode=True, default_flow_style=False)
Beispiel #18
0
 def read(self):
     if LocalOperation.exist(self._path):
         with open(self._path, "r") as stream:
             self._content = yaml.load(stream)
Beispiel #19
0
 def __init__(self, path = None):
     path = LocalOperation.rel2abs(path or SYS_CONF)
     _Conf.__init__(self, path)
Beispiel #20
0
 def __init__(self, config = None, path = None):
     self.__config = config
     self.__path   = path or LocalOperation.pwd()
Beispiel #21
0
 def list(cls):
     ret = LocalOperation.ls(GPM_SRC)
     cls.__show_pkgs(ret)
Beispiel #22
0
 def __file_exist(self):
     db_dir = os.path.dirname(self.__path)
     if not LocalOperation.exist(db_dir):
         LocalOperation.mkdir(db_dir)
     return LocalOperation.exist(self.__path)
Beispiel #23
0
 def _version(self, *args, **kwargs):
     puts(LocalOperation.distr())
     puts("%s %s" % (name, version))
Beispiel #24
0
 def __file_exist(self):
     db_dir = os.path.dirname(self.__path)
     if not LocalOperation.exist(db_dir):
         LocalOperation.mkdir(db_dir)
     return LocalOperation.exist(self.__path)
Beispiel #25
0
 def _version(self, *args, **kwargs):
     puts(LocalOperation.distr())
     puts("%s %s" % (name, version))
Beispiel #26
0
 def __remove_src(self):
     return LocalOperation.rm(os.path.join(GPM_SRC, self.__config.name))