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

Richard Hughes hughsient at kemper.freedesktop.org
Fri Feb 22 07:25:52 PST 2008


 backends/yum2/helpers/yumDBUSBackend.py |   27 +++++++++-
 backends/zypp/pk-backend-zypp.cpp       |   40 ++++++++-------
 backends/zypp/zypp-utils.cpp            |   73 ++++++++++++++++++++++++++++
 backends/zypp/zypp-utils.h              |    5 +
 configure.ac                            |    2 
 python/packagekit/daemonBackend.py      |   82 +++++++++++++++++++++++++++++++-
 6 files changed, 208 insertions(+), 21 deletions(-)

New commits:
commit f5370e1f128321d441f28146a053db7ed8e15675
Author: Stefan Haas <shaas at suse.de>
Date:   Fri Feb 22 15:30:43 2008 +0100

    assigning the right group to a package

diff --git a/backends/zypp/pk-backend-zypp.cpp b/backends/zypp/pk-backend-zypp.cpp
index c4d6d11..e1cb8c2 100644
--- a/backends/zypp/pk-backend-zypp.cpp
+++ b/backends/zypp/pk-backend-zypp.cpp
@@ -151,20 +151,24 @@ backend_get_groups (PkBackend *backend, PkEnumList *elist)
 {
 	g_return_if_fail (backend != NULL);
 	pk_enum_list_append_multiple (elist,
-				      PK_GROUP_ENUM_GAMES,
-				      PK_GROUP_ENUM_GRAPHICS,
-				      PK_GROUP_ENUM_INTERNET,
-				      PK_GROUP_ENUM_OFFICE,
-				      PK_GROUP_ENUM_OTHER,
-				      PK_GROUP_ENUM_PROGRAMMING,
-				      PK_GROUP_ENUM_MULTIMEDIA,
-				      PK_GROUP_ENUM_SYSTEM,
-				      PK_GROUP_ENUM_PUBLISHING,
-				      PK_GROUP_ENUM_SERVERS,
-				      PK_GROUP_ENUM_FONTS,
-				      PK_GROUP_ENUM_ADMIN_TOOLS,
-				      PK_GROUP_ENUM_LOCALIZATION,
-				      PK_GROUP_ENUM_SECURITY,
+                                      PK_GROUP_ENUM_GAMES,
+                                      PK_GROUP_ENUM_GRAPHICS,
+                                      PK_GROUP_ENUM_OFFICE,
+                                      PK_GROUP_ENUM_PROGRAMMING,
+                                      PK_GROUP_ENUM_MULTIMEDIA,
+                                      PK_GROUP_ENUM_SYSTEM,
+                                      PK_GROUP_ENUM_DESKTOP_GNOME,
+                                      PK_GROUP_ENUM_DESKTOP_KDE,
+                                      PK_GROUP_ENUM_DESKTOP_XFCE,
+                                      PK_GROUP_ENUM_DESKTOP_OTHER,
+                                      PK_GROUP_ENUM_PUBLISHING,
+                                      PK_GROUP_ENUM_ADMIN_TOOLS,
+                                      PK_GROUP_ENUM_LOCALIZATION,
+                                      PK_GROUP_ENUM_SECURITY,
+                                      PK_GROUP_ENUM_EDUCATION,
+                                      PK_GROUP_ENUM_COMMUNICATION,
+                                      PK_GROUP_ENUM_NETWORK,
+                                      PK_GROUP_ENUM_UNKNOWN,
 				      -1);
 }
 
@@ -397,9 +401,11 @@ backend_get_description_thread (PkBackendThread *thread, gpointer data)
 	}
         
         try {
+                PkGroupEnum group = zypp_get_group (package);
+
                 // currently it is necessary to access the rpmDB directly to get infos like size for already installed packages
                 if (package->isSystem ()){
-                       zypp::Target_Ptr target;
+                        zypp::Target_Ptr target;
 
                         zypp::ZYpp::Ptr zypp;
                         zypp = get_zypp ();
@@ -414,7 +420,7 @@ backend_get_description_thread (PkBackendThread *thread, gpointer data)
 	                pk_backend_description (backend,
 			                	d->package_id,                  		// package_id
 				                rpmHeader->tag_license ().c_str (),		// const gchar *license
-				                PK_GROUP_ENUM_OTHER,                    	// PkGroupEnum group
+				                group,                                  	// PkGroupEnum group
 				                rpmHeader->tag_description ().c_str (),   	// const gchar *description
 				                rpmHeader->tag_url (). c_str (),	  	// const gchar *url
 				                (gulong)rpmHeader->tag_size ());		// gulong size
@@ -425,7 +431,7 @@ backend_get_description_thread (PkBackendThread *thread, gpointer data)
                         pk_backend_description (backend,
                                                 d->package_id,
                                                 pkg->license ().c_str (),
-                                                PK_GROUP_ENUM_OTHER,
+                                                group,
                                                 pkg->description ().c_str (),
                                                 pkg->url ().c_str (),
                                                 (gulong)pkg->size ());
diff --git a/backends/zypp/zypp-utils.cpp b/backends/zypp/zypp-utils.cpp
index 179b5ec..b810b80 100644
--- a/backends/zypp/zypp-utils.cpp
+++ b/backends/zypp/zypp-utils.cpp
@@ -121,6 +121,79 @@ zypp_build_local_pool ()
 
 }
 
+PkGroupEnum
+zypp_get_group (zypp::ResObject::constPtr item)
+{
+        PkGroupEnum pkGroup = PK_GROUP_ENUM_UNKNOWN;
+        std::string group;
+
+        if (item->isSystem ()) {
+                zypp::ZYpp::Ptr zypp = get_zypp ();
+                zypp::Target_Ptr target = zypp->target ();
+
+                zypp::target::rpm::RpmDb &rpm = target->rpmDb ();
+                rpm.initDatabase ();
+
+                zypp::target::rpm::RpmHeader::constPtr rpmHeader;
+                rpm.getData (item->name (), item->edition (), rpmHeader);
+                group = rpmHeader->tag_group ();
+
+                rpm.closeDatabase ();
+       
+        }else{
+                zypp::Package::constPtr pkg = zypp::asKind<zypp::Package>(item);
+                group = pkg->group ();
+        }
+
+        // TODO Look for a faster and nice way to do this conversion
+
+        if (group.find ("Amusements") != std::string::npos) {
+                pkGroup = PK_GROUP_ENUM_GAMES;
+        } else if (group.find ("Development") != std::string::npos) {
+                pkGroup = PK_GROUP_ENUM_PROGRAMMING;
+        } else if (group.find ("Hardware") != std::string::npos) {
+                pkGroup = PK_GROUP_ENUM_SYSTEM;
+        } else if (group.find ("Archiving") != std::string::npos 
+                  || group.find("Clustering") != std::string::npos
+                  || group.find("System/Monitoring") != std::string::npos
+                  || group.find("Databases") != std::string::npos
+                  || group.find("System/Management") != std::string::npos) {
+                pkGroup = PK_GROUP_ENUM_ADMIN_TOOLS;
+        } else if (group.find ("Graphics") != std::string::npos) {
+                pkGroup = PK_GROUP_ENUM_GRAPHICS;
+        } else if (group.find ("Mulitmedia") != std::string::npos) {
+                pkGroup = PK_GROUP_ENUM_MULTIMEDIA;
+        } else if (group.find ("") != std::string::npos) {
+                pkGroup = PK_GROUP_ENUM_NETWORK;
+        } else if (group.find ("Office") != std::string::npos 
+                  || group.find("Text") != std::string::npos
+                  || group.find("Editors") != std::string::npos) {
+                pkGroup = PK_GROUP_ENUM_OFFICE;
+        } else if (group.find ("Publishing") != std::string::npos) {
+                pkGroup = PK_GROUP_ENUM_PUBLISHING;
+        } else if (group.find ("Security") != std::string::npos) {
+                pkGroup = PK_GROUP_ENUM_SECURITY;
+        } else if (group.find ("Telephony") != std::string::npos) {
+                pkGroup = PK_GROUP_ENUM_COMMUNICATION;
+        } else if (group.find ("GNOME") != std::string::npos) {
+                pkGroup = PK_GROUP_ENUM_DESKTOP_GNOME;
+        } else if (group.find ("KDE") != std::string::npos) {
+                pkGroup = PK_GROUP_ENUM_DESKTOP_KDE;
+        } else if (group.find ("XFCE") != std::string::npos) {
+                pkGroup = PK_GROUP_ENUM_DESKTOP_XFCE;
+        } else if (group.find ("GUI/Other") != std::string::npos) {
+                pkGroup = PK_GROUP_ENUM_DESKTOP_OTHER;
+        } else if (group.find ("Localization") != std::string::npos) {
+                pkGroup = PK_GROUP_ENUM_LOCALIZATION;
+        } else if (group.find ("System") != std::string::npos) {
+                pkGroup = PK_GROUP_ENUM_SYSTEM;
+        } else if (group.find ("Scientific") != std::string::npos) {
+                pkGroup = PK_GROUP_ENUM_EDUCATION;
+        }
+
+        return pkGroup;
+}
+
 std::vector<zypp::PoolItem> *
 zypp_get_packages_by_name (const gchar *package_name, gboolean include_local)
 {
diff --git a/backends/zypp/zypp-utils.h b/backends/zypp/zypp-utils.h
index 50ccf23..5365cca 100644
--- a/backends/zypp/zypp-utils.h
+++ b/backends/zypp/zypp-utils.h
@@ -41,6 +41,11 @@ zypp::ResPool zypp_build_pool (gboolean include_local);
 zypp::ResPool zypp_build_local_pool ();
 
 /**
+  * Return the PkGroupEnum of the given PoolItem.
+  */
+PkGroupEnum zypp_get_group (zypp::ResObject::constPtr item);
+
+/**
  * Returns a list of packages that match the specified package_name.
  */
 std::vector<zypp::PoolItem> * zypp_get_packages_by_name (const gchar *package_name, gboolean include_local);
commit 6dc3e6e06d759761a316cf559172a46622659e47
Merge: 136830c... febc7b9...
Author: Robin Norwood <rnorwood at redhat.com>
Date:   Thu Feb 21 17:39:36 2008 -0500

    Merge branch 'master' of git+ssh://rnorwood@git.packagekit.org/srv/git/PackageKit

commit 136830c94ce1e3efbd5d7c0fbd7146f68ed36fcb
Author: Robin Norwood <rnorwood at redhat.com>
Date:   Thu Feb 21 17:29:30 2008 -0500

    o Increase timeout to 30 minutes instead of 30 seconds.
    o Rename constants.
    o Remove debug print statement.

diff --git a/python/packagekit/daemonBackend.py b/python/packagekit/daemonBackend.py
index fdfabce..dd4f82d 100644
--- a/python/packagekit/daemonBackend.py
+++ b/python/packagekit/daemonBackend.py
@@ -39,12 +39,12 @@ import time
 PACKAGEKIT_DBUS_INTERFACE = 'org.freedesktop.PackageKitBackend'
 PACKAGEKIT_DBUS_PATH = '/org/freedesktop/PackageKitBackend'
 
-INACTIVITY_CHECK_TIMEOUT = 1000 * 60 * 5 # Check every 5 minutes.
+INACTIVE_CHECK_TIMEOUT = 1000 * 60 * 5 # Check every 5 minutes.
+INACTIVE_TIMEOUT = 1000 * 60 * 30 # timeout after 30 minutes of inactivity.
 
 class PackageKitBaseBackend(dbus.service.Object):
 
     def PKSignalHouseKeeper(func):
-        print "wrapping..."
         def wrapper(*args,**kwargs):
             self = args[0]
             self.last_action_time = time.time()
@@ -74,7 +74,7 @@ class PackageKitBaseBackend(dbus.service.Object):
 
         self.loop = gobject.MainLoop()
 
-        gobject.timeout_add(INACTIVITY_CHECK_TIMEOUT, self.check_for_inactivity)
+        gobject.timeout_add(INACTIVE_CHECK_TIMEOUT, self.check_for_inactivity)
         self.last_action_time = time.time()
 
         self.loop.run()
@@ -91,7 +91,7 @@ class PackageKitBaseBackend(dbus.service.Object):
         return self._locked
 
     def check_for_inactivity(self):
-        if time.time() - self.last_action_time > 30:
+        if time.time() - self.last_action_time > INACTIVE_TIMEOUT:
             print "Exiting due to timeout."
             self.Exit()
 
commit 26a9758a4875cafcc8d1ca7687c1281f220c9334
Author: Robin Norwood <rnorwood at redhat.com>
Date:   Thu Feb 21 17:23:52 2008 -0500

    Add a timeout on the yum dbus backend.  If no signal or method is sent within the timeout, then abort.
    
    Note: I would've implemented the last_action_time update in a
    decorator for the methods, but the dbus decorator does introspection
    of the function it decorates, and does not like having that function
    wrapped by another decorator, or having the wrapper it uses wrapped
    inside a decorator.

diff --git a/backends/yum2/helpers/yumDBUSBackend.py b/backends/yum2/helpers/yumDBUSBackend.py
index 2118011..81b8e2e 100755
--- a/backends/yum2/helpers/yumDBUSBackend.py
+++ b/backends/yum2/helpers/yumDBUSBackend.py
@@ -51,6 +51,8 @@ import types
 import signal
 import time
 import os.path
+import operator
+
 
 # Global vars
 yumbase = None
@@ -302,6 +304,7 @@ class PackageKitYumBackend(PackageKitBaseBackend):
     @dbus.service.method(PACKAGEKIT_DBUS_INTERFACE,
                          in_signature='', out_signature='')
     def Init(self):
+        self.last_action_time = time.time()
         self.yumbase = PackageKitYumBase()
         yumbase = self.yumbase
         self._setup_yum()
@@ -310,6 +313,7 @@ class PackageKitYumBackend(PackageKitBaseBackend):
     @dbus.service.method(PACKAGEKIT_DBUS_INTERFACE,
                          in_signature='', out_signature='')
     def Exit(self):
+        self.last_action_time = time.time()
         if self.isLocked():
             self.doUnlock()
 
@@ -318,6 +322,7 @@ class PackageKitYumBackend(PackageKitBaseBackend):
     @dbus.service.method(PACKAGEKIT_DBUS_INTERFACE,
                          in_signature='', out_signature='')
     def Lock(self):
+        self.last_action_time = time.time()
         self.doLock()
 
     def doLock(self):
@@ -340,6 +345,7 @@ class PackageKitYumBackend(PackageKitBaseBackend):
     @dbus.service.method(PACKAGEKIT_DBUS_INTERFACE,
                          in_signature='', out_signature='')
     def Unlock(self):
+        self.last_action_time = time.time()
         self.doUnlock()
 
     def doUnlock(self):
@@ -355,6 +361,7 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         '''
         Implement the {backend}-search-name functionality
         '''
+        self.last_action_time = time.time()
         self._check_init(cache=True)
         self.AllowCancel(True)
         self.NoPercentageUpdates()
@@ -375,6 +382,7 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         '''
         Implement the {backend}-search-details functionality
         '''
+        self.last_action_time = time.time()
         self._check_init(cache=True)
         self.AllowCancel(True)
         self.NoPercentageUpdates()
@@ -395,6 +403,7 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         '''
         Implement the {backend}-search-group functionality
         '''
+        self.last_action_time = time.time()
         self._check_init(cache=True)
         self.AllowCancel(True)
         self.NoPercentageUpdates()
@@ -443,6 +452,7 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         '''
         Implement the {backend}-search-file functionality
         '''
+        self.last_action_time = time.time()
         self._check_init(cache=True)
         self.AllowCancel(True)
         self.NoPercentageUpdates()
@@ -477,6 +487,7 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         '''
         Print a list of requires for a given package
         '''
+        self.last_action_time = time.time()
         self._check_init(cache=True)
         self.AllowCancel(True)
         self.NoPercentageUpdates()
@@ -503,6 +514,7 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         '''
         Print a list of depends for a given package
         '''
+        self.last_action_time = time.time()
         self._check_init(cache=True)
         self.AllowCancel(True)
         self.PercentageChanged(0)
@@ -538,6 +550,7 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         '''
         Implement the {backend}-update-system functionality
         '''
+        self.last_action_time = time.time()
         self._check_init()
         self.AllowCancel(False)
         self.PercentageChanged(0)
@@ -564,6 +577,7 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         '''
         Implement the {backend}-refresh_cache functionality
         '''
+        self.last_action_time = time.time()
         self._check_init()
         self.AllowCancel(True);
         self.PercentageChanged(0)
@@ -617,6 +631,7 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         '''
         Implement the {backend}-resolve functionality
         '''
+        self.last_action_time = time.time()
         self._check_init(cache=True)
         self.AllowCancel(True);
         self.NoPercentageUpdates()
@@ -657,6 +672,7 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         Implement the {backend}-install functionality
         This will only work with yum 3.2.4 or higher
         '''
+        self.last_action_time = time.time()
         self._check_init()
         self.AllowCancel(False)
         self.PercentageChanged(0)
@@ -692,6 +708,7 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         Install the package containing the inst_file file
         Needed to be implemented in a sub class
         '''
+        self.last_action_time = time.time()
         self._check_init()
         self.AllowCancel(False);
         self.PercentageChanged(0)
@@ -720,6 +737,7 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         Implement the {backend}-update functionality
         This will only work with yum 3.2.4 or higher
         '''
+        self.last_action_time = time.time()
         self._check_init()
         self.AllowCancel(False);
         self.PercentageChanged(0)
@@ -748,6 +766,7 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         '''
         Implement the {backend}-remove functionality
         '''
+        self.last_action_time = time.time()
         self._check_init()
         self.AllowCancel(False);
         self.PercentageChanged(0)
@@ -781,6 +800,7 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         '''
         Print a detailed description for a given package
         '''
+        self.last_action_time = time.time()
         self._check_init(cache=True)
         self.AllowCancel(True)
         self.NoPercentageUpdates()
@@ -799,6 +819,7 @@ class PackageKitYumBackend(PackageKitBaseBackend):
     @dbus.service.method(PACKAGEKIT_DBUS_INTERFACE,
                          in_signature='s', out_signature='')
     def GetFiles(self, package):
+        self.last_action_time = time.time()
         self._check_init(cache=True)
         self.AllowCancel(True)
         self.NoPercentageUpdates()
@@ -825,6 +846,7 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         '''
         Implement the {backend}-get-updates functionality
         '''
+        self.last_action_time = time.time()
         self._check_init(cache=True)
         self.AllowCancel(True)
         self.NoPercentageUpdates()
@@ -858,6 +880,7 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         @param filters: package types to search (all,installed,available)
         @param key: key to seach for
         '''
+        self.last_action_time = time.time()
         self._check_init(cache=True)
         self.AllowCancel(True)
         self.NoPercentageUpdates()
@@ -896,13 +919,13 @@ class PackageKitYumBackend(PackageKitBaseBackend):
 
         self.Finished(EXIT_SUCCESS)
         
-
     @dbus.service.method(PACKAGEKIT_DBUS_INTERFACE,
                          in_signature='sb', out_signature='')
     def RepoEnable(self, repoid, enable):
         '''
         Implement the {backend}-repo-enable functionality
         '''
+        self.last_action_time = time.time()
         self._check_init()
         try:
             repo = self.yumbase.repos.getRepo(repoid)
@@ -926,6 +949,7 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         '''
         Implement the {backend}-get-repo-list functionality
         '''
+        self.last_action_time = time.time()
         self._check_init()
         self.StatusChanged(STATUS_INFO)
         for repo in self.yumbase.repos.repos.values():
@@ -936,13 +960,13 @@ class PackageKitYumBackend(PackageKitBaseBackend):
 
         self.Finished(EXIT_SUCCESS)
 
-
     @dbus.service.method(PACKAGEKIT_DBUS_INTERFACE,
                          in_signature='s', out_signature='')
     def GetUpdateDetail(self,package):
         '''
         Implement the {backend}-get-update_detail functionality
         '''
+        self.last_action_time = time.time()
         self._check_init()
         self.AllowCancel(True)
         self.NoPercentageUpdates()
@@ -971,6 +995,7 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         '''
         Implement the {backend}-repo-set-data functionality
         '''
+        self.last_action_time = time.time()
         self._check_init()
         self.AllowCancel(False)
         self.NoPercentageUpdates()
@@ -1694,6 +1719,87 @@ class PackageKitYumBase(yum.YumBase):
         yum.YumBase.__init__(self)
         self.missingGPGKey = None
 
+    # Modified searchGenerator to make sure that
+    # non unicode strings read from rpmdb is converted to unicode
+    # FIXME: Remove this when fixed and released in upstream
+    def searchGenerator(self, fields, criteria, showdups=True):
+        """Generator method to lighten memory load for some searches.
+           This is the preferred search function to use."""
+        sql_fields = []
+        for f in fields:
+            if RPM_TO_SQLITE.has_key(f):
+                sql_fields.append(RPM_TO_SQLITE[f])
+            else:
+                sql_fields.append(f)
+
+        matched_values = {}
+
+        # yield the results in order of most terms matched first
+        sorted_lists = {}
+        tmpres = []
+        real_crit = []
+        for s in criteria:
+            if s.find('%') == -1:
+                real_crit.append(s)
+        real_crit_lower = [] # Take the s.lower()'s out of the loop
+        for s in criteria:
+            if s.find('%') == -1:
+                real_crit_lower.append(s.lower())
+
+        for sack in self.pkgSack.sacks.values():
+            tmpres.extend(sack.searchPrimaryFieldsMultipleStrings(sql_fields, real_crit))
+
+        for (po, count) in tmpres:
+            # check the pkg for sanity
+            # pop it into the sorted lists
+            tmpvalues = []
+            if count not in sorted_lists: sorted_lists[count] = []
+            for s in real_crit_lower:
+                for field in fields:
+                    value = getattr(po, field)
+                    if value and value.lower().find(s) != -1:
+                        tmpvalues.append(value)
+
+            if len(tmpvalues) > 0:
+                sorted_lists[count].append((po, tmpvalues))
+
+            
+        
+        for po in self.rpmdb:
+            tmpvalues = []
+            criteria_matched = 0
+            for s in real_crit_lower:
+                matched_s = False
+                for field in fields:
+                    value = getattr(po, field)
+                    # make sure that string are in unicode
+                    if isinstance(value, str):
+                        value = unicode(value,'unicode-escape')
+                    if value and value.lower().find(s) != -1:
+                        if not matched_s:
+                            criteria_matched += 1
+                            matched_s = True
+                        
+                        tmpvalues.append(value)
+
+
+            if len(tmpvalues) > 0:
+                if criteria_matched not in sorted_lists: sorted_lists[criteria_matched] = []
+                sorted_lists[criteria_matched].append((po, tmpvalues))
+                
+
+        # close our rpmdb connection so we can ctrl-c, kthxbai                    
+        self.closeRpmDB()
+        
+        yielded = {}
+        for val in reversed(sorted(sorted_lists)):
+            for (po, matched) in sorted(sorted_lists[val], key=operator.itemgetter(0)):
+                if (po.name, po.arch) not in yielded:
+                    yield (po, matched)
+                    if not showdups:
+                        yielded[(po.name, po.arch)] = 1
+
+
     def _checkSignatures(self,pkgs,callback):
         ''' The the signatures of the downloaded packages '''
         # This can be overloaded by a subclass.
diff --git a/python/packagekit/daemonBackend.py b/python/packagekit/daemonBackend.py
index 5f6db8c..fdfabce 100644
--- a/python/packagekit/daemonBackend.py
+++ b/python/packagekit/daemonBackend.py
@@ -31,20 +31,52 @@ import os
 from pkexceptions import *
 import dbus.service
 
+import time
+
 # Classes
 
 # This is common between backends
 PACKAGEKIT_DBUS_INTERFACE = 'org.freedesktop.PackageKitBackend'
 PACKAGEKIT_DBUS_PATH = '/org/freedesktop/PackageKitBackend'
 
+INACTIVITY_CHECK_TIMEOUT = 1000 * 60 * 5 # Check every 5 minutes.
+
 class PackageKitBaseBackend(dbus.service.Object):
 
+    def PKSignalHouseKeeper(func):
+        print "wrapping..."
+        def wrapper(*args,**kwargs):
+            self = args[0]
+            self.last_action_time = time.time()
+
+            return func(*args,**kwargs)
+
+        return wrapper
+
+# I tried to do the same thing with methods as we do with signals, but
+# dbus-python's method decorator uses inspect.getargspec...since the
+# signature of the wrapper function is different.  So now each method
+# has to call self.last_action_time = time.time()
+#
+#    def PKMethodHouseKeeper(func):
+#        def wrapper(*args,**kwargs):
+#            self = args[0]
+#            self.last_action_time = time.time()
+#
+#            return func(*args, **kwargs)
+#
+#        return wrapper
+
     def __init__(self, bus_name, dbus_path):
         dbus.service.Object.__init__(self, bus_name, dbus_path)
 
         self._locked = False
 
         self.loop = gobject.MainLoop()
+
+        gobject.timeout_add(INACTIVITY_CHECK_TIMEOUT, self.check_for_inactivity)
+        self.last_action_time = time.time()
+
         self.loop.run()
 
     def doLock(self):
@@ -58,65 +90,84 @@ class PackageKitBaseBackend(dbus.service.Object):
     def isLocked(self):
         return self._locked
 
+    def check_for_inactivity(self):
+        if time.time() - self.last_action_time > 30:
+            print "Exiting due to timeout."
+            self.Exit()
+
+        return True
+
 #
 # Signals ( backend -> engine -> client )
 #
 
+    @PKSignalHouseKeeper
     @dbus.service.signal(dbus_interface=PACKAGEKIT_DBUS_INTERFACE,
                          signature='s')
     def Finished(self, exit):
         print "Finished (%s)" % (exit)
 
+    @PKSignalHouseKeeper
     @dbus.service.signal(dbus_interface=PACKAGEKIT_DBUS_INTERFACE,
                          signature='ssb')
     def RepoDetail(self, repo_id, description, enabled):
         print "RepoDetail (%s, %s, %i)" % (repo_id, description, enabled)
 
+    @PKSignalHouseKeeper
     @dbus.service.signal(dbus_interface=PACKAGEKIT_DBUS_INTERFACE,
                          signature='b')
     def AllowCancel(self, allow_cancel):
         print "AllowCancel (%i)" % (allow_cancel)
 
+    @PKSignalHouseKeeper
     @dbus.service.signal(dbus_interface=PACKAGEKIT_DBUS_INTERFACE,
                          signature='sss')
     def Package(self, status, package_id, summary):
         print "Package (%s, %s, %s)" % (status, package_id, summary)
 
+    @PKSignalHouseKeeper
     @dbus.service.signal(dbus_interface=PACKAGEKIT_DBUS_INTERFACE,
                          signature='sssssu')
     def Description(self, package_id, license, group, detail, url, size):
         print "Description (%s, %s, %s, %s, %s, %u)" % (package_id, license, group, detail, url, size)
 
+    @PKSignalHouseKeeper
     @dbus.service.signal(dbus_interface=PACKAGEKIT_DBUS_INTERFACE,
                          signature='ss')
     def Files(self, package_id, file_list):
         print "Files (%s, %s)" % (package_id, file_list)
 
+    @PKSignalHouseKeeper
     @dbus.service.signal(dbus_interface=PACKAGEKIT_DBUS_INTERFACE,
                          signature='s')
     def StatusChanged(self, status):
         print "StatusChanged (%s)" % (status)
 
+    @PKSignalHouseKeeper
     @dbus.service.signal(dbus_interface=PACKAGEKIT_DBUS_INTERFACE,
                          signature='')
     def NoPercentageUpdates(self):
         print "NoPercentageUpdates"
 
+    @PKSignalHouseKeeper
     @dbus.service.signal(dbus_interface=PACKAGEKIT_DBUS_INTERFACE,
                          signature='u')
     def PercentageChanged(self, percentage):
         print "PercentageChanged (%i)" % (percentage)
 
+    @PKSignalHouseKeeper
     @dbus.service.signal(dbus_interface=PACKAGEKIT_DBUS_INTERFACE,
                          signature='u')
     def SubPercentageChanged(self, percentage):
         print "SubPercentageChanged (%i)" % (percentage)
 
+    @PKSignalHouseKeeper
     @dbus.service.signal(dbus_interface=PACKAGEKIT_DBUS_INTERFACE,
                          signature='ssssssss')
     def UpdateDetail(self, package_id, updates, obsoletes, vendor_url, bugzilla_url, cve_url, restart, update):
         print "UpdateDetail (%s, %s, %s, %s, %s, %s, %s, %s)" % (package_id, updates, obsoletes, vendor_url, bugzilla_url, cve_url, restart, update)
 
+    @PKSignalHouseKeeper
     @dbus.service.signal(dbus_interface=PACKAGEKIT_DBUS_INTERFACE,
                          signature='ss')
     def ErrorCode(self, code, description):
@@ -127,6 +178,7 @@ class PackageKitBaseBackend(dbus.service.Object):
         '''
         print "ErrorCode (%s, %s)" % (code, description)
 
+    @PKSignalHouseKeeper
     @dbus.service.signal(dbus_interface=PACKAGEKIT_DBUS_INTERFACE,
                          signature='ss')
     def MetaData(self,typ,fname):
@@ -137,6 +189,7 @@ class PackageKitBaseBackend(dbus.service.Object):
         '''
         print  "MetaData (%s, %s)" % (typ,fname)
 
+    @PKSignalHouseKeeper
     @dbus.service.signal(dbus_interface=PACKAGEKIT_DBUS_INTERFACE,
                          signature='ss')
     def RequireRestart(self,type,details):
@@ -147,6 +200,7 @@ class PackageKitBaseBackend(dbus.service.Object):
         '''
         print  "RestartRequired (%s, %s)" % (type,details)
 
+    @PKSignalHouseKeeper
     @dbus.service.signal(dbus_interface=PACKAGEKIT_DBUS_INTERFACE,
                          signature='ss')
     def Message(self,type,details):
@@ -157,6 +211,7 @@ class PackageKitBaseBackend(dbus.service.Object):
         '''
         print  "Message (%s, %s)" % (type,details)
 
+    @PKSignalHouseKeeper
     @dbus.service.signal(dbus_interface=PACKAGEKIT_DBUS_INTERFACE,
                          signature='')
     def UpdatesChanged(self,typ,fname):
@@ -169,6 +224,10 @@ class PackageKitBaseBackend(dbus.service.Object):
 #
 # Methods ( client -> engine -> backend )
 #
+# Python inheritence with decorators makes implementing these in the
+# base class and overriding them in child classes very ugly.  So
+# they're commented out here.  Just implement the ones you need in
+# your class, and don't forget the decorators.
 #
 #    @dbus.service.method(PACKAGEKIT_DBUS_INTERFACE,
 #                         in_signature='', out_signature='')
@@ -202,6 +261,7 @@ class PackageKitBaseBackend(dbus.service.Object):
 #        self.ErrorCode(ERROR_NOT_SUPPORTED,"Method not supported")
 #        self.Exit()
 #
+#    @PKMethodHouseKeeper
 #    @dbus.service.method(PACKAGEKIT_DBUS_INTERFACE,
 #                         in_signature='ss', out_signature='')
 #    def SearchName(self, filters, search):
@@ -211,6 +271,7 @@ class PackageKitBaseBackend(dbus.service.Object):
 #        self.ErrorCode(ERROR_NOT_SUPPORTED,"Method not supported")
 #        self.Exit()
 #
+#    @PKMethodHouseKeeper
 #    @dbus.service.method(PACKAGEKIT_DBUS_INTERFACE,
 #                         in_signature='ss', out_signature='')
 #    def SearchDetails(self,filters,key):
@@ -220,6 +281,7 @@ class PackageKitBaseBackend(dbus.service.Object):
 #        self.ErrorCode(ERROR_NOT_SUPPORTED,"Method not supported")
 #        self.Exit()
 #
+#    @PKMethodHouseKeeper
 #    @dbus.service.method(PACKAGEKIT_DBUS_INTERFACE,
 #                         in_signature='ss', out_signature='')
 #    def SearchGroup(self,filters,key):
@@ -229,6 +291,7 @@ class PackageKitBaseBackend(dbus.service.Object):
 #        self.ErrorCode(ERROR_NOT_SUPPORTED,"Method not supported")
 #        self.Exit()
 #
+#    @PKMethodHouseKeeper
 #    @dbus.service.method(PACKAGEKIT_DBUS_INTERFACE,
 #                         in_signature='ss', out_signature='')
 #    def SearchFile(self,filters,key):
@@ -238,6 +301,7 @@ class PackageKitBaseBackend(dbus.service.Object):
 #        self.ErrorCode(ERROR_NOT_SUPPORTED,"Method not supported")
 #        self.Exit()
 #
+#    @PKMethodHouseKeeper
 #    @dbus.service.method(PACKAGEKIT_DBUS_INTERFACE,
 #                         in_signature='sb', out_signature='')
 #    def GetRequires(self,package,recursive):
@@ -247,6 +311,7 @@ class PackageKitBaseBackend(dbus.service.Object):
 #        self.ErrorCode(ERROR_NOT_SUPPORTED,"Method not supported")
 #        self.Exit()
 #
+#    @PKMethodHouseKeeper
 #    @dbus.service.method(PACKAGEKIT_DBUS_INTERFACE,
 #                         in_signature='sb', out_signature='')
 #    def GetDepends(self,package,recursive):
@@ -256,6 +321,7 @@ class PackageKitBaseBackend(dbus.service.Object):
 #        self.ErrorCode(ERROR_NOT_SUPPORTED,"Method not supported")
 #        self.Exit()
 #
+#    @PKMethodHouseKeeper
 #    @dbus.service.method(PACKAGEKIT_DBUS_INTERFACE,
 #                         in_signature='', out_signature='')
 #    def UpdateSystem(self):
@@ -265,6 +331,7 @@ class PackageKitBaseBackend(dbus.service.Object):
 #        self.ErrorCode(ERROR_NOT_SUPPORTED,"Method not supported")
 #        self.Exit()
 #
+#    @PKMethodHouseKeeper
 #    @dbus.service.method(PACKAGEKIT_DBUS_INTERFACE,
 #                         in_signature='b', out_signature='')
 #    def RefreshCache(self, force):
@@ -274,7 +341,7 @@ class PackageKitBaseBackend(dbus.service.Object):
 #        self.ErrorCode(ERROR_NOT_SUPPORTED,"Method not supported")
 #        self.Exit()
 #
-#
+#    @PKMethodHouseKeeper
 #    @dbus.service.method(PACKAGEKIT_DBUS_INTERFACE,
 #                         in_signature='ss', out_signature='')
 #    def Resolve(self, filters, name):
@@ -284,6 +351,7 @@ class PackageKitBaseBackend(dbus.service.Object):
 #        self.ErrorCode(ERROR_NOT_SUPPORTED,"Method not supported")
 #        self.Exit()
 #
+#    @PKMethodHouseKeeper
 #    @dbus.service.method(PACKAGEKIT_DBUS_INTERFACE,
 #                         in_signature='s', out_signature='')
 #    def InstallPackage(self, package):
@@ -294,6 +362,7 @@ class PackageKitBaseBackend(dbus.service.Object):
 #        self.ErrorCode(ERROR_NOT_SUPPORTED,"Method not supported")
 #        self.Exit()
 #
+#    @PKMethodHouseKeeper
 #    @dbus.service.method(PACKAGEKIT_DBUS_INTERFACE,
 #                         in_signature='s', out_signature='')
 #    def InstallFile (self, inst_file):
@@ -305,6 +374,7 @@ class PackageKitBaseBackend(dbus.service.Object):
 #        self.ErrorCode(ERROR_NOT_SUPPORTED,"Method not supported")
 #        self.Exit()
 #
+#    @PKMethodHouseKeeper
 #    @dbus.service.method(PACKAGEKIT_DBUS_INTERFACE,
 #                         in_signature='s', out_signature='')
 #    def ServicePack (self, location):
@@ -316,6 +386,7 @@ class PackageKitBaseBackend(dbus.service.Object):
 #        self.ErrorCode(ERROR_NOT_SUPPORTED,"Method not supported")
 #        self.Exit()
 #
+#    @PKMethodHouseKeeper
 #    @dbus.service.method(PACKAGEKIT_DBUS_INTERFACE,
 #                         in_signature='s', out_signature='')
 #    def UpdatePackage(self, package):
@@ -325,6 +396,7 @@ class PackageKitBaseBackend(dbus.service.Object):
 #        self.ErrorCode(ERROR_NOT_SUPPORTED,"Method not supported")
 #        self.Exit()
 #
+#    @PKMethodHouseKeeper
 #    @dbus.service.method(PACKAGEKIT_DBUS_INTERFACE,
 #                         in_signature='sb', out_signature='')
 #    def RemovePackage(self, package, allowdep):
@@ -334,6 +406,7 @@ class PackageKitBaseBackend(dbus.service.Object):
 #        self.ErrorCode(ERROR_NOT_SUPPORTED,"Method not supported")
 #        self.Exit()
 #
+#    @PKMethodHouseKeeper
 #    @dbus.service.method(PACKAGEKIT_DBUS_INTERFACE,
 #                         in_signature='s', out_signature='')
 #    def GetDescription(self, package):
@@ -343,6 +416,7 @@ class PackageKitBaseBackend(dbus.service.Object):
 #        self.ErrorCode(ERROR_NOT_SUPPORTED,"Method not supported")
 #        self.Exit()
 #
+#    @PKMethodHouseKeeper
 #    @dbus.service.method(PACKAGEKIT_DBUS_INTERFACE,
 #                         in_signature='s', out_signature='')
 #    def GetFiles(self, package):
@@ -352,6 +426,7 @@ class PackageKitBaseBackend(dbus.service.Object):
 #        self.ErrorCode(ERROR_NOT_SUPPORTED,"Method not supported")
 #        self.Exit()
 #
+#    @PKMethodHouseKeeper
 #    @dbus.service.method(PACKAGEKIT_DBUS_INTERFACE,
 #                         in_signature='', out_signature='')
 #    def GetUpdates(self):
@@ -361,6 +436,7 @@ class PackageKitBaseBackend(dbus.service.Object):
 #        self.ErrorCode(ERROR_NOT_SUPPORTED,"Method not supported")
 #        self.Exit()
 #
+#    @PKMethodHouseKeeper
 #    @dbus.service.method(PACKAGEKIT_DBUS_INTERFACE,
 #                         in_signature='sb', out_signature='')
 #    def RepoEnable(self, repoid, enable):
@@ -370,6 +446,7 @@ class PackageKitBaseBackend(dbus.service.Object):
 #        self.ErrorCode(ERROR_NOT_SUPPORTED,"Method not supported")
 #        self.Exit()
 #
+#    @PKMethodHouseKeeper
 #    @dbus.service.method(PACKAGEKIT_DBUS_INTERFACE,
 #                         in_signature='', out_signature='')
 #    def GetRepoList(self):
@@ -379,6 +456,7 @@ class PackageKitBaseBackend(dbus.service.Object):
 #        self.ErrorCode(ERROR_NOT_SUPPORTED,"Method not supported")
 #        self.Exit()
 #
+#    @PKMethodHouseKeeper
 #    @dbus.service.method(PACKAGEKIT_DBUS_INTERFACE,
 #                         in_signature='s', out_signature='')
 #    def GetUpdateDetail(self,package):
@@ -388,6 +466,7 @@ class PackageKitBaseBackend(dbus.service.Object):
 #        self.ErrorCode(ERROR_NOT_SUPPORTED,"Method not supported")
 #        self.Exit()
 #
+#    @PKMethodHouseKeeper
 #    @dbus.service.method(PACKAGEKIT_DBUS_INTERFACE,
 #                         in_signature='sss', out_signature='')
 #    def RepoSetData(self, repoid, parameter, value):
@@ -396,6 +475,7 @@ class PackageKitBaseBackend(dbus.service.Object):
 #        '''
 #        self.ErrorCode(ERROR_NOT_SUPPORTED,"Method not supported")
 #        self.Exit()
+
 #
 # Utility methods
 #
commit 319a4407331037ac088f9925280dc0f947ca82bb
Author: Robin Norwood <rnorwood at redhat.com>
Date:   Thu Feb 21 15:07:17 2008 -0500

    merge changes to testym2

diff --git a/backends/yum2/helpers/testyum2.py b/backends/yum2/helpers/testyum2.py
index f59f773..15ec90a 100755
--- a/backends/yum2/helpers/testyum2.py
+++ b/backends/yum2/helpers/testyum2.py
@@ -37,43 +37,58 @@ except dbus.DBusException, e:
 try:
     proxy = bus.get_object(PACKAGEKIT_DBUS_SERVICE, PACKAGEKIT_DBUS_PATH)
     iface = dbus.Interface(proxy, PACKAGEKIT_DBUS_INTERFACE)
-    print "Testing Init()"
-    iface.Init()
-    print "Testing GetUpdate()"
-    iface.GetUpdates()
-    print "Testing SearchName(FILTER_NONE,'yum')"
-    iface.SearchName(FILTER_NONE,'yum')
-    # print "SearchDetails(FILTER_NONE,'dbus')"
-    # This one is failing because of some  UnicodeDecodeError in yum 
-    #iface.SearchDetails(FILTER_NONE,'DBus')
-    print "Testing SearchGroup(FILTER_NONE,GROUP_GAMES)"
-    iface.SearchGroup(FILTER_NONE,GROUP_GAMES)
-    print "Testing SearchFile(FILTER_NONE,'/usr/bin/yum')"
-    iface.SearchFile(FILTER_NONE,'/usr/bin/yum')
-    print "Testing GetRequires(PKG_ID,False)"
-    iface.GetRequires(PKG_ID,False)
-    print "Testing GetDepends(PKG_ID,False)"
-    iface.GetDepends(PKG_ID,False)
-    print "Testing RefreshCache(True)"
-    iface.RefreshCache(True)
-    print "Testing Resolve(FILTER_NONE,'yum')"
-    iface.Resolve(FILTER_NONE,'yum')
-    print "Testing GetDescription(PKG_ID)"
-    iface.GetDescription(PKG_ID)
-    print "Testing GetFiles(PKG_ID)"
-    iface.GetFiles(PKG_ID)
-    print "Testing GetPackages(FILTER_INSTALLED,'no')"
-    iface.GetPackages(FILTER_INSTALLED,'no')
-    print "Testing GetRepoList()"
-    iface.GetRepoList()
-    print "Testing GetUpdateDetail(PKG_ID)"
-    iface.GetUpdateDetail(PKG_ID)
+    cmd = sys.argv[1]
+    if cmd == 'init' or cmd == 'all':
+        print "Testing Init()"
+        iface.Init()
+    if cmd == 'get-updates' or cmd == 'all':
+        print "Testing GetUpdate()"
+        iface.GetUpdates()
+    if cmd == 'search-name' or cmd == 'all':
+        print "Testing SearchName(FILTER_NONE,'yum')"
+        iface.SearchName(FILTER_NONE,'yum')
+    if cmd == 'search-details' or cmd == 'all':
+        print "SearchDetails(FILTER_NONE,'dbus')"
+        # This one is failing because of some  UnicodeDecodeError in yum 
+        iface.SearchDetails(FILTER_NONE,'dbus')
+    if cmd == 'search-group' or cmd == 'all':
+        print "Testing SearchGroup(FILTER_NONE,GROUP_GAMES)"
+        iface.SearchGroup(FILTER_NONE,GROUP_GAMES)
+    if cmd == 'search-file' or cmd == 'all':
+        print "Testing SearchFile(FILTER_NONE,'/usr/bin/yum')"
+        iface.SearchFile(FILTER_NONE,'/usr/bin/yum')
+    if cmd == 'get-requires' or cmd == 'all':
+        print "Testing GetRequires(PKG_ID,False)"
+        iface.GetRequires(PKG_ID,False)
+    if cmd == 'get-depends' or cmd == 'all':
+        print "Testing GetDepends(PKG_ID,False)"
+        iface.GetDepends(PKG_ID,False)
+    if cmd == 'refresh-cache' or cmd == 'all':
+        print "Testing RefreshCache()"
+        iface.RefreshCache()
+    if cmd == 'resolve' or cmd == 'all':
+        print "Testing Resolve(FILTER_NONE,'yum')"
+        iface.Resolve(FILTER_NONE,'yum')
+    if cmd == 'get-description' or cmd == 'all':
+        print "Testing GetDescription(PKG_ID)"
+        iface.GetDescription(PKG_ID)
+    if cmd == 'get-files' or cmd == 'all':
+        print "Testing GetFiles(PKG_ID)"
+        iface.GetFiles(PKG_ID)
+    if cmd == 'get-packages' or cmd == 'all':
+        print "Testing GetPackages(FILTER_INSTALLED,'no')"
+        iface.GetPackages(FILTER_INSTALLED,'no')
+    if cmd == 'get-repolist' or cmd == 'all':
+        print "Testing GetRepoList()"
+        iface.GetRepoList()
+    if cmd == 'get-updatedetail' or cmd == 'all':
+        print "Testing GetUpdateDetail(PKG_ID)"
+        iface.GetUpdateDetail(PKG_ID)
     #print "Testing "
     #iface.
-    print "Testing RefreshCache(False)"
-    iface.RefreshCache(False)
-    print "Testing Exit()"
-    iface.Exit()
+    if cmd == 'exit' or cmd == 'all':
+        print "Testing Exit()"
+        iface.Exit()
     
 except dbus.DBusException, e:
     print "Unable to send message on dbus"
commit febc7b9a1a88b18955cacf7c2a9ad76df5f50e4b
Author: Richard Hughes <richard at hughsie.com>
Date:   Thu Feb 21 19:16:25 2008 +0000

    post release version bump

diff --git a/configure.ac b/configure.ac
index d95d4eb..47be954 100755
--- a/configure.ac
+++ b/configure.ac
@@ -1,6 +1,6 @@
 AC_PREREQ(2.52)
 
-AC_INIT(PackageKit, 0.1.8)
+AC_INIT(PackageKit, 0.1.9)
 AC_CONFIG_SRCDIR(src)
 AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION)
 AM_CONFIG_HEADER(config.h)
commit 7b95dd5e9579e7514e57254b0fdb54488526c695
Author: Robin Norwood <rnorwood at redhat.com>
Date:   Wed Feb 20 17:48:18 2008 -0500

    add new force parameter for RefreshCache.

diff --git a/backends/yum2/helpers/testyum2.py b/backends/yum2/helpers/testyum2.py
index 05d9faa..f59f773 100755
--- a/backends/yum2/helpers/testyum2.py
+++ b/backends/yum2/helpers/testyum2.py
@@ -54,8 +54,8 @@ try:
     iface.GetRequires(PKG_ID,False)
     print "Testing GetDepends(PKG_ID,False)"
     iface.GetDepends(PKG_ID,False)
-    print "Testing RefreshCache()"
-    iface.RefreshCache()
+    print "Testing RefreshCache(True)"
+    iface.RefreshCache(True)
     print "Testing Resolve(FILTER_NONE,'yum')"
     iface.Resolve(FILTER_NONE,'yum')
     print "Testing GetDescription(PKG_ID)"
@@ -70,8 +70,8 @@ try:
     iface.GetUpdateDetail(PKG_ID)
     #print "Testing "
     #iface.
-    print "Testing RefreshCache()"
-    iface.RefreshCache()
+    print "Testing RefreshCache(False)"
+    iface.RefreshCache(False)
     print "Testing Exit()"
     iface.Exit()
     



More information about the PackageKit mailing list