From f170549687222d8a6c281a253a2ea6bcb7feea9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eray=20=C3=96zkural?= Date: Tue, 9 May 2006 14:11:35 +0000 Subject: [PATCH] * fix: make list-upgradable command work. use the routine in operations, and also fix is_upgradable as Caglar suggests * fix: add an option --ignore-script-errors to continue in case of postinstall/preremove errors, also arrange options in order of importance * implement automatic rebuild-db using os.system, couldn't do it with pisi.api yet * fix: show help when command syntax broken, ctx.ui.info can't be used there, somehow --- pisi-cli | 5 ++++- pisi/api.py | 16 +--------------- pisi/atomicoperations.py | 16 ++++++++++++++-- pisi/cli/commands.py | 27 +++++++++++++++++---------- pisi/operations.py | 32 ++++++++++++++++++++++++-------- 5 files changed, 60 insertions(+), 36 deletions(-) diff --git a/pisi-cli b/pisi-cli index 1bdd8c2e..d804a401 100755 --- a/pisi-cli +++ b/pisi-cli @@ -80,4 +80,7 @@ if __name__ == "__main__": locale.setlocale(locale.LC_ALL, '') cli = PisiCLI() - cli.run_command() + try: + cli.run_command() + except pisi.operations.PisiUpgradeException, e: + print 'PISI has been upgraded' diff --git a/pisi/api.py b/pisi/api.py index 0d37b7c5..67df1611 100644 --- a/pisi/api.py +++ b/pisi/api.py @@ -154,21 +154,7 @@ def list_available(repo = None): def list_upgradable(): ignore_build = ctx.get_option('ignore_build_no') - A = ctx.installdb.list_installed() - - # filter packages that are not upgradable - Ap = [] - for x in A: - (version, release, build) = ctx.installdb.get_version(x) - pkg = ctx.packagedb.get_package(x) - if ignore_build or (not build) or (not pkg.build): - if Version(release) < Version(pkg.release): - Ap.append(x) - elif build < pkg.build: - Ap.append(x) - else: - pass - return Ap + return filter(pisi.operations.is_upgradable, ctx.installdb.list_installed()) def package_graph(A, ignore_installed = False): """Construct a package relations graph, containing diff --git a/pisi/atomicoperations.py b/pisi/atomicoperations.py index 872d2486..998bbd12 100644 --- a/pisi/atomicoperations.py +++ b/pisi/atomicoperations.py @@ -242,7 +242,13 @@ class Install(AtomicOperation): if ctx.comar: import pisi.comariface as comariface ctx.ui.notify(pisi.ui.configuring, package = self.pkginfo, files = self.files) - comariface.run_postinstall(self.pkginfo.name) + try: + comariface.run_postinstall(self.pkginfo.name) + except Exception, e: + if ctx.get_option('ignore_script_errors'): + ctx.ui.warning(_('Ignoring script error: ' + unicode(e))) + else: + raise e ctx.ui.notify(pisi.ui.configured, package = self.pkginfo, files = self.files) else: self.config_later = True @@ -432,7 +438,13 @@ class Remove(AtomicOperation): def run_preremove(self): if ctx.comar and self.package.providesComar: import pisi.comariface as comariface - comariface.run_preremove(self.package_name) + try: + comariface.run_preremove(self.package_name) + except Exception, e: + if ctx.get_option('ignore_script_errors'): + ctx.ui.warning(_('Ignoring script error: ' + unicode(e))) + else: + raise e else: # TODO: store this somewhere pass diff --git a/pisi/cli/commands.py b/pisi/cli/commands.py index daa374b6..95bf6a52 100644 --- a/pisi/cli/commands.py +++ b/pisi/cli/commands.py @@ -161,10 +161,10 @@ class Command(object): def help(self): """print help for the command""" - ctx.ui.info(self.format_name() + ': ') + print self.format_name() + ': ' trans = gettext.translation('pisi', fallback=True) - ctx.ui.info(trans.ugettext(self.__doc__) + '\n') - ctx.ui.info(self.parser.format_option_help()) + print trans.ugettext(self.__doc__) + '\n' + print self.parser.format_option_help() def die(self): """exit program""" @@ -357,19 +357,19 @@ unpack, setup, build, install, package # help=_("perform only specified step")) self.parser.add_option("-U", "--until", action="store", default=None, help=_("perform until and including specified step")) - self.parser.add_option("-C", "--compression-method", action="store", default='lzma', - help=_("package compression method")) self.parser.add_option("-A", "--ignore-action-errors", action="store_true", default=False, help=_("bypass errors from ActionsAPI")) self.parser.add_option("-B", "--ignore-comar", action="store_true", default=False, help=_("bypass comar configuration agent")) self.parser.add_option("", "--create-static", action="store_true", - default=False, help=_("don't create a static package with ar files")) + default=False, help=_("create a static package with ar files")) self.parser.add_option("", "--no-debug", action="store_true", default=False, help=_("don't create a debug package with debug files")) self.parser.add_option("", "--no-install", action="store_true", default=False, help=_("don't install build dependencies, fail if a build dependency is present")) + self.parser.add_option("-C", "--compression-method", action="store", default='lzma', + help=_("package compression method")) def run(self): @@ -422,6 +422,11 @@ downloaded from a repository containing sources. name = ("emerge", "em") + def options(self): + Build.options(self) + self.parser.add_option("", "--ignore-script-errors", action="store_true", + default=False, help=_("Ignore errors from scripts")) + def run(self): if not self.args: self.help() @@ -453,6 +458,8 @@ class PackageOp(Command): default=False, help=_("bypass safety switch")) p.add_option("-n", "--dry-run", action="store_true", default=False, help = _("do not perform any action, just show what would be done")) + p.add_option("", "--ignore-script-errors", action="store_true", + default=False, help=_("Ignore errors from scripts")) ignoredep_opt(self) def init(self): @@ -531,11 +538,11 @@ expanded to package names. buildno_opts(self) p = self.parser p.add_option("-r", "--bypass-update-repo", action="store_true", - default=False, help=_("Do not update repositories")) + default=False, help=_("Do not update repositories")) p.add_option("", "--bypass-ldconfig", action="store_true", - default=False, help=_("Bypass ldconfig phase")) - self.parser.add_option("-e", "--eager", action="store_true", - default=False, help=_("eager upgrades")) + default=False, help=_("Bypass ldconfig phase")) + p.add_option("-e", "--eager", action="store_true", + default=False, help=_("eager upgrades")) def run(self): self.init() diff --git a/pisi/operations.py b/pisi/operations.py index 0bea1ca2..91061e36 100644 --- a/pisi/operations.py +++ b/pisi/operations.py @@ -42,9 +42,21 @@ class Error(pisi.Error): pass class PisiUpgradeException(pisi.Exception): + """application must reload all pisi modules it imported after receiving + this exception""" def __init__(self): pisi.Exception.__init__(self, _("Upgrading PISI requires database rebuild and restart")) +def upgrade_pisi(): + ctx.ui.warning(_("PISI package has been upgraded. Rebuilding database and restarting.")) + pisi.api.finalize() + os.system('pisi rebuild-db -y') + #reload(pisi) + #pisi.api.init() + #pisi.api.rebuild_db() + raise PisiUpgradeException() + + # high level operations def install(packages, reinstall = False): @@ -232,7 +244,10 @@ def is_upgradable(name, ignore_build = False): if not ctx.installdb.is_installed(name): return False (version, release, build) = ctx.installdb.get_version(name) - pkg = ctx.packagedb.get_package(name) + try: + pkg = ctx.packagedb.get_package(name) + except: + return False if ignore_build or (not build) or (not pkg.build): return Version(release) < Version(pkg.release) else: @@ -308,6 +323,9 @@ in the respective order to satisfy dependencies: for x in order: atomicoperations.install_single_name(x) + + if 'pisi' in order and ctx.installdb.is_installed('pisi'): + upgrade_pisi() def plan_install_pkg_names(A): # try to construct a pisi graph of packages to @@ -424,13 +442,8 @@ def upgrade_pkg_names(A = [], bypass_safety = False): install_op = atomicoperations.Install(path) install_op.install(True) - #if 'pisi' in order: - # ctx.ui.warning(_("PISI package has been upgraded. You should run rebuild-db.")) - # pisi.api.finalize() - # reload(pisi) - # pisi.api.init() - # pisi.api.rebuild_db() - # raise PisiUpgradeException() + if 'pisi' in order: + upgrade_pisi() def plan_upgrade(A, ignore_build = False): # try to construct a pisi graph of packages to @@ -711,6 +724,9 @@ installed in the respective order to satisfy dependencies: package_names, blah = atomicoperations.build(x) install_pkg_files(package_names) # handle inter-package deps here + if 'pisi' in order_build or ('pisi' in order_inst and ctx.installdb.is_installed('pisi')): + upgrade_pisi() + def plan_emerge(A, rebuild_all): # try to construct a pisi graph of packages to