From 9c21f0d4370b81354936acb1bf7784193f447815 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eray=20=C3=96zkural?= Date: Sun, 9 Oct 2005 23:18:07 +0000 Subject: [PATCH] * fix: make join_path smarter (now it's really better than os.path.xx) * fix: #507 call comar dynamically. wow. --- pisi/api.py | 12 ++---------- pisi/comariface.py | 33 +++++++++++++++++++++++++++++---- pisi/install.py | 17 ++++------------- pisi/util.py | 1 + 4 files changed, 36 insertions(+), 27 deletions(-) diff --git a/pisi/api.py b/pisi/api.py index 5d3a8b95..647d6f9c 100644 --- a/pisi/api.py +++ b/pisi/api.py @@ -46,16 +46,8 @@ def init(database = True, options = None, ui = None, comar = True): import pisi.config ctx.config = pisi.config.Config(options) - if comar and not ctx.config.get_option('ignore_comar'): - # FIXME: just try for others (that don't use comar) - try: - import comar - ctx.comard = comar.Link() - except ImportError: - raise Error(_("COMAR: comard not fully installed")) - #print _("skipping COMAR connection for now...") - except comar.Error: - raise Error(_("COMAR: comard not running or defunct")) + # TODO: this is definitely not dynamic beyond this point! + ctx.comar = comar and not ctx.config.get_option('ignore_comar') if ui is None: if options: diff --git a/pisi/comariface.py b/pisi/comariface.py index 8d18080c..3eb2e338 100644 --- a/pisi/comariface.py +++ b/pisi/comariface.py @@ -24,10 +24,35 @@ import pisi.context as ctx class Error(pisi.Error): pass +def make_com(): + # FIXME: just try for others (that don't use comar) + try: + import comar + comard = comar.Link() + return comard + except ImportError: + raise Error(_("COMAR: comard not fully installed")) + except comar.Error: + raise Error(_("COMAR: comard not running or defunct")) + +def register(pcomar, name, path): + ctx.ui.info(_("Registering COMAR script %s") % pcomar.script) + com = make_com() + assert(com) + com.register(pcomar.om, name, path) + + while 1: + reply = com.read_cmd() + if reply[0] == com.RESULT: + break + else: + raise Error, _("COMAR.register ERROR!") + + def run_postinstall(package_name): "run postinstall scripts trough COMAR" - com = ctx.comard + com = make_com() assert(com) ctx.ui.info(_("Running post-install script for %s") % package_name) com.call_package("System.Package.postInstall", package_name) @@ -45,7 +70,8 @@ def run_postinstall(package_name): raise Error, _("COMAR.call_package ERROR: %d") % reply[0] def run_preremove(package_name): - com = ctx.comard + + com = make_com() assert(com) # First, call preRemove script! @@ -64,7 +90,7 @@ def run_preremove(package_name): else: raise Error, _("COMAR.call_package ERROR: %d") % reply[0] - # and than, remove package's Comar Scripts... + # and then, remove package's Comar Scripts... ctx.ui.info(_("Unregistering COMAR scripts for %s") % package_name) com.remove(package_name) while 1: @@ -73,4 +99,3 @@ def run_preremove(package_name): break elif reply[1] == com.ERROR: raise Error, "COMAR.remove failed!" - diff --git a/pisi/install.py b/pisi/install.py index cf11d603..710300e6 100644 --- a/pisi/install.py +++ b/pisi/install.py @@ -63,7 +63,7 @@ class Installer: self.check_reinstall() self.extract_install() self.store_pisi_files() - if ctx.comard: + if ctx.comar: self.register_comar_scripts() import pisi.comariface as comariface comariface.run_postinstall(self.pkginfo.name) @@ -190,18 +190,9 @@ class Installer: for pcomar in self.metadata.package.providesComar: scriptPath = os.path.join(self.package.comar_dir(),pcomar.script) - ctx.ui.info(_("Registering COMAR script %s") % pcomar.script) - - com.register(pcomar.om, - self.metadata.package.name, - scriptPath) - while 1: - reply = com.read_cmd() - if reply[0] == com.RESULT: - break - else: - raise Error, _("COMAR.register ERROR!") - + import pisi.comariface + pisi.comariface.register(pcomar, self.metadata.package.name, + scriptPath) def update_databases(self): "update databases" diff --git a/pisi/util.py b/pisi/util.py index d4dc9410..88300d43 100644 --- a/pisi/util.py +++ b/pisi/util.py @@ -196,6 +196,7 @@ def join_path(a, *p): """The python original version has a silly logic""" path = a for b in p: + b = b.lstrip('/') if path == '' or path.endswith('/'): path += b else: