fazlalık fonksiyonu attım, biraz temizlik ve açıklamalar

This commit is contained in:
Gürer Özen
2006-11-12 14:34:45 +00:00
parent df7cde7788
commit 78ffa14d2e
3 changed files with 30 additions and 36 deletions
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
+28 -34
View File
@@ -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)