def run(self, cmdline, db): repo = (db.session.query(Repo) .filter(Repo.name == cmdline.NAME) .first()) if repo: self.log_error("Repository '{0}' already defined" .format(cmdline.NAME)) return 1 self.log_info("Adding repository '{0}' ({1})" .format(cmdline.NAME, cmdline.URL)) new = Repo() new.name = cmdline.NAME new.type = cmdline.TYPE for url in cmdline.URL: new_url = Url() new_url.url = url new.url_list.append(new_url) if cmdline.nice_name: new.nice_name = cmdline.nice_name new.nogpgcheck = cmdline.nogpgcheck db.session.add(new) db.session.flush() return 0
def run(self, cmdline, db): repo = (db.session.query(Repo) .filter(Repo.name == cmdline.NAME) .first()) if repo: self.log_error("Repository '{0}' already defined" .format(cmdline.NAME)) return 1 self.log_info("Adding repository '{0}' ({1})" .format(cmdline.NAME, cmdline.URL)) new = Repo() new.name = cmdline.NAME new.type = cmdline.TYPE for url in cmdline.URL: new_url = Url() new_url.url = url new.url_list.append(new_url) if cmdline.nice_name: new.nice_name = cmdline.nice_name new.nogpgcheck = cmdline.nogpgcheck db.session.add(new) db.session.flush()
def _import_yum_repo(self, fp): """ Parse open .repo file `fp` and return list of Repo instances. Section name is used as repository name, baseurl (required) and gpgcheck are stored. """ parser = ConfigParser.SafeConfigParser() try: parser.readfp(fp) except ConfigParser.Error as exc: self.log_error("Exception while parsing repository file: " "'{0}'".format(exc)) return None result = [] for section in parser.sections(): new = Repo() new.name = section new.type = "yum" if not parser.has_option(section, "baseurl"): self.log_error("Repo '{0}' is missing required" " option 'baseurl'".format(section)) return None new.url = parser.get(section, "baseurl") if parser.has_option(section, "gpgcheck"): new.nogpgcheck = parser.getint(section, "gpgcheck") == 0 result.append(new) return result
def import_repo(self, fp, repo_type): """ Parse open .repo file `fp` and return list of Repo instances. Section name is used as repository name, baseurl (required) and gpgcheck are stored. """ parser = configparser.SafeConfigParser() try: parser.readfp(fp) #pylint: disable=deprecated-method except configparser.Error as exc: self.log_error("Exception while parsing repository file: " "'{0}'".format(exc)) return None result = [] for section in parser.sections(): new = Repo() new.name = section new.type = repo_type if not parser.has_option(section, "baseurl"): self.log_error("Repo '{0}' is missing required" " option 'baseurl'".format(section)) return None new_url = Url() new_url.url = parser.get(section, "baseurl") new.url_list = [new_url] if parser.has_option(section, "gpgcheck"): new.nogpgcheck = parser.getint(section, "gpgcheck") == 0 result.append(new) return result