[packagekit] packagekit: Branch 'master' - 4 commits

Richard Hughes hughsient at kemper.freedesktop.org
Wed Aug 29 11:28:39 PDT 2007


 AUTHORS                            |    3 
 helpers/conary-refresh-cache.py    |    5 
 helpers/conary-search-name-live.py |   20 +++
 helpers/conary-search-name.py      |    1 
 helpers/conaryBackend.py           |  219 ++++++++++++++++++++++++++++++++++++-
 helpers/yumBackend.py              |   11 -
 6 files changed, 242 insertions(+), 17 deletions(-)

New commits:
diff-tree 4f545bced45da6c06392244dc465fbc57b9e386a (from ee1632926fdae6d0157a2183f6c43de70be92b83)
Author: Ken VanDine <ken at vandine.org>
Date:   Wed Aug 29 13:57:44 2007 -0400

    Implement caching for the conary backend

diff --git a/helpers/conary-refresh-cache.py b/helpers/conary-refresh-cache.py
index 7240171..f853b48 100755
--- a/helpers/conary-refresh-cache.py
+++ b/helpers/conary-refresh-cache.py
@@ -10,6 +10,7 @@
 # (at your option) any later version.
 
 import sys
+from conaryBackend import PackageKitConaryBackend
 
-sys.exit(1)
-
+backend = PackageKitConaryBackend(sys.argv[1:])
+backend.refresh_cache()
diff --git a/helpers/conary-search-name.py b/helpers/conary-search-name.py
index 712c169..d96d4cb 100755
--- a/helpers/conary-search-name.py
+++ b/helpers/conary-search-name.py
@@ -18,4 +18,3 @@ from conaryBackend import PackageKitCona
 
 backend = PackageKitConaryBackend(sys.argv[1:])
 backend.search_name(options,searchlist)
-
diff --git a/helpers/conaryBackend.py b/helpers/conaryBackend.py
index abdca0d..82eff26 100644
--- a/helpers/conaryBackend.py
+++ b/helpers/conaryBackend.py
@@ -9,10 +9,12 @@
 # (at your option) any later version.
 
 import sys
+import os
 
 from conary.deps import deps
 from conary.conaryclient import cmdline
 from conary import conarycfg, conaryclient, queryrep, versions, updatecmd
+from pysqlite2 import dbapi2 as sqlite
 
 from packagekit import *
 
@@ -40,6 +42,42 @@ class PackageKitConaryBackend(PackageKit
                                                     arch, fullVersion)
 
     def _do_search(self,searchlist,filters):
+        fltlist = filters.split(';')
+        troveSpecs = [ cmdline.parseTroveSpec(searchlist, allowEmptyName=False)]
+        # get a hold of cached data
+        cache = Cache()
+
+        try:
+            troveTupleList = cache.search(searchlist)
+        finally:
+            pass
+
+        # Remove dupes
+        tempDict = {}
+        for element in troveTupleList:
+            tempDict[element] = None
+            troveTupleList = tempDict.keys()
+
+        # Get the latest first
+        troveTupleList.sort()
+        troveTupleList.reverse()
+
+        for troveTuple in troveTupleList:
+            troveTuple = tuple([item.encode('UTF-8') for item in troveTuple])
+            name = troveTuple[0]
+            version = versions.ThawVersion(troveTuple[1]).trailingRevision()
+            fullVersion = versions.ThawVersion(troveTuple[1])
+            flavor = deps.ThawFlavor(troveTuple[2])
+            # We don't have summary data yet... so leave it blank for now
+            summary = " "
+            troveTuple = tuple([name, fullVersion, flavor])
+            installed = self.check_installed(troveTuple)
+
+            if self._do_filtering(name,fltlist,installed):
+                id = self.get_package_id(name, version, flavor, fullVersion)
+                self.package(id, installed, summary)
+
+    def _do_search_live(self,searchlist,filters):
         '''
         Search for conary packages
         @param searchlist: The conary package fields to search in
@@ -76,9 +114,6 @@ class PackageKitConaryBackend(PackageKit
             for troveTuple in troveTupleList:
                 name = troveTuple[0]
                 version = troveTuple[1].trailingRevision()
-                #version = troveTuple[1].trailingRevision().asString()
-                # Hard code this until i get the flavor parsing right
-                arch = "x86"
                 fullVersion = troveTuple[1].asString()
                 flavor = troveTuple[2]
                 # We don't have summary data yet... so leave it blank for now
@@ -106,6 +141,12 @@ class PackageKitConaryBackend(PackageKit
         '''
         self._do_search(searchlist, options)
 
+    def search_name_live(self, options, searchlist):
+        '''
+        Implement the {backend}-search-name-live functionality
+        '''
+        self._do_search_live(searchlist, options)
+
     def search_details(self, opt, key):
         pass
 
@@ -116,7 +157,8 @@ class PackageKitConaryBackend(PackageKit
         pass
 
     def refresh_cache(self):
-        pass
+        cache = Cache()
+        cache.populate_database()
 
     def install(self, package_id):
         pass
@@ -195,3 +237,172 @@ class PackageKitConaryBackend(PackageKit
         #
         #
         return isDevel == wantDevel
+
+class Cache(object):
+    # Database name and path
+    dbName = 'cache.db'
+    # Someday we might want to make this writable by users
+    #if 'HOME' in os.environ:
+    #    dbPath = '%s/.conary/cache/data/' % os.environ['HOME']
+    #else:
+    #    dbPath = '/var/cache/conary/'
+    dbPath = '/var/cache/conary/'
+
+    """ Class to retrieve and cache package information from label. """
+    def __init__(self):
+        if not os.path.isdir(self.dbPath):
+            os.makedirs(self.dbPath)
+
+        self.conn = sqlite.connect(os.path.join(self.dbPath, self.dbName), isolation_level=None)
+        self.cursor = self.conn.cursor()
+        self.cursor.execute("PRAGMA count_changes=0")
+        self.cursor.execute("pragma synchronous=off")
+
+        if os.path.isfile(os.path.join(self.dbPath, self.dbName)):
+            self._validate_tables()
+
+    def _validate_tables(self):
+        """ Validates that all tables are up to date. """
+        stmt = "select tbl_name from sqlite_master where type = 'table' and tbl_name like 'conary_%'"
+        self.cursor.execute(stmt)
+        # List of all tables with names that start with "conary_"
+        tbllist = self.cursor.fetchall()
+        if tbllist != []:
+            return True
+            #print "Verified packages table"
+        else:
+            #print "Creating packages table..."
+            # Create all tables if database is empty
+            if len(tbllist) == 0:
+                self._create_database()
+                return True
+
+    def conaryquery(self):
+        self.cfg = conarycfg.ConaryConfiguration()
+        self.client = conaryclient.ConaryClient(self.cfg)
+        self.cfg.readFiles()
+        self.cfg.initializeFlavors()
+        self.repos = self.client.getRepos()
+        self.db = conaryclient.ConaryClient(self.cfg).db
+
+        troves = queryrep.getTrovesToDisplay(self.repos, None, None, None,
+            queryrep.VERSION_FILTER_LEAVES, queryrep.FLAVOR_FILTER_BEST, 
+            self.cfg.installLabelPath, self.cfg.flavor, None)
+
+        packages = []
+
+        for troveTuple in troves:
+            # troveTuple is probably what we want to store in the cachedb
+            # Then use the below methods to present them in a nicer fashion
+            if troveTuple[0].endswith(':source'):
+                continue
+            if ":" in troveTuple[0]:
+                fragments = troveTuple[0].split(":")
+                trove = fragments[0]
+                component = fragments[1]
+            else:
+                trove = troveTuple[0]
+                component = ""
+
+            installed = 0
+            localVersion = ""
+            flavor = troveTuple[2]
+            frozenFlavor = troveTuple[2].freeze()
+            version = str(troveTuple[1].trailingRevision())
+            frozenVersion = troveTuple[1].freeze()
+            label = str(troveTuple[1].branch().label())
+            description = ""
+            category = ""
+            packagegroup = ""
+            size = ""
+            packages.append([trove, component, frozenVersion, label, frozenFlavor, description, category, packagegroup, size])
+
+        return packages
+
+    def connect_memory(self):
+        return sqlite.connect(':memory:')
+
+    def cursor(self, connection):
+        return connection.cursor()
+
+    def _create_database(self):
+        """ Creates a blank database. """
+        sql = '''CREATE TABLE conary_packages (
+            trove text,
+            component text,
+            version text,
+            label text,
+            flavor text,
+            description text,
+            category text,
+            packagegroup text,
+            size text)'''
+
+        self.cursor.execute(sql)
+
+    def commit(self):
+        self.cursor.commit()
+
+    def getTroves(self, label=None):
+        """
+        Returns all troves for now.  Add filtering capability.
+        """
+        stmt = "select distinct trove, version, flavor, description, category, packagegroup, size" \
+            " from conary_packages"
+
+        try:
+            self.cursor.execute(stmt)
+            return self.cursor.fetchall()
+        except Exception, e:
+            print str(e)
+            return None
+
+    def search(self, package):
+        """
+        Returns all troves for now.  Add filtering capability.
+        """
+        stmt = "select distinct trove, version, flavor, description, category, packagegroup, size" \
+            " from conary_packages"
+
+        if package:
+            stmt = stmt + " where trove like '%" + package + "%' and component = '' order by version desc"
+
+        try:
+            self.cursor.execute(stmt)
+            results = self.cursor.fetchall()
+            return results
+        except Exception, e:
+            print str(e)
+            return None
+
+    def _insert(self, trove):
+        """
+        Insert trove into database.
+        """
+        values = [str(field) for field in trove]
+        cols = ",".join("?" * len(trove))
+        sql = "INSERT INTO conary_packages VALUES (%s)" % cols
+
+        try:
+            self.cursor.execute(sql, values)
+        except Exception,e:
+            print str(e)
+
+    def _clear_table(self, tableName='conary_packages'):
+        """
+        Deletes * records from table.
+        """
+        stmt = "DELETE FROM %s" % tableName
+        self.cursor.execute(stmt)
+
+    def populate_database(self):
+        try:
+            packages = self.conaryquery()
+            # Clear table first
+            self._clear_table()
+            for package in packages:
+                self._insert(package)
+        except Exception, e:
+            print str(e)
+
+
diff-tree ee1632926fdae6d0157a2183f6c43de70be92b83 (from acd3076562c5429e955bb3f3d5c7665edade2ebb)
Author: Ken VanDine <ken at vandine.org>
Date:   Wed Aug 29 13:57:23 2007 -0400

    Now that we have caching, maintain a script for doing live queries

diff --git a/helpers/conary-search-name-live.py b/helpers/conary-search-name-live.py
new file mode 100755
index 0000000..2556f8d
--- /dev/null
+++ b/helpers/conary-search-name-live.py
@@ -0,0 +1,20 @@
+#!/usr/bin/python
+#
+# Copyright (C) 2007 Ken VanDine <ken at vandine.org>
+#
+# Licensed under the GNU General Public License Version 2
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+import sys
+
+options = sys.argv[1]
+searchlist = sys.argv[2]
+
+from conaryBackend import PackageKitConaryBackend
+
+backend = PackageKitConaryBackend(sys.argv[1:])
+backend.search_name_live(options,searchlist)
diff-tree acd3076562c5429e955bb3f3d5c7665edade2ebb (from d18ab97c906f5659f1948224c3e627bf23fe2efa)
Author: Ken VanDine <ken at vandine.org>
Date:   Wed Aug 29 13:56:40 2007 -0400

    Added Og Maciel and Elliot Peele to AUTHORS
      Og did allot of the conary caching code and Elliot significantly improved some of the code I had already committed

diff --git a/AUTHORS b/AUTHORS
index 71d2a32..d4f7d8c 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -4,3 +4,6 @@ Ken VanDine <ken at vandine.org>
 Tim Lauridsen <tla at rasmil.dk>
 Luke Macken <lmacken at redhat.com>
 
+Backend: conary
+    Og Maciel <omaciel at foresightlinux.org>
+    Elliot Peele <elliot at foresightlinux.org>
diff-tree d18ab97c906f5659f1948224c3e627bf23fe2efa (from 63867efc756af198545f2c2943e0fc4958cc4780)
Author: Tim Lauridsen <tla at rasmil.dk>
Date:   Wed Aug 29 19:19:52 2007 +0200

    Removed some debug printing for yumBackend

diff --git a/helpers/yumBackend.py b/helpers/yumBackend.py
index d671fb0..53d7747 100644
--- a/helpers/yumBackend.py
+++ b/helpers/yumBackend.py
@@ -183,7 +183,6 @@ class PackageKitYumBackend(PackageKitBas
         # get e,v,r from package id version
         e,v,r = self._getEVR(idver)
         # search the rpmdb for the nevra
-        print n,e,v,r,a
         pkgs = self.yumbase.rpmdb.searchNevra(name=n,epoch=e,ver=v,rel=r,arch=a)
         # if the package is found, then return it
         if len(pkgs) != 0:
@@ -272,13 +271,11 @@ class PackageKitYumBackend(PackageKitBas
         self._setup_yum()
         self.percentage(0)
         pkg,inst = self._findPackage(package)
-        print pkg,inst
         if pkg:
             if inst:
                 self.error(ERROR_PACKAGE_ALREADY_INSTALLED,'Package already installed')        
             try:
                 txmbr = self.yumbase.install(name=pkg.name)
-                print txmbr
                 self._runYumTransaction()
             except yum.Errors.InstallError,e:
                 print e
@@ -338,11 +335,9 @@ class PackageKitYumBackend(PackageKitBas
         self._setup_yum()
         self.percentage(0)
         pkg,inst = self._findPackage( package)
-        print pkg,inst
         if pkg and inst:        
             txmbr = self.yumbase.remove(name=pkg.name)
             if txmbr:
-                print txmbr[0].po
                 self._runYumTransaction()
             else:
                 self.error(ERROR_PACKAGE_NOT_INSTALLED,"Package is not installed")
@@ -483,15 +478,11 @@ class PackageKitCallback(RPMBaseCallback
         self.base = base
         self.pct = 0
         self.curpkg = None
-        self.actions = { 'Updating' : STATE_UPDATE,
-                         'Erasing' : STATE_REMOVE,
-                         'Installing' : STATE_INSTALL}
 
     def event(self, package, action, te_current, te_total, ts_current, ts_total):
         if str(package) != self.curpkg:
             self.curpkg = str(package)
-            self.base.data(package)
-            print action
+            self.base.data(self.curpkg)
             if action in TS_INSTALL_STATES:
                 self.base.status(STATE_INSTALL)
             elif action in TS_REMOVE_STATES:



More information about the PackageKit mailing list