Merged COMAR patch. PiSi now has a cleaner comar interface module.

This commit is contained in:
Bahadır Kandemir
2009-03-24 08:33:24 +00:00
parent da90f3b579
commit 91f32cf4d7
7 changed files with 94 additions and 350 deletions
+3
View File
@@ -1,3 +1,6 @@
2009-03-24 Bahadır Kandemir <bahadir@pardus.org.tr>
* Merged COMAR patch. PiSi now has a cleaner comar interface module.
2009-03-11 Ozan Çağlayan <ozan@pardus.org.tr>
* pisi/actionsapi/pisitools.py: Implement new method removeLaFiles()
to recursively delete libtool *la files from /usr/lib.
+2 -3
View File
@@ -5,9 +5,8 @@ You can install PiSi on your system with a single command.
If you are on a Pardus system, you should delete /usr/lib/pardus/pisi
when you are installing the SVN version
PiSi requires piksemel XML processing library, the newest version
bsd bindings called "bsddb3" and Pardus configuration manager COMAR
in order to run.
PiSi requires piksemel XML processing library, Pardus configuration
manager COMAR and COMAR API in order to run.
If you are upgrading from an old PiSi release you may have to
run the following command as root:
-291
View File
@@ -1,291 +0,0 @@
Index: pisi/comariface.py
===================================================================
--- pisi/comariface.py (revision 21915)
+++ 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 21915)
+++ 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):
"""
Index: pisi/atomicoperations.py
===================================================================
--- pisi/atomicoperations.py (revision 21915)
+++ 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 21915)
+++ 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
+4 -4
View File
@@ -97,12 +97,12 @@ def set_comar(enable):
"""
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):
"""
+12 -1
View File
@@ -165,7 +165,7 @@ class Install(AtomicOperation):
# 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 @@ class Remove(AtomicOperation):
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 @@ class Remove(AtomicOperation):
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")
+72 -50
View File
@@ -26,16 +26,23 @@ class Error(pisi.Error):
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 @@ def make_object_path(package):
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 @@ def get_iface(package="", model=""):
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 @@ def get_iface(package="", model=""):
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,8 +92,14 @@ def post_install(package_name, provided_scripts, scriptpath, metapath, filepath,
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)
package_name = safe_package_name(package_name)
if package_name == 'comar':
ctx.ui.debug(_("COMAR package updated. From now on, using new COMAR daemon."))
pisi.api.set_comar_updated(True)
link = get_link()
for script in provided_scripts:
ctx.ui.debug(_("Registering %s comar script") % script.om)
@@ -101,25 +108,22 @@ def post_install(package_name, provided_scripts, scriptpath, metapath, filepath,
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 +134,66 @@ def post_install(package_name, provided_scripts, scriptpath, metapath, filepath,
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')
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
+1 -1
View File
@@ -38,7 +38,7 @@ stdout = None
stderr = None
comar = True
comar_destination = "tr.org.pardus.comar"
comar_updated = False
dbus_sockname = None
dbus_timeout = 300