]> git.ipfire.org Git - pakfire.git/commitdiff
Cleanup of package data structures.
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 7 Feb 2011 01:14:48 +0000 (02:14 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 7 Feb 2011 01:14:48 +0000 (02:14 +0100)
Makes them more clear and gives them access to the Pakfire()
object so they can access anything.

12 files changed:
examples/pakfire.repos.d/ipfire.repo
pakfire/builder.py
pakfire/cli.py
pakfire/database.py
pakfire/index.py
pakfire/packages/base.py
pakfire/packages/binary.py
pakfire/packages/file.py
pakfire/packages/installed.py
pakfire/packages/make.py
pakfire/packages/virtual.py
pakfire/repository.py

index 32999f7409d10065c2ea30db35147d3b049818d7..ce6ddcdc68c03402f8827a96c6f9a54b872cf512 100644 (file)
@@ -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
 
index 6e15ea3b2f85912583516ad7c19c3b8e93d646a7..bc6e23dd37ac8e4ba74856ba7a6eac42549e0cf8 100644 (file)
@@ -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
index ab7f14351812e44f3a644be165676923f23f86ed..ca78a9b7b411823c3040e0ad279322018f9d27b3 100644 (file)
@@ -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
index a38eb313541e8e0969fcd8f16a65b6d270e52fb1..69724dcf193ff5867e34ea4e96d1f1033b511dcf 100644 (file)
@@ -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
index 592653ff843976e9f2325ec39935be48797337fa..4cc2d21b32829b29389c714e713ef5b7c44cce41 100644 (file)
@@ -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")]
 
index b6c2282238065f613242c0f1eb9971a603a0c327..dfcbe12583a93bde2d05d8a27493f7e2d5058fb7 100644 (file)
@@ -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
index bb9fdc3ea4abeab8bef3039cf0cd169a1ab8e20d..51fcdaf8bf2e96bdb8ad591b88581f7b84251218 100644 (file)
@@ -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
-
index 2b12674bbef2cf664a825339bed99e34165b04a7..e25f0813b95605c46dd0fc3b9ca78b3873c956f8 100644 (file)
@@ -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
index f4218fac0ca0112b2d1a89018459f151aabac157..ffce0c22eb23c01023b43a96d792faa8e8cc61b9 100644 (file)
@@ -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 = {}
index 64df40b881dfe13197b0260744ef1dad4c3f166e..9d7a33a23d4f72366781ea73496463a627d006bd 100644 (file)
@@ -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")
index 87d2cee03fa25724700b28aecb43f6deb9fc1ee1..a21bafc0c489f0362d7597a3dbb86c8fb99cc460 100644 (file)
@@ -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():
index 02d1286aaf692ca0d1cdb874ed4789a52d889370..276c64f0e5f192da68e0617d6f677252469e57e5 100644 (file)
@@ -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