def do_upgrade(xom): tw = py.io.TerminalWriter() serverdir = xom.config.serverdir exportdir = serverdir + "-export" if exportdir.check(): tw.line("removing exportdir: %s" % exportdir) exportdir.remove() newdir = serverdir + "-import" script = sys.argv[0] def rel(p): return py.path.local().bestrelpath(p) state_version = xom.get_state_version() tw.sep("-", "exporting to %s" % rel(exportdir)) if Version(state_version) > Version(server_version): fatal("%s has state version %s which is newer than what we " "can handle (%s)" % (xom.config.serverdir, state_version, server_version)) elif Version(state_version) < Version(server_version): tw.line("creating server venv %s ..." % state_version) tmpdir = py.path.local.make_numbered_dir("devpi-upgrade") venv = create_server_venv(tw, state_version, tmpdir) tw.line("server venv %s created: %s" % (server_version, tmpdir)) venv.check_call([ "devpi-server", "--serverdir", str(serverdir), "--export", str(exportdir) ]) else: #tw.sep("-", "creating venv" % rel(exportdir)) subprocess.check_call([ sys.executable, script, "--serverdir", str(serverdir), "--export", str(exportdir) ]) tw.sep("-", "importing from %s" % rel(exportdir)) tw.line("importing into server version: %s" % server_version) subprocess.check_call([ sys.executable, script, "--serverdir", str(newdir), "--import", str(exportdir) ]) tw.sep("-", "replacing serverstate") backup_dir = serverdir + "-backup" if backup_dir.check(): tw.line("backup dir exists, not creating backup", bold=True) else: tw.line("moving serverstate to backupdir: %s" % (backup_dir), bold=True) serverdir.move(backup_dir) if serverdir.check(): tw.line("removing serverstate: %s" % (serverdir)) serverdir.remove() tw.line("copying new serverstate to serverdir", bold=True) newdir.move(serverdir) serverdir.join(".serverversion").read() tw.line("cleanup: removing exportdir: %s" % exportdir) tw.line("have fun serving the new state :)") exportdir.remove()
def check_compatible_version(xom): args = xom.config.args if args.upgrade_state or args.export: return state_version = xom.get_state_version() if Version(server_version) != Version(state_version): fatal("Incompatible state: server %s cannot run serverdir " "%s created by %s. " % (server_version, xom.config.serverdir, state_version))
def getnewestversion(self, pkgname): best = None for link in self.links: basename = URL(link.url).basename name, version = splitbasename(basename)[:2] ver = Version(version) if name == pkgname: if best is None or ver > best[0]: best = ver, link return best and best[1] or None
def filter_latest(path_pkginfo): name_version_path = {} for archivepath, pkginfo in path_pkginfo.items(): name = pkginfo.name iversion = Version(pkginfo.version) data = name_version_path.get(name) if data is None or data[0] < iversion: name_version_path[name] = (iversion, pkginfo, archivepath) retval = {} for x in name_version_path.values(): retval[x[2]] = x[1] return retval
def getnewestversion(self, pkgname): """ returns newest applicable version of package """ req = next(pkg_resources.parse_requirements(pkgname)) best = None for link in self.links: basename = URL(link.url).basename name, version = splitbasename(basename)[:2] ver = Version(version) if name in (req.project_name, pkgname) and version in req: if best is None or ver > best[0]: best = ver, link return best and best[1] or None
def check_compatible_version(xom): args = xom.config.args if args.export: return state_version = xom.get_state_version() if server_version != state_version: state_ver = tuple(state_version.split(".")) server_ver = tuple(server_version.split(".")) incompatible = (state_ver[:1] != server_ver[:1] or Version(state_version) < Version("2.2.dev0")) if incompatible: fatal("Incompatible state: server %s cannot run serverdir " "%s created by %s.\n" "Use --export from older version, then --import with newer " "version." % (server_version, xom.config.serverdir, state_version)) xom.set_state_version(server_version) tw = py.io.TerminalWriter(sys.stderr) tw.line("minor version upgrade: setting serverstate to %s from %s" % (server_version, state_version), bold=True)
def compute_global_projectname_normalization(self): self.tw.line("computing global projectname normalization map") norm2maxversion = {} # compute latest normname version across all stages for user in self.xom.model.get_userlist(): userconfig = user.get() for indexname in userconfig.get("indexes", []): stage = self.xom.model.getstage(user.name, indexname) names = stage.list_projectnames_perstage() for name in names: # pypi names take precedence for defining the realname if stage.name == "root/pypi": version = Version("999999.99999") version.realname = name norm2maxversion[normalize_name(name)] = version continue versions = stage.list_versions_perstage(name) if versions: maxver = None for ver in versions: version = Version(ver) verdata = stage.get_versiondata(name, ver) version.realname = verdata.get("name", name) if maxver is None or version > maxver: maxver = version if not maxver: continue norm = normalize_name(name) normver = norm2maxversion.setdefault(norm, maxver) if maxver > normver: norm2maxversion[norm] = maxver # determine real name of a project self.norm2name = norm2name = {} for norm, maxver in norm2maxversion.items(): norm2name[norm] = maxver.realname
def test_normalization_merge(self, caplog, impexp): mapp = impexp.import_testdata('normalization_merge') with mapp.xom.keyfs.transaction(write=False): stage = mapp.xom.model.getstage('root/dev') links = sorted(stage.get_releaselinks("hello.pkg"), key=lambda x: Version(x.version)) assert len(links) == 2 assert links[0].project == "hello-pkg" assert links[1].project == "hello-pkg" assert links[0].version == "1.0" assert links[1].version == "1.1" link = stage.get_link_from_entrypath(links[0].entrypath) assert link.entry.file_get_content() == b"content1" link = stage.get_link_from_entrypath(links[1].entrypath) assert link.entry.file_get_content() == b"content2"
def test_version(): ver1 = Version("1.0") ver2 = Version("1.1") assert max([ver1, ver2]) == ver2
def version_get(context, request): """ Show version for the precise stage, ignores inheritance. """ context = ContextWrapper(context) name = context.verified_project stage = context.stage version = context.version if version == 'latest' and context._versions: version = context._versions[0] elif version == 'stable' and context._stable_versions: version = context._stable_versions[0] try: verdata = context.get_versiondata(version=version, perstage=True) except stage.UpstreamError as e: log.error(e.msg) raise HTTPBadGateway(e.msg) infos = [] skipped_keys = frozenset( ("description", "home_page", "name", "summary", "version")) for key, value in sorted(verdata.items()): if key in skipped_keys or key.startswith('+'): continue if isinstance(value, seq_types): if not len(value): continue value = html.ul([html.li(x) for x in value]).unicode() else: if not value: continue value = py.xml.escape(value) infos.append((py.xml.escape(key), value)) show_toxresults = (stage.ixconfig['type'] != 'mirror') linkstore = stage.get_linkstore_perstage(name, version) files = get_files_info(request, linkstore, show_toxresults) docs = get_docs_info(request, stage, linkstore) home_page = verdata.get("home_page") nav_links = [] if docs: nav_links.append(dict(title="Documentation", url=docs['url'])) if home_page: nav_links.append(dict(title="Homepage", url=home_page)) nav_links.append( dict(title="Simple index", url=request.route_url("/{user}/{index}/+simple/{project}", user=context.username, index=context.index, project=context.project))) if hasattr(stage, 'get_mirror_whitelist_info'): whitelist_info = stage.get_mirror_whitelist_info(name) else: whitelist_info = dict(has_mirror_base=stage.has_mirror_base(name), blocked_by_mirror_whitelist=False) if whitelist_info['has_mirror_base']: for base in reversed(list(stage.sro())): if base.ixconfig["type"] != "mirror": continue mirror_web_url_fmt = base.ixconfig.get("mirror_web_url_fmt") if not mirror_web_url_fmt: continue nav_links.append( dict(title="%s page" % base.ixconfig.get("title", "Mirror"), url=mirror_web_url_fmt.format(name=name))) cmp_version = Version(version) if context._stable_versions: stable_version = Version(context._stable_versions[0]) url = request.route_url("/{user}/{index}/{project}/{version}", user=context.username, index=context.index, project=context.project, version='stable') if cmp_version.is_prerelease(): nav_links.append( dict(title="Stable version available", css_class="warning", url=url)) elif stable_version != cmp_version: nav_links.append( dict(title="Newer version available", css_class="severe", url=url)) return dict(title="%s/: %s-%s metadata and description" % (stage.name, name, version), content=get_description(stage, name, version), summary=verdata.get("summary"), nav_links=nav_links, infos=infos, metadata_list_fields=frozenset( py.xml.escape(x) for x in getattr(stage, 'metadata_list_fields', ())), files=files, blocked_by_mirror_whitelist=whitelist_info[ 'blocked_by_mirror_whitelist'], show_toxresults=show_toxresults, make_toxresults_url=functools.partial(request.route_url, "toxresults", user=context.username, index=context.index, project=context.project, version=context.version), make_toxresult_url=functools.partial(request.route_url, "toxresult", user=context.username, index=context.index, project=context.project, version=context.version))