diff options
author | Matěj Cepl <mcepl@cepl.eu> | 2019-01-05 11:18:59 +0100 |
---|---|---|
committer | Matěj Cepl <mcepl@cepl.eu> | 2019-01-05 11:23:53 +0100 |
commit | 54981106fdada59b6f34cd25e0e4b468a13fcaa0 (patch) | |
tree | 54a38e44cc9f9626ec9d3ad73846d1a9d276329f | |
parent | d9d9224f40ebc0e6a73e1fa828ebaa44891e443f (diff) | |
download | dlp_check_version_PyPI-54981106fdada59b6f34cd25e0e4b468a13fcaa0.tar.gz |
Restart the project.
What should we do with projects which are not on PyPI? How do we find
out whether they are there? Should we run search for every package?
-rwxr-xr-x | dlpcvp.py | 39 |
1 files changed, 28 insertions, 11 deletions
@@ -1,6 +1,7 @@ #!/usr/bin/python3.6 # Requires: python3-rpm +import argparse import configparser import json import logging @@ -21,6 +22,7 @@ import rpm PyPI_base = "https://pypi.org/pypi/{}/json" OBS_base = "https://api.opensuse.org" ConfigRC = os.path.expanduser('~/.config/osc/oscrc') +CUTCHARS = len('python-') config = configparser.ConfigParser() config.read(ConfigRC) @@ -29,6 +31,7 @@ logging.basicConfig(format='%(levelname)s:%(funcName)s:%(message)s', level=logging.DEBUG) log = logging.getLogger() +# or HTTPPasswordMgrWithPriorAuth ? password_mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm() user = config[OBS_base]['user'] passw = config[OBS_base]['pass'] @@ -36,6 +39,7 @@ password_mgr.add_password(None, OBS_base, user, passw) handler = urllib.request.HTTPBasicAuthHandler(password_mgr) opener = urllib.request.build_opener(handler) +urllib.request.install_opener(opener) def get_version_from_pypi(name: str, etag: str = None) -> Tuple[str, str, str]: @@ -63,8 +67,8 @@ def suse_packages(proj:str) -> Iterable[str]: """ Iterator returning names of all packages in the given proj - ETag management won't work here, because I don't like any way how to - return it in iterator. + ETag management won't work here, because I don't know about any way + how to return it in iterator. """ req = Request(url=OBS_base + f'/source/{proj}') @@ -161,15 +165,28 @@ def package_version(proj:str, pkg_name:str, else: raise - -if __name__=='__main__': - cutchars = len('python-') - project = 'devel:languages:python:singlespec-staging' - for pkg in suse_packages(project): - if pkg: - assert pkg.startswith('python-') - pypi_name = pkg[cutchars:] +def main(prj): + for pkg in suse_packages(prj): + log.debug(f'pkg = {pkg}') + if pkg.startswith('python-'): + pypi_name = pkg[CUTCHARS:] pypi_ver = get_version_from_pypi(pypi_name) - suse_ver = package_version(project, pkg) + suse_ver = package_version(prj, pkg) + # FIXME We should somehow react to the situation, not just + # ignore it. if suse_ver is not None: print(f"{pkg} {suse_ver} {pypi_ver}") + else: + print(f'Is {pkg} on PyPI?') + + +if __name__=='__main__': + parser = argparse.ArgumentParser(description='Check available versions ' + 'of the upstream packages on PyPI') + parser.add_argument('--opensuse-project', + default='devel:languages:python:numeric', + help='The OpenBuildService project. Defaults ' + 'to %(default)s') + + args = parser.parse_args() + sys.exit(main(args.opensuse_project)) |