From: Michael Tremer Date: Mon, 7 Feb 2011 01:14:48 +0000 (+0100) Subject: Cleanup of package data structures. X-Git-Tag: 0.9.3~195 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3723913b604e5e1f78cad4b5c893cace0147689a;p=pakfire.git Cleanup of package data structures. Makes them more clear and gives them access to the Pakfire() object so they can access anything. --- diff --git a/examples/pakfire.repos.d/ipfire.repo b/examples/pakfire.repos.d/ipfire.repo index 32999f740..ce6ddcdc6 100644 --- a/examples/pakfire.repos.d/ipfire.repo +++ b/examples/pakfire.repos.d/ipfire.repo @@ -9,7 +9,8 @@ description = IPFire Development Repository #url = http://mirror0.ipfire.org/pakfire3/$name/$arch -url = file:///ipfire-3.x/build/packages/i686 +#url = file:///ipfire-3.x/build/packages/i686 +url = file:///tmp/pakfire3 gpgkey = /not/yet/existant diff --git a/pakfire/builder.py b/pakfire/builder.py index 6e15ea3b2..bc6e23dd3 100644 --- a/pakfire/builder.py +++ b/pakfire/builder.py @@ -438,9 +438,12 @@ class Builder(object): k, v = m.groups() pkg[k] = v.strip("\"") + # Create a dummy repository to link the virtual packages to + repo = repository.DummyRepository(self.pakfire) + self._packages = [] for pkg in pkgs: - pkg = packages.VirtualPackage(pkg) + pkg = packages.VirtualPackage(self.pakfire, repo, pkg) self._packages.append(pkg) return self._packages diff --git a/pakfire/cli.py b/pakfire/cli.py index ab7f14351..ca78a9b7b 100644 --- a/pakfire/cli.py +++ b/pakfire/cli.py @@ -230,10 +230,11 @@ class CliBuilder(Cli): pkg = os.path.abspath(pkg) if pkg.endswith(MAKEFILE_EXTENSION): - pkg = packages.Makefile(pkg) + pkg = packages.Makefile(self.pakfire, pkg) elif pkg.endswith(PACKAGE_EXTENSION): - pkg = packages.SourcePackage(pkg) + repo = repository.FileSystemRepository(self.pakfire) + pkg = packages.SourcePackage(self.pakfire, repo, pkg) else: # XXX walk through the source tree and find a matching makefile @@ -251,10 +252,11 @@ class CliBuilder(Cli): pkg = os.path.abspath(pkg) if pkg.endswith(MAKEFILE_EXTENSION): - pkg = packages.Makefile(pkg) + pkg = packages.Makefile(self.pakfire, pkg) elif pkg.endswith(PACKAGE_EXTENSION): - pkg = packages.SourcePackage(pkg) + repo = repository.FileSystemRepository(self.pakfire) + pkg = packages.SourcePackage(self.pakfire, repo, pkg) else: # XXX walk through the source tree and find a matching makefile @@ -272,7 +274,7 @@ class CliBuilder(Cli): pkg = os.path.abspath(pkg) if pkg.endswith(MAKEFILE_EXTENSION): - pkg = packages.Makefile(pkg) + pkg = packages.Makefile(self.pakfire, pkg) else: # XXX walk through the source tree and find a matching makefile diff --git a/pakfire/database.py b/pakfire/database.py index a38eb3135..69724dcf1 100644 --- a/pakfire/database.py +++ b/pakfire/database.py @@ -7,7 +7,8 @@ import sqlite3 import packages class Database(object): - def __init__(self, filename): + def __init__(self, pakfire, filename): + self.pakfire = pakfire self.filename = filename self._db = None @@ -128,7 +129,7 @@ class LocalPackageDatabase(Database): ret = None for pkg in c: - ret = packages.InstalledPackage(self, pkg) + ret = packages.InstalledPackage(self.pakfire, self, pkg) break assert ret diff --git a/pakfire/index.py b/pakfire/index.py index 592653ff8..4cc2d21b3 100644 --- a/pakfire/index.py +++ b/pakfire/index.py @@ -6,8 +6,9 @@ import os import packages class Index(object): - def __init__(self, pakfire): + def __init__(self, pakfire, repo): self.pakfire = pakfire + self.repo = repo self.arch = self.pakfire.distro.arch # XXX ??? @@ -53,10 +54,10 @@ class Index(object): class DirectoryIndex(Index): - def __init__(self, pakfire, path): + def __init__(self, pakfire, repo, path): self.path = path - Index.__init__(self, pakfire) + Index.__init__(self, pakfire, repo) def update(self, force=False): logging.debug("Updating repository index '%s' (force=%s)" % (self.path, force)) @@ -65,7 +66,7 @@ class DirectoryIndex(Index): for file in files: file = os.path.join(dir, file) - package = packages.BinaryPackage(file) + package = packages.BinaryPackage(self.pakfire, self.repo, file) if not package.arch in (self.arch, "noarch"): logging.warning("Skipped package with wrong architecture: %s (%s)" \ @@ -76,17 +77,17 @@ class DirectoryIndex(Index): class InstalledIndex(Index): - def __init__(self, pakfire, db): + def __init__(self, pakfire, repo, db): self.db = db - Index.__init__(self, pakfire) + Index.__init__(self, pakfire, repo) def get_all_by_name(self, name): c = self.db.cursor() c.execute("SELECT * FROM packages WHERE name = ?", name) for pkg in c: - yield package.InstalledPackage(self.db, pkg) + yield package.InstalledPackage(self.pakfire, self.db, pkg) c.close() @@ -106,20 +107,7 @@ class InstalledIndex(Index): c.execute("SELECT * FROM packages") for pkg in c: - yield packages.InstalledPackage(self.db, pkg) + yield packages.InstalledPackage(self.pakfire, self.db, pkg) c.close() - - - - -if __name__ == "__main__": - di = DirectoryIndex("/ipfire-3.x/build/packages/i686", "i686") - - for package in di.packages: - print package - - print di.package_names - print di.get_latest_by_name("ccache") - print [p for p in di.get_all_by_name("ccache")] diff --git a/pakfire/packages/base.py b/pakfire/packages/base.py index b6c228223..dfcbe1258 100644 --- a/pakfire/packages/base.py +++ b/pakfire/packages/base.py @@ -10,11 +10,12 @@ from pakfire.i18n import _ class Package(object): type = None # either "bin", "src" or "virt" - def __init__(self, filename): - self.filename = filename + def __init__(self, pakfire, repo): + self.pakfire = pakfire + self._repo = repo def __repr__(self): - return "<%s %s>" % (self.__class__.__name__, self.filename) + return "<%s %s>" % (self.__class__.__name__, self.friendly_name) def __cmp__(self, other): # if packages differ names return in alphabetical order diff --git a/pakfire/packages/binary.py b/pakfire/packages/binary.py index bb9fdc3ea..51fcdaf8b 100644 --- a/pakfire/packages/binary.py +++ b/pakfire/packages/binary.py @@ -31,30 +31,3 @@ class BinaryPackage(FilePackage): def get_extractor(self, pakfire): return packager.Extractor(pakfire, self) - -if __name__ == "__main__": - for pkg in sys.argv[1:]: - pkg = BinaryPackage(pkg) - - fmt = "%-10s : %s" - - items = ( - ("Name", pkg.name), - ("Version", pkg.version), - ("Release", pkg.release), - ("Epoch", pkg.epoch), - ("Size", pkg.size), - ("Arch", pkg.arch), - ("Signature", pkg.signature), - ) - - for item in items: - print fmt % item - - print fmt % ("Filelist", "") - print "\n".join([" %s" % f for f in pkg.filelist]) - - print pkg.filelist - - print - diff --git a/pakfire/packages/file.py b/pakfire/packages/file.py index 2b12674bb..e25f0813b 100644 --- a/pakfire/packages/file.py +++ b/pakfire/packages/file.py @@ -13,7 +13,8 @@ class FilePackage(Package): This class is a wrapper that reads package data from the (outer) tarball and should never be used solely. """ - def __init__(self, filename): + def __init__(self, pakfire, repo, filename): + Package.__init__(self, pakfire, repo) self.filename = filename # Place to keep the tarfile handle and cache the metadata diff --git a/pakfire/packages/installed.py b/pakfire/packages/installed.py index f4218fac0..ffce0c22e 100644 --- a/pakfire/packages/installed.py +++ b/pakfire/packages/installed.py @@ -13,7 +13,9 @@ from base import Package class InstalledPackage(Package): type = "installed" - def __init__(self, db, data): + def __init__(self, pakfire, db, data): + Package.__init__(self, pakfire, pakfire.repos.local) + self.db = db self._data = {} diff --git a/pakfire/packages/make.py b/pakfire/packages/make.py index 64df40b88..9d7a33a23 100644 --- a/pakfire/packages/make.py +++ b/pakfire/packages/make.py @@ -7,6 +7,7 @@ from urlgrabber.grabber import URLGrabber, URLGrabError from urlgrabber.progress import TextMeter import packager +import pakfire.repository as repository from base import Package from source import SourcePackage @@ -43,6 +44,12 @@ class SourceDownloader(object): class Makefile(Package): + def __init__(self, pakfire, filename): + repo = repository.DummyRepository(pakfire) + + Package.__init__(self, pakfire, repo) + self.filename = filename + @property def files(self): basedir = os.path.dirname(self.filename) @@ -110,7 +117,7 @@ class Makefile(Package): f = open(files["signature"], "w") f.close() - pkg = VirtualPackage(env.make_info) + pkg = VirtualPackage(self.pakfire, env.make_info) # Save meta information. f = open(files["info"], "w") diff --git a/pakfire/packages/virtual.py b/pakfire/packages/virtual.py index 87d2cee03..a21bafc0c 100644 --- a/pakfire/packages/virtual.py +++ b/pakfire/packages/virtual.py @@ -8,7 +8,8 @@ from pakfire.constants import * class VirtualPackage(Package): type = "virt" - def __init__(self, data): + def __init__(self, pakfire, data): + self.pakfire = pakfire self._data = {} for key in data.keys(): diff --git a/pakfire/repository.py b/pakfire/repository.py index 02d1286aa..276c64f0e 100644 --- a/pakfire/repository.py +++ b/pakfire/repository.py @@ -200,15 +200,34 @@ class RepositoryFactory(object): return self.index.packages +class DummyRepository(RepositoryFactory): + """ + Just a dummy repository that actually does nothing. + """ + def __init__(self, pakfire): + RepositoryFactory.__init__(self, pakfire, "dummy", + "This is a dummy repository.") + + +class FileSystemRepository(RepositoryFactory): + """ + Dummy repository to indicate that a specific package came from the + filesystem. + """ + def __init__(self, pakfire): + RepositoryFactory.__init__(self, pakfire, "filesystem", + "Filesystem repository") + + class LocalRepository(RepositoryFactory): def __init__(self, pakfire): RepositoryFactory.__init__(self, pakfire, "installed", "Installed packages") self.path = os.path.join(self.pakfire.path, PACKAGES_DB) - self.db = database.LocalPackageDatabase(self.path) + self.db = database.LocalPackageDatabase(self.pakfire, self.path) - self.index = index.InstalledIndex(self.pakfire, self.db) + self.index = index.InstalledIndex(self.pakfire, self, self.db) @property def priority(self): @@ -233,7 +252,7 @@ class RemoteRepository(RepositoryFactory): self.enabled = False if self.url.startswith("file://"): - self.index = index.DirectoryIndex(self.pakfire, self.url[7:]) + self.index = index.DirectoryIndex(self.pakfire, self, self.url[7:]) else: self.index = None