From 78ffa14d2ed1e724409cb6afc34d7ec5d999fe0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCrer=20=C3=96zen?= Date: Sun, 12 Nov 2006 14:34:45 +0000 Subject: [PATCH] =?UTF-8?q?fazlal=C4=B1k=20fonksiyonu=20att=C4=B1m,=20bira?= =?UTF-8?q?z=20temizlik=20ve=20a=C3=A7=C4=B1klamalar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pisi/api.py | 2 +- pisi/atomicoperations.py | 2 +- pisi/comariface.py | 62 ++++++++++++++++++---------------------- 3 files changed, 30 insertions(+), 36 deletions(-) diff --git a/pisi/api.py b/pisi/api.py index 55afaad5..30b71ce5 100644 --- a/pisi/api.py +++ b/pisi/api.py @@ -95,7 +95,7 @@ def init(database = True, write = True, # TODO: this is definitely not dynamic beyond this point! ctx.comar = comar and not ctx.config.get_option('ignore_comar') - # This is for YALI, used in comariface.py:make_com() + # This is for YALI, used in comariface.py ctx.comar_sockname = comar_sockname # initialize repository databases diff --git a/pisi/atomicoperations.py b/pisi/atomicoperations.py index 929369f7..86707ca7 100644 --- a/pisi/atomicoperations.py +++ b/pisi/atomicoperations.py @@ -137,7 +137,7 @@ class Install(AtomicOperation): # check comar if self.metadata.package.providesComar and ctx.comar: import pisi.comariface as comariface - com = comariface.make_com() + com = comariface.get_comar() def check_relations(self): # check dependencies diff --git a/pisi/comariface.py b/pisi/comariface.py index aafab7ac..1f53d2e8 100644 --- a/pisi/comariface.py +++ b/pisi/comariface.py @@ -29,12 +29,19 @@ try: except ImportError: raise Error(_("comar package is not fully installed")) -def make_com(): +def get_comar(): + """Connect to the comar daemon and return the handle""" + sockname = "/var/run/comar.socket" - # This is used by YALI + # YALI starts comar chrooted in the install target, but uses PiSi outside of + # the chroot environment, so PiSi needs to use a different socket path to be + # able to connect true comar (usually /mnt/target/var/run/comar.socket). if ctx.comar_sockname: sockname = ctx.comar_sockname + # This function is sometimes called when comar has recently started + # or restarting after an update. So we give comar a chance to become + # active in a reasonable time. timeout = 7 while timeout > 0: try: @@ -46,26 +53,9 @@ def make_com(): timeout -= 0.2 raise Error(_("cannot connect to comar")) -def wait_comar(): - # FIXME: this function is redundant, use make_com in wait_for_result - import socket - sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) - timeout = 5 - sockname = "/var/run/comar.socket" - if ctx.comar_sockname: - sockname = ctx.comar_sockname - while timeout > 0: - try: - sock.connect(sockname) - return True - except socket.error: - timeout -= 0.2 - time.sleep(0.2) - return False - def wait_for_result(com, package_name=None): multiple = False - while 1: + while True: try: reply = com.read_cmd() except select.error: @@ -76,14 +66,16 @@ def wait_for_result(com, package_name=None): # Comar postInstall does a "service comar restart" which cuts # our precious communication link, so we waitsss if package_name == "comar": - if not wait_comar(): + try: + get_comar() + except Error: raise Error, _("Could not restart comar") return else: if ctx.keyboard_interrupt_pending(): return raise Error, _("connection with comar unexpectedly closed") - + cmd = reply[0] if cmd == com.RESULT and not multiple: return @@ -95,47 +87,49 @@ def wait_for_result(com, package_name=None): elif cmd == com.RESULT_END: return elif cmd == com.FAIL: - e = _("Configuration error: %s") % reply[2] - raise Error, e + raise Error, _("Configuration error: %s") % reply[2] elif cmd == com.ERROR: - e = _("Script error: %s") % reply[2] - raise Error, e + raise Error, _("Script error: %s") % reply[2] elif cmd == com.DENIED: raise Error, _("comar denied our access") def post_install(package_name, provided_scripts, scriptpath, metapath, filepath): + """Do package's post install operations""" + ctx.ui.info(_("Configuring %s package") % package_name) self_post = False - com = make_com() - + com = get_comar() + for script in provided_scripts: ctx.ui.debug(_("Registering %s comar script") % script.om) if script.om == "System.Package": self_post = True com.register(script.om, package_name, os.path.join(scriptpath, script.script)) wait_for_result(com) - + ctx.ui.debug(_("Calling post install handlers")) com.call("System.PackageHandler.setupPackage", [ "metapath", metapath, "filepath", filepath ]) wait_for_result(com) - + if self_post: ctx.ui.debug(_("Running package's post install script")) com.call_package("System.Package.postInstall", package_name) wait_for_result(com, package_name) def pre_remove(package_name, metapath, filepath): + """Do package's pre removal operations""" + ctx.ui.info(_("Configuring %s package for removal") % package_name) - com = make_com() - + com = get_comar() + ctx.ui.debug(_("Running package's pre remove script")) com.call_package("System.Package.preRemove", package_name) wait_for_result(com) - + ctx.ui.debug(_("Calling pre remove handlers")) com.call("System.PackageHandler.cleanupPackage", [ "metapath", metapath, "filepath", filepath ]) wait_for_result(com) - + ctx.ui.debug(_("Unregistering comar scripts")) com.remove(package_name) wait_for_result(com)