From 7d296516ba5253a6963ca3fa0d1098e4699b6e4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bahad=C4=B1r=20Kandemir?= Date: Fri, 20 Feb 2009 12:17:59 +0000 Subject: [PATCH] New COMAR patch, not final --- comar.patch | 305 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 305 insertions(+) create mode 100644 comar.patch diff --git a/comar.patch b/comar.patch new file mode 100644 index 00000000..b0c077a6 --- /dev/null +++ b/comar.patch @@ -0,0 +1,305 @@ +Index: pisi/comariface.py +=================================================================== +--- pisi/comariface.py (revision 21595) ++++ pisi/comariface.py (working copy) +@@ -26,16 +26,23 @@ + pass + + try: ++ import comar + import dbus + except ImportError: +- raise Error(_("dbus-python package is not fully installed")) ++ raise Error(_("comar-api package is not fully installed")) + + def is_char_valid(char): + """Test if char is valid object path character.""" + return char in string.ascii_letters + string.digits + "_" + +-def make_object_path(package): +- """Generates DBus object name from package name.""" ++def is_method_missing(exception): ++ """Tells if exception is about missing method in COMAR script""" ++ if exception._dbus_error_name in ("tr.org.pardus.comar.python.missing", "tr.org.pardus.comar.Missing"): ++ return True ++ return False ++ ++def safe_package_name(package): ++ """Generates DBus-safe object name for package name.""" + object = package + for char in package: + if not is_char_valid(char): +@@ -44,8 +51,8 @@ + object = '_%s' % object + return object + +-def get_iface(package="", model=""): +- """Connect to the DBus daemon and return the system interface.""" ++def get_link(): ++ """Connect to the COMAR daemon and return the link.""" + + sockname = "/var/run/dbus/system_bus_socket" + # YALI starts comar chrooted in the install target, but uses PiSi outside of +@@ -55,14 +62,12 @@ + if ctx.dbus_sockname: + sockname = ctx.dbus_sockname + +- if package: +- obj_path = "/package/%s" % package +- else: +- obj_path = "/" +- if model: +- obj_interface = "tr.org.pardus.comar.%s" % model +- else: +- obj_interface = "tr.org.pardus.comar" ++ alternate = False ++ # If COMAR package is updated, all new configuration requests should be ++ # made through new COMAR service. Passing alternate=True to Link() class ++ # will ensure this. ++ if ctx.comar_updated: ++ alternate = True + + # This function is sometimes called when comar has recently started + # or restarting after an update. So we give comar a chance to become +@@ -71,19 +76,15 @@ + exceptions = [] + while timeout > 0: + try: +- bus = dbus.bus.BusConnection(address_or_type="unix:path=%s" % sockname) +- obj = bus.get_object(ctx.comar_destination, obj_path, introspect=False) +- iface = dbus.Interface(obj, dbus_interface=obj_interface) +- return iface ++ link = comar.Link(socket=sockname, alternate=alternate) ++ return link + except dbus.DBusException, e: + exceptions.append(str(e)) +- pass + except Exception, e: + exceptions.append(str(e)) +- pass + time.sleep(0.2) + timeout -= 0.2 +- raise Error(_("cannot connect to dbus: \n %s\n") % "\n ".join(exceptions)) ++ raise Error(_("Cannot connect to COMAR: \n %s\n") % "\n ".join(exceptions)) + + def post_install(package_name, provided_scripts, scriptpath, metapath, filepath, fromVersion, fromRelease, toVersion, toRelease): + """Do package's post install operations""" +@@ -91,9 +92,10 @@ + ctx.ui.info(_("Configuring %s package") % package_name) + self_post = False + sys_service = False +- sys_iface = get_iface() +- object_name = make_object_path(package_name) ++ link = get_link() + ++ package_name = safe_package_name(package_name) ++ + for script in provided_scripts: + ctx.ui.debug(_("Registering %s comar script") % script.om) + if script.om == "System.Package": +@@ -101,25 +103,22 @@ + elif script.om == "System.Service": + sys_service = True + try: +- sys_iface.register(object_name, script.om, os.path.join(scriptpath, script.script), timeout=ctx.dbus_timeout) ++ link.register(package_name, script.om, os.path.join(scriptpath, script.script)) + except dbus.DBusException, exception: + raise Error, _("Script error: %s") % exception + if sys_service: + try: +- iface = get_iface(object_name, "System.Service") +- iface.registerState(timeout=ctx.dbus_timeout) ++ link.System.Service[package_name].registerState() + except dbus.DBusException, exception: + raise Error, _("Script error: %s") % exception + + ctx.ui.debug(_("Calling post install handlers")) +- for handler in sys_iface.listModelApplications("System.PackageHandler", timeout=ctx.dbus_timeout): +- iface = get_iface(handler, "System.PackageHandler") ++ for handler in link.System.PackageHandler: + try: +- iface.setupPackage(metapath, filepath, timeout=ctx.dbus_timeout) ++ link.System.PackageHandler[handler].setupPackage(metapath, filepath) + except dbus.DBusException, exception: + # Do nothing if setupPackage method is not defined in package script +- if not (exception._dbus_error_name.startswith("tr.org.pardus.comar") and +- exception._dbus_error_name.split('tr.org.pardus.comar.')[1] == 'python.missing'): ++ if not is_method_missing(exception): + raise Error, _("Script error: %s") % exception + + if self_post: +@@ -130,48 +129,70 @@ + + ctx.ui.debug(_("Running package's post install script")) + try: +- iface = get_iface(object_name, "System.Package") +- iface.postInstall(fromVersion, fromRelease, toVersion, toRelease, timeout=ctx.dbus_timeout) ++ link.System.Package[package_name].postInstall(fromVersion, fromRelease, toVersion, toRelease, timeout=ctx.dbus_timeout) + except dbus.DBusException, exception: + # Do nothing if postInstall method is not defined in package script +- if not (exception._dbus_error_name.startswith("tr.org.pardus.comar") and +- exception._dbus_error_name.split('tr.org.pardus.comar.')[1] == 'python.missing'): ++ if not is_method_missing(exception): + raise Error, _("Script error: %s") % exception + + if package_name == 'comar': +- pisi.api.set_comar_destination('tr.org.pardus.comar2') ++ ctx.ui.debug(_("COMAR package updated. From now on, using new COMAR daemon.")) ++ pisi.api.set_comar_updated(True) + + def pre_remove(package_name, metapath, filepath): + """Do package's pre removal operations""" + + ctx.ui.info(_("Configuring %s package for removal") % package_name) +- sys_iface = get_iface() +- object_name = make_object_path(package_name) ++ link = get_link() + +- if "System.Package" in sys_iface.listApplicationModels(object_name, timeout=ctx.dbus_timeout): ++ package_name = safe_package_name(package_name) ++ ++ if package_name in list(link.System.Package): + ctx.ui.debug(_("Running package's pre remove script")) +- iface = get_iface(object_name, "System.Package") + try: +- iface.preRemove(timeout=ctx.dbus_timeout) ++ link.System.Package[package_name].preRemove(timeout=ctx.dbus_timeout) + except dbus.DBusException, exception: + # Do nothing if preRemove method is not defined in package script +- if not (exception._dbus_error_name.startswith("tr.org.pardus.comar") and +- exception._dbus_error_name.split('tr.org.pardus.comar.')[1] == 'python.missing'): ++ if not is_method_missing(exception): + raise Error, _("Script error: %s") % exception + + ctx.ui.debug(_("Calling pre remove handlers")) +- for handler in sys_iface.listModelApplications("System.PackageHandler"): +- iface = get_iface(handler, "System.PackageHandler") ++ for handler in list(link.System.PackageHandler): + try: +- iface.cleanupPackage(metapath, filepath, timeout=ctx.dbus_timeout) ++ link.System.PackageHandler[handler].cleanupPackage(metapath, filepath, timeout=ctx.dbus_timeout) + except dbus.DBusException, exception: + # Do nothing if cleanupPackage method is not defined in package script +- if not (exception._dbus_error_name.startswith("tr.org.pardus.comar") and +- exception._dbus_error_name.split('tr.org.pardus.comar.')[1] == 'python.missing'): ++ if not is_method_missing(exception): + raise Error, _("Script error: %s") % exception ++ ++def post_remove(package_name, metapath, filepath): ++ """Do package's post removal operations""" + ++ ctx.ui.info(_("Configuring %s package for removal") % package_name) ++ link = get_link() ++ ++ package_name = safe_package_name(package_name) ++ ++ if package_name in list(link.System.Package): ++ ctx.ui.debug(_("Running package's postremove script")) ++ try: ++ link.System.Package[package_name].postRemove(timeout=ctx.dbus_timeout) ++ except dbus.DBusException, exception: ++ # Do nothing if postRemove method is not defined in package script ++ if not is_method_missing(exception): ++ raise Error, _("Script error: %s") % exception ++ ++ ctx.ui.debug(_("Calling post remove handlers")) ++ for handler in list(link.System.PackageHandler): ++ try: ++ link.System.PackageHandler[handler].postCleanupPackage(metapath, filepath, timeout=ctx.dbus_timeout) ++ except dbus.DBusException, exception: ++ # Do nothing if postCleanupPackage method is not defined in package script ++ if not is_method_missing(exception): ++ raise Error, _("Script error: %s") % exception ++ + ctx.ui.debug(_("Unregistering comar scripts")) + try: +- sys_iface.remove(object_name, timeout=ctx.dbus_timeout) ++ link.remove(package_name, timeout=ctx.dbus_timeout) + except dbus.DBusException, exception: + raise Error, _("Script error: %s") % exception +Index: pisi/api.py +=================================================================== +--- pisi/api.py (revision 21595) ++++ pisi/api.py (working copy) +@@ -97,12 +97,12 @@ + """ + ctx.comar = enable + +-def set_comar_destination(destination): ++def set_comar_updated(updated): + """ +- Set comar bus destination +- @param destination: Path to bus destination of COMAR ++ Set comar package update status ++ @param updated: True if COMAR package is updated, else False + """ +- ctx.comar_destination = destination ++ ctx.comar_updated = updated + + def set_dbus_sockname(sockname): + """ +@@ -524,11 +524,12 @@ + def configure_pending(packages=None): + # start with pending packages + # configure them in reverse topological order of dependency +- installdb = pisi.db.installdb.InstallDB() + + # Import COMAR + import pisi.comariface + ++ installdb = pisi.db.installdb.InstallDB() ++ + if not packages: + packages = installdb.list_pending() + else: +Index: pisi/atomicoperations.py +=================================================================== +--- pisi/atomicoperations.py (revision 21595) ++++ pisi/atomicoperations.py (working copy) +@@ -165,7 +165,7 @@ + # check comar + if self.metadata.package.providesComar and ctx.comar: + import pisi.comariface as comariface +- comariface.get_iface() ++ comariface.get_link() + + def check_versioning(self, version): + if not pisi.version.Version.valid(version): +@@ -492,6 +492,8 @@ + for fileinfo in self.files.list: + self.remove_file(fileinfo, self.package_name, True) + ++ self.run_postremove() ++ + self.update_databases() + + self.remove_pisi_files() +@@ -568,6 +570,15 @@ + os.path.join(self.package.pkg_dir(), ctx.const.files_xml), + ) + ++ def run_postremove(self): ++ if ctx.comar: ++ import pisi.comariface ++ pisi.comariface.post_remove( ++ self.package_name, ++ os.path.join(self.package.pkg_dir(), ctx.const.metadata_xml), ++ os.path.join(self.package.pkg_dir(), ctx.const.files_xml), ++ ) ++ + def update_databases(self): + self.remove_db() + self.historydb.add_and_update(pkgBefore=self.package, operation="remove") +Index: pisi/context.py +=================================================================== +--- pisi/context.py (revision 21595) ++++ pisi/context.py (working copy) +@@ -38,7 +38,7 @@ + stderr = None + + comar = True +-comar_destination = "tr.org.pardus.comar" ++comar_updated = False + dbus_sockname = None + dbus_timeout = 300 +