def check_dbversion(versionfile, ver, write=False, update=False): verfn = join_path(pisi.context.config.db_dir(), versionfile) firsttime = False if os.path.exists(verfn): verfile = file(verfn, 'r') ls = verfile.readlines() currver = Version(ls[0]) dbver = Version(ver) if currver < dbver: if not update: raise Error( _('Database version for %s insufficient. Please run rebuild-db command.' ) % versionfile) else: pass # continue to update, then elif currver > dbver: raise Error( _('Database version for %s greater than PiSi version. You need a newer PiSi.' ) % versionfile) elif not update: return True # db version is OK else: firsttime = True if write and (update or firsttime): if os.access(pisi.context.config.db_dir(), os.W_OK): ctx.ui.warning( _('Writing current database version for %s') % versionfile) verfile = file(verfn, 'w') verfile.write(ver) verfile.close() else: raise Error( _('Cannot attain write access to database environment')) else: raise Error(_('Database version %s not present.') % versionfile)
def testOpsCharacters(self): # with character v1 = Version("2.10a") v2 = Version("2.10") v3 = Version("2.10d") self.assertTrue(v1 > v2) self.assertTrue(v1 < v3) self.assertTrue(v2 < v3)
def testOpsNumerical(self): v1 = Version("0.3.1") v2 = Version("0.3.5") v3 = Version("1.5.2") v4 = Version("0.3.1") v5 = Version("2.07") self.assertTrue(v1 < v2) self.assertTrue(v3 > v2) self.assertTrue(v1 <= v3) self.assertTrue(v4 >= v4) self.assertTrue(v5 > v3)
def postInstall(fromVersion, fromRelease, toVersion, toRelease): if fromVersion and Version("0.90") <= Version(fromVersion) <= Version( "0.96"): from zorg import config busId = call("zorg", "Xorg.Display", "activeDeviceID") device = config.getDeviceInfo(busId) if device: config.saveDeviceInfo(device) config.saveXorgConfig(device)
def is_upgradable(name, ignore_build=False): if not ctx.installdb.is_installed(name): return False (version, release, build) = ctx.installdb.get_version(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: return build < pkg.build
def postInstall(fromVersion, fromRelease, toVersion, toRelease): if fromVersion and Version("0.90") <= Version(fromVersion) <= Version( "0.96"): from zorg import config busId = call("zorg", "Xorg.Display", "activeDeviceID") device = config.getDeviceInfo(busId) if device: config.saveDeviceInfo(device) config.saveXorgConfig(device) if fromRelease and int(fromRelease) < 81: from zorg import config layout, variant = config.getKeymapOld() config.saveKeymap(layout, variant)
def clean_duplicates(): i_version = {} # installed versions replica = [] for pkg in os.listdir(pisi.util.join_path(pisi.api.ctx.config.lib_dir(), 'package')): (name, ver) = util.parse_package_name(pkg) if i_version.has_key(name): if Version(ver) > Version(i_version[name]): # found a greater version, older one is a replica replica.append(name + '-' + i_version[name]) i_version[name] = ver else: # found an older version which is a replica replica.append(name + '-' + ver) else: i_version[name] = ver for pkg in replica: pisi.util.clean_dir(pisi.util.join_path(pisi.api.ctx.config.lib_dir(), 'package', pkg))
def postInstall(fromVersion, fromRelease, toVersion, toRelease): enabledPackage = "/var/lib/zorg/enabled_package" if os.path.exists(enabledPackage) and file( enabledPackage).read() == "ati-drivers": call("ati_drivers", "Xorg.Driver", "enable") if fromVersion and Version(fromVersion) < Version("9.3"): from zorg import config busId = call("zorg", "Xorg.Display", "activeDeviceID") device = config.getDeviceInfo(busId) if device: device.probe_result["flags"] = "randr12" config.saveDeviceInfo(device) config.saveXorgConfig(device)
def findUnneededFiles(listdir): dict = {} for f in listdir: try: name, version = util.parse_package_name(f) if dict.has_key(name): if Version(dict[name]) < Version(version): dict[name] = version else: if version: dict[name] = version except: pass for f in dict: listdir.remove("%s-%s" % (f, dict[f])) return listdir
def getPackageLists(pkgList): latest = {} for f in pkgList: try: name, version = util.parse_package_name(f) if latest.has_key(name): if Version(latest[name]) < Version(version): latest[name] = version else: if version: latest[name] = version except: pass latestVersions = [] for pkg in latest: latestVersions.append("%s-%s" % (pkg, latest[pkg])) oldVersions = list(set(pkgList) - set(latestVersions)) return oldVersions, latestVersions
def testOpsKeywords(self): # with keywords v1 = Version("2.23_pre10") v2 = Version("2.23") v3 = Version("2.21") v4 = Version("2.23_p1") v5 = Version("2.23_beta1") v6 = Version("2.23_m1") v7 = Version("2.23_rc1") v8 = Version("2.23_rc2") self.assertTrue(v1 < v2) self.assertTrue(v1 > v3) self.assertTrue(v1 < v4) self.assertTrue(v1 > v5) self.assertTrue(v2 < v4) self.assertTrue(v2 > v5) self.assertTrue(v6 < v4) self.assertTrue(v6 > v5) self.assertTrue(v7 > v5) self.assertTrue(v8 > v7) v1 = Version("1.0_alpha1") v2 = Version("1.0_alpha2") self.assertTrue(v2 > v1)
def minsandmaxes(): packages = [os.path.basename(x).split(".pisi")[0] for x in set(glob.glob("*.pisi")) - set(glob.glob("*.delta.pisi"))] versions = {} for file in packages: name, version = util.parse_package_name(file) versions.setdefault(name, []).append(Version(version)) mins = {} maxs = {} for pkg in list(versions.keys()): mins[pkg] = min(versions[pkg]) maxs[pkg] = max(versions[pkg]) return mins, maxs
def satisfies(self, pkg_name, version, release): """determine if a package ver. satisfies given dependency spec""" ret = True v = Version(version) if self.version: ret &= v == Version(self.version) if self.versionFrom: ret &= v >= Version(self.versionFrom) if self.versionTo: ret &= v <= Version(self.versionTo) r = Version(release) if self.release: ret &= r == Version(self.release) if self.releaseFrom: ret &= r >= Version(self.releaseFrom) if self.releaseTo: ret &= r <= Version(self.releaseTo) return ret
def minsandmaxes(): packages = map(lambda x: os.path.basename(x).split(".eopkg")[0], set(glob.glob("*.eopkg")) - set(glob.glob("*.delta.eopkg"))) versions = {} for file in packages: name, version = util.parse_package_name(file) versions.setdefault(name, []).append(Version(version)) mins = {} maxs = {} for pkg in versions.keys(): mins[pkg] = min(versions[pkg]) maxs[pkg] = max(versions[pkg]) return mins, maxs
def testSingle(self): v1 = Version("103") v2 = Version("90") self.assertTrue(v1 > v2)
def check_reinstall(self): "check reinstall, confirm action, and schedule reinstall" pkg = self.pkginfo self.reinstall = False self.upgrade = False if ctx.installdb.is_installed(pkg.name): # is this a reinstallation? #FIXME: consider REPOSITORY instead of DISTRIBUTION -- exa #ipackage = ctx.packagedb.get_package(pkg.name, pisi.db.itembyrepo.installed) ipkg = ctx.installdb.get_info(pkg.name) repomismatch = ipkg.distribution != pkg.distribution (iversion, irelease, ibuild) = ctx.installdb.get_version(pkg.name) # determine if same version self.same_ver = False ignore_build = ctx.config.options and ctx.config.options.ignore_build_no if repomismatch or (not ibuild) or (not pkg.build) or ignore_build: # we don't look at builds to compare two package versions if Version(pkg.release) == Version(irelease): self.same_ver = True else: if pkg.build == ibuild: self.same_ver = True if self.same_ver: if self.ask_reinstall: if not ctx.ui.confirm( _('Re-install same version package?')): raise Error(_('Package re-install declined')) else: upgrade = False # is this an upgrade? # determine and report the kind of upgrade: version, release, build if Version(pkg.version) > Version(iversion): ctx.ui.info(_('Upgrading to new upstream version')) upgrade = True elif Version(pkg.release) > Version(irelease): ctx.ui.info(_('Upgrading to new distribution release')) upgrade = True elif ((not ignore_build) and ibuild and pkg.build and pkg.build > ibuild): ctx.ui.info(_('Upgrading to new distribution build')) upgrade = True self.upgrade = upgrade # is this a downgrade? confirm this action. if self.ask_reinstall and (not upgrade): if Version(pkg.version) < Version(iversion): #x = _('Downgrade to old upstream version?') x = None elif Version(pkg.release) < Version(irelease): x = _('Downgrade to old distribution release?') else: x = _('Downgrade to old distribution build?') if x and not ctx.ui.confirm(x): raise Error(_('Package downgrade declined')) # schedule for reinstall self.old_files = ctx.installdb.files(pkg.name) self.old_path = ctx.installdb.pkg_dir(pkg.name, iversion, irelease) self.reinstall = True self.remove_old = remove.Remove(pkg.name) self.remove_old.run_preremove()
def testGeBug(self): # bug 603 v1 = Version('1.8.0') v2 = Version('1.9.1') self.assertTrue(not v1 > v2) self.assertTrue(not v1 >= v2)
def upgrade_pkg_names(A=[]): """Re-installs packages from the repository, trying to perform a minimum or maximum number of upgrades according to options.""" ignore_build = ctx.get_option('ignore_build_no') security = ctx.get_option('security') if not A: # if A is empty, then upgrade all packages A = ctx.installdb.list_installed() A_0 = A = component.expand_components(set(A)) Ap = [] for x in A: if x.endswith(ctx.const.package_suffix): ctx.ui.debug(_("Warning: package *name* ends with '.pisi'")) if not ctx.installdb.is_installed(x): ctx.ui.info(_('Package %s is not installed.') % x, True) continue (version, release, build) = ctx.installdb.get_version(x) if ctx.packagedb.has_package(x): pkg = ctx.packagedb.get_package(x) else: ctx.ui.info( _('Package %s is not available in repositories.') % x, True) continue if security: # below is a readable functional code, don't overflow lines! updates = [ x for x in pkg.history if Version(x.release) > Version(release) ] if not pisi.util.any(lambda x: x.type == 'security', updates): continue if ignore_build or (not build) or (not pkg.build): if Version(release) < Version(pkg.release): Ap.append(x) else: ctx.ui.info( _('Package %s is already at the latest release %s.') % (pkg.name, pkg.release), True) else: if build < pkg.build: Ap.append(x) else: ctx.ui.info( _('Package %s is already at the latest build %s.') % (pkg.name, pkg.build), True) A = set(Ap) if len(A) == 0: ctx.ui.info(_('No packages to upgrade.')) return True A |= upgrade_base(A) ctx.ui.debug('A = %s' % str(A)) if not ctx.config.get_option('ignore_dependency'): G_f, order = plan_upgrade(A, ignore_build) else: G_f = None order = A ctx.ui.info( _('The following packages will be upgraded: ') + util.strlist(order)) total_size = sum([ctx.packagedb.get_package(p).packageSize for p in order]) total_size, symbol = util.human_readable_size(total_size) ctx.ui.info(_('Total size of packages: %.2f %s') % (total_size, symbol)) if ctx.get_option('dry_run'): return if len(order) > len(A_0): if not ctx.ui.confirm( _('There are extra packages due to dependencies. Do you want to continue?' )): return False ctx.ui.notify(ui.packagestogo, order=order) paths = [] for x in order: install_op = install.Install.from_name(x) paths.append(install_op.package_fname) for path in paths: install_op = install.Install(path, ignore_file_conflicts=True) install_op.install(True) if 'pisi' in order: upgradepisi.upgrade_pisi()