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

Richard Hughes hughsient at kemper.freedesktop.org
Wed Sep 26 14:36:54 PDT 2007


 python/packagekit/__init__.py |   18 ------
 python/packagekit/frontend.py |  116 ++++++++++++++++++++++++++++++++----------
 python/pk-frontend-test.py    |    8 +-
 3 files changed, 94 insertions(+), 48 deletions(-)

New commits:
diff-tree 6bb3bde62e79fd76ee0534e9e50c6dc3409e9028 (from parents)
Merge: 9b8629dac8dfb487fbe8eeab50b09e5267e6292c dbc3485ac113b46241db5f86042c4ad2886e0d98
Author: Robin Norwood <rnorwood at redhat.com>
Date:   Wed Sep 26 15:08:29 2007 -0400

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

diff-tree 9b8629dac8dfb487fbe8eeab50b09e5267e6292c (from parents)
Merge: 7498ddee21dcffd4066216dcddf9670be9c2ee43 00229dd1868eea15321198bc96f77d7b154ff389
Author: Robin Norwood <rnorwood at redhat.com>
Date:   Wed Sep 26 14:42:43 2007 -0400

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

diff --cc python/packagekit/frontend.py
index 0000000,21bb908..53df0f7
mode 000000,100644..100644
@@@ -1,0 -1,159 +1,223 @@@
 -# PackageKit python interface
++#!/usr/bin/python -tt
++# 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.
+ #
 -# Copyright (C) 2007 Tom Parker <palfrey at tevp.net>
++# This program is distributed in the hope that it will be useful,
++# but WITHOUT ANY WARRANTY; without even the implied warranty of
++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++# GNU Library General Public License for more details.
+ #
 -# Licensed under the GNU General Public License Version 2
++# You should have received a copy of the GNU General Public License
++# along with this program; if not, write to the Free Software
++# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ #
 -# This program is free software; you can redistribute it and/or modify
 -# it under the terms of the GNU General Public License v2 as published by
 -# the Free Software Foundation.
+ 
+ from types import *
+ import dbus
+ from dbus.mainloop.glib import DBusGMainLoop
+ import gobject
+ 
+ class PackageKitException(Exception):
+ 	def __init__(self):
+ 		Exception.__init__(self)
+ 	
+ 	def __init__(self,e=None):
+ 		Exception.__init__(self)
+ 		if e == None:
+ 			self._pk_name = None
+ 			self._full_str = None
+ 		else:
+ 			if not isinstance(e,dbus.exceptions.DBusException):
+ 				raise Exception,"Can only handle DBusExceptions"
+ 			self._pk_name = str(e.get_dbus_name())
+ 			self._full_str = str(e)
+ 	
+ 	def get_backend_name(self):
+ 		return self._pk_name
+ 	
+ 	def __str__(self):
+ 		if self._full_str!=None:
+ 			return self._full_str
+ 		else:
+ 			return ""
+ 
+ class PackageKitNotStarted(PackageKitException):
+ 	pass
+ 
+ class PackageKitAccessDenied(PackageKitException):
+ 	pass
+ 
+ class PackageKitTransactionFailure(PackageKitException):
+ 	pass
+ 
+ class PackageKitBackendFailure(PackageKitException):
+ 	pass
+ 
+ def dbusException(func):
+ 	def wrapper(*args,**kwargs):
+ 		try:
+ 			return func(*args,**kwargs)
+ 		except dbus.exceptions.DBusException,e:
+ 			if e.get_dbus_name() == "org.freedesktop.DBus.Error.AccessDenied":
+ 				raise PackageKitAccessDenied
+ 			elif e.get_dbus_name() == "org.freedesktop.DBus.Error.NoReply":
+ 				raise PackageKitBackendFailure
+ 			else:
+ 				raise PackageKitException(e)
+ 		except Exception:
+ 			print "wibble"
+ 			raise
+ 	return wrapper
+ 
+ 
+ class PackageKit:
+ 	def job_id(func):
+ 		def wrapper(*args,**kwargs):
+ 			jid = func(*args,**kwargs)
+ 			if jid == -1:
+ 				raise PackageKitTransactionFailure
+ 			else:
+ 				return jid
+ 		return wrapper
+ 
 -	def tid(self):
 -		return self.pk_iface.GetTid()
 -
+ 	def __init__(self):
+ 		DBusGMainLoop(set_as_default=True)
+ 		bus = dbus.SystemBus()
+ 		try:
+ 			pk = bus.get_object('org.freedesktop.PackageKit', '/org/freedesktop/PackageKit')
+ 			self.pk_iface = dbus.Interface(pk, dbus_interface='org.freedesktop.PackageKit')
+ 		except dbus.exceptions.DBusException,e:
+ 			if e.get_dbus_name() == "org.freedesktop.DBus.Error.ServiceUnknown":
+ 				raise PackageKitNotStarted
+ 			else:
+ 				raise PackageKitException(e)
+ 
+ 		#self.job = None
+ 		self.progress = 0.0
+ 		bus.add_signal_receiver(self.catchall_signal_handler, interface_keyword='dbus_interface', member_keyword='member',dbus_interface="org.freedesktop.PackageKit")
+ 	
+ 	def run(self):
+ 		self.loop = gobject.MainLoop()
+ 		self.loop.run()
+ 
+ 	def catchall_signal_handler(self,*args, **kwargs):
+ 		#if args[0] != self.job and kwargs['member']!="TransactionListChanged":
+ 		#	print "args",args,kwargs
+ 		#	return
+ 		if kwargs['member'] == "Finished":
+ 			self.loop.quit()
 -			self.Finish()
++			self.Finished(args[0],args[1],args[2])
+ 		elif kwargs['member'] == "PercentageChanged":
+ 			progress = float(args[1])+(progress%1.0)
 -			self.Percentage(progress)
++			self.Percentage(args[0], progress)
+ 		elif kwargs['member'] == "SubPercentageChanged":
+ 			progress = (float(args[1])/100.0)+int(progress)
 -			self.Percentage(progress)
++			self.Percentage(args[0], progress)
+ 		elif kwargs['member'] == "TransactionStatusChanged":
 -			self.JobStatus(args[1])
++			self.JobStatus(args[0], args[1])
+ 		elif kwargs['member'] == "Package":
 -			self.Package(args[2],args[3])
 -		elif kwargs['member'] in ["NoPercentageUpdates","TransactionListChanged"]:
 -			pass
++			self.Package(args[0],args[1],args[2],args[3])
++		elif kwargs['member'] == "UpdateDetail":
++			self.UpdateDetail(args[0],args[1],args[2],args[3],args[4],args[5],args[6])
+ 		elif kwargs['member'] == "Description":
 -			self.Description(args[1],args[3],args[4],args[5])
++			self.Description(args[0],args[1],args[2],args[3],args[4],args[5])
++		elif kwargs['member'] == "ErrorCode":
++			self.ErrorCode(args[0],args[1],args[2])
++		elif kwargs['member'] == "RequireRestart":
++			self.RequireRestart(args[0],args[1],args[2])
++		elif kwargs['member'] in ["NoPercentageUpdates","TransactionListChanged","Transaction",
++					  "AllowInterrupt","JobListChanged"]:
++			pass
+ 		else:
 -			print "Caught signal %s"% kwargs['member']
++			print "Caught unhandled signal %s"% kwargs['member']
++			print "  args:"
+ 			for arg in args:
+ 				print "		" + str(arg)
++
++# --- PK Signal Handlers ---
++
++	def Finished(self,
++		     jid,          # Job ID
++		     status,       # enum - unknown, success, failed, canceled
++		     running_time  # amount of time transaction has been running in seconds
++		     ):
++		pass
+ 	
 -	def Percentage(self,value):
++	def Percentage(self,
++		       jid,        # Job ID
++		       progress    # 0.0 - 100.0
++		       ):
+ 		pass
+ 	
 -	def JobStatus(self,string):
++	def JobStatus(self,
++		      jid,        # Job ID
++		      status      # enum - invalid, setup, download, install, update, exit
++		      ):
+ 		pass
+ 	
 -	def Finish(self):
++	def Package(self,
++		    jid,        # Job ID
++		    value,      # installed=1, not-installed=0 | security=1, normal=0
++		    package_id,
++		    package_summary
++		    ):
+ 		pass
+ 
 -	def Package(self,package_name,package_summary):
++	def UpdateDetail(self,
++			 jid,        # Job ID
++			 package_id,
++			 updates,
++			 obsoletes,
++			 url,
++			 restart_required,
++			 update_text
++			 ):
+ 		pass
+ 
 -	def Description(self,package_name,package_group,package_description,package_url):
++	def Description(self,
++			jid,        # Job ID
++			package_id,
++			license,
++			group,
++			detail,
++			url
++			):
++		pass
++
++	def ErrorCode(self,
++		      jid,        # Job ID
++		      error_code, # enumerated - see pk-enum.c in PackageKit source
++		      details     # non-localized details
++		      ):
+ 		pass
+ 	
++	def RequireRestart(self,
++			   jid,        # Job ID
++			   type,       # enum - system,application,session
++			   details     # non-localized details
++			   ):
++		pass
++
++
++# --- PK Methods ---
++	
+ 	@dbusException
+ 	@job_id
+ 	def SearchName(self,pattern,filter="none"):
 -		return self.pk_iface.SearchName(self.tid(),filter,pattern)
++		return self.pk_iface.SearchName(filter,pattern)
+ 
+ 	@dbusException
+ 	@job_id
+ 	def GetDescription(self,package_id):
 -		return self.pk_iface.GetDescription(self.tid(),package_id)
++		return self.pk_iface.GetDescription(package_id)
+ 
+ 	@dbusException
+ 	@job_id
+ 	def RefreshCache(self,force=False):
 -		return self.pk_iface.RefreshCache(self.tid(),force)
++		return self.pk_iface.RefreshCache(force)
+ 
+ # hack to avoid exporting them
+ del dbusException
++
diff --cc python/pk-frontend-test.py
index 0000000,358b48d..6004686
mode 000000,100755..100755
@@@ -1,0 -1,86 +1,86 @@@
+ #!/usr/bin/python
+ #
+ # "pkt" python test program for PackageKit
+ #
+ # pkt serves both as a simple PackageKit client, and as an example user of the
+ # PackageKit python API
+ #
+ # Copyright (C) 2007 Tom Parker <palfrey at tevp.net>
+ #
+ # 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 v2 as published by
+ # the Free Software Foundation.
+ 
+ from sys import argv,exit
+ from optparse import OptionParser
+ from types import FunctionType
+ 
+ from packagekit.frontend import *
+ 
+ class pkt(PackageKit):
 -	def Percentage(self,progress):
++	def Percentage(self,jid,progress):
+ 		print "Progress: %.2f%%"%progress
+ 	
 -	def JobStatus(self,type):
++	def JobStatus(self,jid,type):
+ 		print "Job type: %s"%type
+ 	
 -	def Package(self,name,description):
 -		print "Package: %s - %s"%(name,description)
++	def Package(self,jid,value,name,summary):
++		print "Package: %s - %s"%(name,summary)
+ 
+ try:
+ 	p = pkt()
+ except PackageKitNotStarted:
+ 	print "PackageKit doesn't appear to be started. You may need to enable dbus autostart"
+ 	exit(1)
+ 
+ def search(*args):
+ 	patt = " ".join(args[0])
+ 	if len(patt)==0:
+ 		print "need something to search for"
+ 		raise PackageKitTransactionFailure
+ 	return p.SearchName(patt)
+ 
+ def desc(*args):
+ 	if len(args)!=1 or len(args[0])!=1:
+ 		print "desc only takes single arg"
+ 		raise PackageKitTransactionFailure
+ 	return p.GetDescription(args[0][0])
+ 
+ def update(args):
+ 	if len(args)>0 and len(args[0])>0:
+ 		print "update doesn't take args"
+ 		raise PackageKitTransactionFailure
+ 	return p.RefreshCache()
+ 
+ def usage():
+ 	print "Usage: %s <command> <options>"%argv[0]
+ 	print "Valid commands are:"
+ 	for k in globals().keys():
+ 		if k in ["usage","catchall_signal_handler"]: #ignore
+ 			continue
+ 		g = globals()[k]
+ 		if type(g) == FunctionType:
+ 			print "\t%s"%k
+ 	exit(1)
+ 
+ parser = OptionParser()
+ (options, args) = parser.parse_args()
+ 
+ if len(args)==0:
+ 	usage()
+ 
+ if not globals().has_key(args[0]):
+ 	print "Don't know operation '%s'"%args[0]
+ 	usage()
+ 
+ try:
+ 	job = globals()[args[0]](args[1:])
+ except PackageKitAccessDenied:
+ 	print "You don't have sufficient permissions to access PackageKit (on the org.freedesktop.PackageKit dbus service)"
+ 	exit(1)
+ except PackageKitTransactionFailure:
+ 	usage()
+ 
+ p.run()
diff-tree 7498ddee21dcffd4066216dcddf9670be9c2ee43 (from a6cf9cb051d9e8f3ff6c32b6818087627b989ec8)
Author: Robin Norwood <rnorwood at redhat.com>
Date:   Wed Sep 26 14:07:55 2007 -0400

    Add new signal handlers, include and at least name all arguments to template signal handlers.

diff --git a/python/packagekit/__init__.py b/python/packagekit/__init__.py
index 6c71eb7..dde4e0e 100644
--- a/python/packagekit/__init__.py
+++ b/python/packagekit/__init__.py
@@ -102,40 +102,100 @@ class PackageKit:
 		#	return
 		if kwargs['member'] == "Finished":
 			self.loop.quit()
-			self.Finish()
+			self.Finished(args[0],args[1],args[2])
 		elif kwargs['member'] == "PercentageChanged":
 			progress = float(args[1])+(progress%1.0)
-			self.Percentage(progress)
+			self.Percentage(args[0], progress)
 		elif kwargs['member'] == "SubPercentageChanged":
 			progress = (float(args[1])/100.0)+int(progress)
-			self.Percentage(progress)
+			self.Percentage(args[0], progress)
 		elif kwargs['member'] == "TransactionStatusChanged":
-			self.JobStatus(args[1])
+			self.JobStatus(args[0], args[1])
 		elif kwargs['member'] == "Package":
-			self.Package(args[2],args[3])
-		elif kwargs['member'] in ["NoPercentageUpdates","TransactionListChanged"]:
-			pass
+			self.Package(args[0],args[1],args[2],args[3])
+		elif kwargs['member'] == "UpdateDetail":
+			self.UpdateDetail(args[0],args[1],args[2],args[3],args[4],args[5],args[6])
 		elif kwargs['member'] == "Description":
-			self.Description(args[1],args[3],args[4],args[5])
+			self.Description(args[0],args[1],args[2],args[3],args[4],args[5])
+		elif kwargs['member'] == "ErrorCode":
+			self.ErrorCode(args[0],args[1],args[2])
+		elif kwargs['member'] == "RequireRestart":
+			self.RequireRestart(args[0],args[1],args[2])
+		elif kwargs['member'] in ["NoPercentageUpdates","TransactionListChanged","Transaction",
+					  "AllowInterrupt","JobListChanged"]:
+			pass
 		else:
-			print "Caught signal %s"% kwargs['member']
+			print "Caught unhandled signal %s"% kwargs['member']
+			print "  args:"
 			for arg in args:
 				print "		" + str(arg)
+
+# --- PK Signal Handlers ---
+
+	def Finished(self,
+		     jid,          # Job ID
+		     status,       # enum - unknown, success, failed, canceled
+		     running_time  # amount of time transaction has been running in seconds
+		     ):
+		pass
 	
-	def Percentage(self,value):
+	def Percentage(self,
+		       jid,        # Job ID
+		       progress    # 0.0 - 100.0
+		       ):
 		pass
 	
-	def JobStatus(self,string):
+	def JobStatus(self,
+		      jid,        # Job ID
+		      status      # enum - invalid, setup, download, install, update, exit
+		      ):
 		pass
 	
-	def Finish(self):
+	def Package(self,
+		    jid,        # Job ID
+		    value,      # installed=1, not-installed=0 | security=1, normal=0
+		    package_id,
+		    package_summary
+		    ):
+		pass
+
+	def UpdateDetail(self,
+			 jid,        # Job ID
+			 package_id,
+			 updates,
+			 obsoletes,
+			 url,
+			 restart_required,
+			 update_text
+			 ):
 		pass
 
-	def Package(self,package_name,package_summary):
+	def Description(self,
+			jid,        # Job ID
+			package_id,
+			license,
+			group,
+			detail,
+			url
+			):
 		pass
 
-	def Description(self,package_name,package_group,package_description,package_url):
+	def ErrorCode(self,
+		      jid,        # Job ID
+		      error_code, # enumerated - see pk-enum.c in PackageKit source
+		      details     # non-localized details
+		      ):
+		pass
+	
+	def RequireRestart(self,
+			   jid,        # Job ID
+			   type,       # enum - system,application,session
+			   details     # non-localized details
+			   ):
 		pass
+
+
+# --- PK Methods ---
 	
 	@dbusException
 	@job_id
@@ -152,6 +212,7 @@ class PackageKit:
 	def RefreshCache(self,force=False):
 		return self.pk_iface.RefreshCache(force)
 
+
 # hack to avoid exporting them
 #del job_id
 del dbusException
diff --git a/python/pkt b/python/pkt
index ab8b71b..d9848db 100755
--- a/python/pkt
+++ b/python/pkt
@@ -20,14 +20,14 @@ from types import FunctionType
 from packagekit import *
 
 class pkt(PackageKit):
-	def Percentage(self,progress):
+	def Percentage(self,jid,progress):
 		print "Progress: %.2f%%"%progress
 	
-	def JobStatus(self,type):
+	def JobStatus(self,jid,type):
 		print "Job type: %s"%type
 	
-	def Package(self,name,description):
-		print "Package: %s - %s"%(name,description)
+	def Package(self,jid,value,name,summary):
+		print "Package: %s - %s"%(name,summary)
 
 try:
 	p = pkt()



More information about the PackageKit mailing list