def create_rpm_metadata(self, filename): rpm_name = os.path.basename(filename) md_dir = os.path.join(self.md_folder, rpm_name) log.debug("create rpm metadata for %s: md dir %s" % (filename, md_dir)) mkdir(md_dir) linked_filename = os.path.join(md_dir, rpm_name) if os.path.exists(linked_filename): os.unlink(filename) os.link(linked_filename, filename) else: os.link(filename, linked_filename) if not os.path.exists(os.path.join(md_dir, "repodata")): self.create_repodata(md_dir)
def create_repo(self, reponame): if not self.is_allowed_reponame(reponame): return ('', 403) try: log.debug("trying to create_repo %s" % self._to_path(reponame)) mkdir(self._to_path(reponame)) except OSError as e: if e.errno != 17: log.error(e) if e.errno == 2: return ('', 404) raise path = reponame while path: self.create_repo_metadata(path) path, tail = os.path.split(path) log.info("repo %s created!" % reponame) return ('', 201)
def create_repo_metadata(self, reponame): if not self.is_allowed_reponame(reponame): return ('reponame %s now allowed' % reponame, 403) repo_path = os.path.join(self.repos_folder, reponame) log.debug("creating metadata for %s" % repo_path) mkdir(repo_path) for filename in os.listdir(repo_path): if self.is_allowed_file(filename): self.create_rpm_metadata(os.path.join(repo_path, filename)) with open(os.devnull, "w") as fnull: # TODO allow logging here repos = [ rpm_name for rpm_name in os.listdir(repo_path) if self.is_allowed_file(rpm_name) ] while len(repos) < 2: repos.append("__empty__") cmd = [ self.mergerepo_bin, "--all", "-o", repo_path, "--omit-baseurl" ] + [ "--repo=%s" % os.path.join(self.md_folder, rpm_name) for rpm_name in repos ] subprocess.check_call(cmd, stdout=fnull, stderr=fnull) return ('', 204)
def list_rpms(self, reponame): log.debug("listing %s" % os.listdir(self._to_path(reponame))) return [ file for file in os.listdir(self._to_path(reponame)) if fnmatch(file, '*.rpm') ]
def list_repos(self): log.debug("listing %s" % self.repos_folder) return os.listdir(self.repos_folder)