Provide a way to find out which operation an install is actually doing:

Is it downgrade, reinstall, install or upgrade?
This commit is contained in:
Faik Uygur
2008-01-25 07:57:31 +00:00
parent e3c16f8d71
commit 7af80923b5
+20 -18
View File
@@ -53,6 +53,8 @@ class AtomicOperation(object):
"perform an atomic package operation" "perform an atomic package operation"
pass pass
# possible paths of install operation
(INSTALL, REINSTALL, UPGRADE, DOWNGRADE) = range(4)
class Install(AtomicOperation): class Install(AtomicOperation):
"Install class, provides install routines for pisi packages" "Install class, provides install routines for pisi packages"
@@ -110,6 +112,7 @@ class Install(AtomicOperation):
self.pkginfo = self.metadata.package self.pkginfo = self.metadata.package
self.filesdb = pisi.db.filesdb.FilesDB() self.filesdb = pisi.db.filesdb.FilesDB()
self.installdb = pisi.db.installdb.InstallDB() self.installdb = pisi.db.installdb.InstallDB()
self.operation = INSTALL
def install(self, ask_reinstall = True): def install(self, ask_reinstall = True):
if ctx.get_option('fetch_only'): if ctx.get_option('fetch_only'):
@@ -123,7 +126,7 @@ class Install(AtomicOperation):
self.ask_reinstall = ask_reinstall self.ask_reinstall = ask_reinstall
self.check_requirements() self.check_requirements()
self.check_relations() self.check_relations()
self.check_reinstall() self.check_operation()
self.extract_install() self.extract_install()
ctx.disable_keyboard_interrupts() ctx.disable_keyboard_interrupts()
@@ -135,7 +138,7 @@ class Install(AtomicOperation):
ctx.enable_keyboard_interrupts() ctx.enable_keyboard_interrupts()
ctx.ui.close() ctx.ui.close()
if self.upgrade: if self.operation == UPGRADE:
event = pisi.ui.upgraded event = pisi.ui.upgraded
else: else:
event = pisi.ui.installed event = pisi.ui.installed
@@ -185,14 +188,11 @@ class Install(AtomicOperation):
else: else:
raise Error(msg) raise Error(msg)
def check_reinstall(self): def check_operation(self):
"check reinstall, confirm action, and schedule reinstall"
self.old_pkginfo = None self.old_pkginfo = None
pkg = self.pkginfo pkg = self.pkginfo
self.reinstall = False
self.upgrade = False
if self.installdb.has_package(pkg.name): # is this a reinstallation? if self.installdb.has_package(pkg.name): # is this a reinstallation?
ipkg = self.installdb.get_info(pkg.name) ipkg = self.installdb.get_info(pkg.name)
repomismatch = ipkg.distribution != pkg.distribution repomismatch = ipkg.distribution != pkg.distribution
@@ -213,24 +213,23 @@ class Install(AtomicOperation):
if self.ask_reinstall: if self.ask_reinstall:
if not ctx.ui.confirm(_('Re-install same version package?')): if not ctx.ui.confirm(_('Re-install same version package?')):
raise Error(_('Package re-install declined')) raise Error(_('Package re-install declined'))
self.operation = REINSTALL
else: else:
upgrade = False
# is this an upgrade? # is this an upgrade?
# determine and report the kind of upgrade: version, release, build # determine and report the kind of upgrade: version, release, build
if pisi.version.Version(pkg.version) > pisi.version.Version(iversion): if pisi.version.Version(pkg.version) > pisi.version.Version(iversion):
ctx.ui.info(_('Upgrading to new upstream version')) ctx.ui.info(_('Upgrading to new upstream version'))
upgrade = True self.operation = UPGRADE
elif pisi.version.Version(pkg.release) > pisi.version.Version(irelease): elif pisi.version.Version(pkg.release) > pisi.version.Version(irelease):
ctx.ui.info(_('Upgrading to new distribution release')) ctx.ui.info(_('Upgrading to new distribution release'))
upgrade = True self.operation = UPGRADE
elif ((not ignore_build) and ibuild and pkg.build elif ((not ignore_build) and ibuild and pkg.build
and pkg.build > ibuild): and pkg.build > ibuild):
ctx.ui.info(_('Upgrading to new distribution build')) ctx.ui.info(_('Upgrading to new distribution build'))
upgrade = True self.operation = UPGRADE
self.upgrade = upgrade
# is this a downgrade? confirm this action. # is this a downgrade? confirm this action.
if self.ask_reinstall and (not upgrade): if self.ask_reinstall and (not self.operation == UPGRADE):
if pisi.version.Version(pkg.version) < pisi.version.Version(iversion): if pisi.version.Version(pkg.version) < pisi.version.Version(iversion):
#x = _('Downgrade to old upstream version?') #x = _('Downgrade to old upstream version?')
x = None x = None
@@ -240,21 +239,24 @@ class Install(AtomicOperation):
x = _('Downgrade to old distribution build?') x = _('Downgrade to old distribution build?')
if x and not ctx.ui.confirm(x): if x and not ctx.ui.confirm(x):
raise Error(_('Package downgrade declined')) raise Error(_('Package downgrade declined'))
self.operation = DOWNGRADE
# schedule for reinstall # schedule for reinstall
self.old_files = self.installdb.get_files(pkg.name) self.old_files = self.installdb.get_files(pkg.name)
self.old_pkginfo = self.installdb.get_info(pkg.name) self.old_pkginfo = self.installdb.get_info(pkg.name)
self.old_path = self.installdb.pkg_dir(pkg.name, iversion, irelease) self.old_path = self.installdb.pkg_dir(pkg.name, iversion, irelease)
self.reinstall = True
self.remove_old = Remove(pkg.name) self.remove_old = Remove(pkg.name)
self.remove_old.run_preremove() self.remove_old.run_preremove()
def reinstall(self):
return not self.operation == INSTALL
def postinstall(self): def postinstall(self):
self.config_later = False self.config_later = False
if ctx.comar: if ctx.comar:
import pisi.comariface import pisi.comariface
try: try:
if self.upgrade: if self.operation == UPGRADE:
fromVersion = self.old_pkginfo.version fromVersion = self.old_pkginfo.version
fromRelease = self.old_pkginfo.release fromRelease = self.old_pkginfo.release
else: else:
@@ -358,7 +360,7 @@ class Install(AtomicOperation):
for path in leftover: for path in leftover:
Remove.remove_file(old_fileinfo[path], self.pkginfo.name) Remove.remove_file(old_fileinfo[path], self.pkginfo.name)
if self.reinstall: if self.reinstall():
# get 'config' typed file objects # get 'config' typed file objects
new = filter(lambda x: x.type == 'config', self.files.list) new = filter(lambda x: x.type == 'config', self.files.list)
old = filter(lambda x: x.type == 'config', self.old_files.list) old = filter(lambda x: x.type == 'config', self.old_files.list)
@@ -386,7 +388,7 @@ class Install(AtomicOperation):
if config_changed: if config_changed:
rename_configs() rename_configs()
if self.reinstall: if self.reinstall():
clean_leftovers() clean_leftovers()
@@ -394,7 +396,7 @@ class Install(AtomicOperation):
"""put files.xml, metadata.xml, actions.py and COMAR scripts """put files.xml, metadata.xml, actions.py and COMAR scripts
somewhere in the file system. We'll need these in future...""" somewhere in the file system. We'll need these in future..."""
if self.reinstall: if self.reinstall():
util.clean_dir(self.old_path) util.clean_dir(self.old_path)
ctx.ui.info(_('Storing %s, ') % ctx.const.files_xml, verbose=True) ctx.ui.info(_('Storing %s, ') % ctx.const.files_xml, verbose=True)
@@ -412,7 +414,7 @@ class Install(AtomicOperation):
def update_databases(self): def update_databases(self):
"update databases" "update databases"
if self.reinstall: if self.reinstall():
self.remove_old.remove_db() self.remove_old.remove_db()
if self.config_later: if self.config_later: