Little optimization for Install class
* Make release variables integer instead of Version * Create Version objects outside loops if possible * Do not iterate over all update tags
This commit is contained in:
@@ -227,18 +227,22 @@ class Install(AtomicOperation):
|
|||||||
|
|
||||||
self.old_pkginfo = None
|
self.old_pkginfo = None
|
||||||
pkg = self.pkginfo
|
pkg = self.pkginfo
|
||||||
|
pkg_version = pisi.version.Version(pkg.version)
|
||||||
|
pkg_release = int(pkg.release)
|
||||||
|
|
||||||
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_package(pkg.name)
|
ipkg = self.installdb.get_package(pkg.name)
|
||||||
repomismatch = ipkg.distribution != pkg.distribution
|
repomismatch = ipkg.distribution != pkg.distribution
|
||||||
(iversion, irelease, ibuild) = self.installdb.get_version(pkg.name)
|
(iversion, irelease, ibuild) = self.installdb.get_version(pkg.name)
|
||||||
|
iversion = pisi.version.Version(iversion)
|
||||||
|
irelease = int(irelease)
|
||||||
|
|
||||||
# determine if same version
|
# determine if same version
|
||||||
self.same_ver = False
|
self.same_ver = False
|
||||||
ignore_build = ctx.config.options and ctx.config.options.ignore_build_no
|
ignore_build = ctx.config.options and ctx.config.options.ignore_build_no
|
||||||
if repomismatch or (not ibuild) or (not pkg.build) or ignore_build:
|
if repomismatch or (not ibuild) or (not pkg.build) or ignore_build:
|
||||||
# we don't look at builds to compare two package versions
|
# we don't look at builds to compare two package versions
|
||||||
if pisi.version.Version(pkg.release) == pisi.version.Version(irelease):
|
if pkg_release == irelease:
|
||||||
self.same_ver = True
|
self.same_ver = True
|
||||||
else:
|
else:
|
||||||
if pkg.build == ibuild:
|
if pkg.build == ibuild:
|
||||||
@@ -252,10 +256,10 @@ class Install(AtomicOperation):
|
|||||||
else:
|
else:
|
||||||
# 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 pkg_version > iversion:
|
||||||
ctx.ui.info(_('Upgrading to new upstream version'))
|
ctx.ui.info(_('Upgrading to new upstream version'))
|
||||||
self.operation = UPGRADE
|
self.operation = UPGRADE
|
||||||
elif pisi.version.Version(pkg.release) > pisi.version.Version(irelease):
|
elif pkg_release > irelease:
|
||||||
ctx.ui.info(_('Upgrading to new distribution release'))
|
ctx.ui.info(_('Upgrading to new distribution release'))
|
||||||
self.operation = UPGRADE
|
self.operation = UPGRADE
|
||||||
elif ((not ignore_build) and ibuild and pkg.build
|
elif ((not ignore_build) and ibuild and pkg.build
|
||||||
@@ -265,10 +269,10 @@ class Install(AtomicOperation):
|
|||||||
|
|
||||||
# is this a downgrade? confirm this action.
|
# is this a downgrade? confirm this action.
|
||||||
if not self.operation == UPGRADE:
|
if not self.operation == UPGRADE:
|
||||||
if pisi.version.Version(pkg.version) < pisi.version.Version(iversion):
|
if pkg_version < iversion:
|
||||||
#x = _('Downgrade to old upstream version?')
|
#x = _('Downgrade to old upstream version?')
|
||||||
x = None
|
x = None
|
||||||
elif pisi.version.Version(pkg.release) < pisi.version.Version(irelease):
|
elif pkg_release < irelease:
|
||||||
x = _('Downgrade to old distribution release?')
|
x = _('Downgrade to old distribution release?')
|
||||||
else:
|
else:
|
||||||
x = _('Downgrade to old distribution build?')
|
x = _('Downgrade to old distribution build?')
|
||||||
@@ -279,7 +283,7 @@ class Install(AtomicOperation):
|
|||||||
# 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, str(iversion), str(irelease))
|
||||||
self.remove_old = Remove(pkg.name)
|
self.remove_old = Remove(pkg.name)
|
||||||
self.remove_old.run_preremove()
|
self.remove_old.run_preremove()
|
||||||
self.remove_old.run_postremove()
|
self.remove_old.run_postremove()
|
||||||
@@ -508,7 +512,11 @@ class Install(AtomicOperation):
|
|||||||
# get update history
|
# get update history
|
||||||
if self.installdb.has_package(self.pkginfo.name):
|
if self.installdb.has_package(self.pkginfo.name):
|
||||||
(version, release, build) = self.installdb.get_version(self.pkginfo.name)
|
(version, release, build) = self.installdb.get_version(self.pkginfo.name)
|
||||||
updates = [i for i in self.pkginfo.history if pisi.version.Version(i.release) > pisi.version.Version(release)]
|
updates = []
|
||||||
|
for update in self.pkginfo.history:
|
||||||
|
if update.release == release:
|
||||||
|
break
|
||||||
|
updates.append(update)
|
||||||
else:
|
else:
|
||||||
updates = self.pkginfo.history
|
updates = self.pkginfo.history
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user