* 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
This commit is contained in:
Eray Özkural
2006-05-09 14:11:35 +00:00
parent bfccbeaa98
commit f170549687
5 changed files with 60 additions and 36 deletions
+4 -1
View File
@@ -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'
+1 -15
View File
@@ -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
+14 -2
View File
@@ -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
+17 -10
View File
@@ -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()
+24 -8
View File
@@ -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