def add_package(self, filename, optimize_index=True, check_uuids=False): repo_filename = os.path.join(self.path, os.path.basename(filename)) # Check if the package needs to be copied. needs_copy = True if os.path.exists(repo_filename): pkg2 = packages.open(self.pakfire, self, repo_filename) if check_uuids: pkg1 = packages.open(self.pakfire, None, filename) # Package file does already exist, but the UUID don't match. # Copy the package file and then re-open it. if pkg1.uuid == pkg2.uuid: needs_copy = False else: needs_copy = False # Copy the package file if needs_copy: if not os.path.exists(self.path): os.makedirs(self.path) # Copy the file. try: os.link(filename, repo_filename) except OSError: shutil.copy2(filename, repo_filename) # Re-open the package. pkg2 = packages.open(self.pakfire, self, repo_filename) # The package needs to be signed. if self.key_id: pkg2.sign(self.key_id) # Add package to the index. self.index.add_package(pkg2) if optimize_index: self.optimize_index()
def open(self): # Find all files in the repository dir. files = self.search_files(self.path) # Create progress bar. pb = util.make_progress(_("%s: Reading packages...") % self.name, len(files)) i = 0 # Add all files to the index. for file in files: if pb: i += 1 pb.update(i) pkg = packages.open(self.pakfire, self, file) self.index.add_package(pkg) if pb: pb.finish() # Mark repo as open. self.opened = True
def open(self): # Find all files in the repository dir. files = self.search_files(self.path) # Create progress bar. pb = util.make_progress( _("%s: Reading packages...") % self.name, len(files)) i = 0 # Add all files to the index. for file in files: if pb: i += 1 pb.update(i) pkg = packages.open(self.pakfire, self, file) self.index.add_package(pkg) if pb: pb.finish() # Mark repo as open. self.opened = True
def create(self, path): # Just check if the file really exist assert os.path.exists(path) _pkg = packages.open(pakfire.PakfireServer(), None, path) hash_sha512 = misc.calc_hash(path, "sha512") assert hash_sha512 query = [ ("name", _pkg.name), ("epoch", _pkg.epoch), ("version", _pkg.version), ("release", _pkg.release), ("type", _pkg.type), ("arch", _pkg.arch), ("groups", " ".join(_pkg.groups)), ("maintainer", _pkg.maintainer), ("license", _pkg.license), ("url", _pkg.url), ("summary", _pkg.summary), ("description", _pkg.description), ("size", _pkg.inst_size), ("uuid", _pkg.uuid), # Build information. ("build_id", _pkg.build_id), ("build_host", _pkg.build_host), ("build_time", datetime.datetime.utcfromtimestamp(_pkg.build_time)), # File "metadata". ("path", path), ("filesize", os.path.getsize(path)), ("hash_sha512", hash_sha512), ] if _pkg.type == "source": query.append(("supported_arches", _pkg.supported_arches)) keys = [] vals = [] for key, val in query: keys.append(key) vals.append(val) _query = "INSERT INTO packages(%s)" % ", ".join(keys) _query += " VALUES(%s) RETURNING *" % ", ".join("%s" for v in vals) # Create package entry in the database. pkg = self._get_package(_query, *vals) # Dependency information. for d in _pkg.prerequires: pkg.add_dependency("prerequires", d) for d in _pkg.requires: pkg.add_dependency("requires", d) for d in _pkg.provides: pkg.add_dependency("provides", d) for d in _pkg.conflicts: pkg.add_dependency("conflicts", d) for d in _pkg.obsoletes: pkg.add_dependency("obsoletes", d) # Add all files to filelists table for f in _pkg.filelist: pkg.add_file(f.name, f.size, f.hash1, f.type, f.config, f.mode, f.user, f.group, f.mtime, f.capabilities) # Return the newly created object return pkg
def open(cls, _pakfire, path): # Just check if the file really does exist. assert os.path.exists(path) p = pakfire.PakfireServer() file = packages.open(p, None, path) # Get architecture from the database. arch = _pakfire.arches.get_by_name(file.arch) assert arch, "Unknown architecture: %s" % file.arch hash_sha512 = misc.calc_hash(path, "sha512") assert hash_sha512 query = [ ("name", file.name), ("epoch", file.epoch), ("version", file.version), ("release", file.release), ("type", file.type), ("arch", arch.id), ("groups", " ".join(file.groups)), ("maintainer", file.maintainer), ("license", file.license), ("url", file.url), ("summary", file.summary), ("description", file.description), ("size", file.inst_size), ("uuid", file.uuid), # Build information. ("build_id", file.build_id), ("build_host", file.build_host), ("build_time", datetime.datetime.utcfromtimestamp(file.build_time)), # File "metadata". ("path", path), ("filesize", os.path.getsize(path)), ("hash_sha512", hash_sha512), ] if file.type == "source": query.append(("supported_arches", file.supported_arches)) keys = [] vals = [] for key, val in query: keys.append("`%s`" % key) vals.append(val) _query = "INSERT INTO packages(%s)" % ", ".join(keys) _query += " VALUES(%s)" % ", ".join("%s" for v in vals) # Create package entry in the database. id = _pakfire.db.execute(_query, *vals) # Dependency information. deps = [] for d in file.prerequires: deps.append((id, "prerequires", d)) for d in file.requires: deps.append((id, "requires", d)) for d in file.provides: deps.append((id, "provides", d)) for d in file.conflicts: deps.append((id, "conflicts", d)) for d in file.obsoletes: deps.append((id, "obsoletes", d)) if deps: _pakfire.db.executemany("INSERT INTO packages_deps(pkg_id, type, what) \ VALUES(%s, %s, %s)", deps) # Add all files to filelists table. filelist = [] for f in file.filelist: if f.config: config = "Y" else: config = "N" # Convert mtime to integer. try: mtime = int(f.mtime) except ValueError: mtime = 0 filelist.append((id, f.name, f.size, f.hash1, f.type, config, f.mode, f.user, f.group, datetime.datetime.utcfromtimestamp(mtime), f.capabilities)) _pakfire.db.executemany("INSERT INTO filelists(pkg_id, name, size, hash_sha512, \ type, config, mode, user, `group`, mtime, capabilities) \ VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", filelist) # Return the newly created object. return cls(_pakfire, id)