diff options
-rwxr-xr-x | dlpcvp.py | 81 |
1 files changed, 50 insertions, 31 deletions
@@ -21,8 +21,7 @@ PyPI_base = "https://pypi.org/pypi/{}/json" # https://build.opensuse.org/apidocs/index OBS_base = "https://api.opensuse.org" OBS_realm = "Use your novell account" -ConfigRCs = [osp.expanduser('~/.oscrc'), - osp.expanduser('~/.config/osc/oscrc')] +ConfigRCs = [osp.expanduser('~/.oscrc'), osp.expanduser('~/.config/osc/oscrc')] CUTCHARS = len('python-') DBConnType = sqlite3.Connection @@ -31,8 +30,11 @@ OStr = Optional[str] config = configparser.ConfigParser() config.read(ConfigRCs) -logging.basicConfig(format='%(levelname)s:%(funcName)s:%(message)s', - stream=sys.stdout, level=logging.INFO) +logging.basicConfig( + format='%(levelname)s:%(funcName)s:%(message)s', + stream=sys.stdout, + level=logging.INFO, +) log = logging.getLogger() # or HTTPPasswordMgrWithPriorAuth ? @@ -43,7 +45,8 @@ password_mgr.add_password(OBS_realm, OBS_base, user, passw) auth_handler = urllib.request.HTTPBasicAuthHandler(password_mgr) ssl_handler = urllib.request.HTTPSHandler( - context=ssl._create_unverified_context()) + context=ssl._create_unverified_context() +) opener = urllib.request.build_opener(auth_handler, ssl_handler) urllib.request.install_opener(opener) @@ -97,8 +100,7 @@ def suse_packages(proj: str) -> Iterable[str]: raise -def get_etags(con: DBConnType, pkg: str) -> \ - Tuple[OStr, OStr, OStr, OStr]: +def get_etags(con: DBConnType, pkg: str) -> Tuple[OStr, OStr, OStr, OStr]: # pkg, suse_name_etag, suse_spec_etag, pypi_etag cur = con.execute("SELECT * FROM etags WHERE pkg=?", (pkg,)) ret = cur.fetchone() @@ -109,16 +111,24 @@ def get_etags(con: DBConnType, pkg: str) -> \ return ret -def update_etags(con: sqlite3.Connection, pkg: str, - e_suse_name: OStr, e_suse_spec: OStr, e_pypi: OStr): +def update_etags( + con: sqlite3.Connection, + pkg: str, + e_suse_name: OStr, + e_suse_spec: OStr, + e_pypi: OStr, +): res = con.execute("SELECT * FROM etags WHERE pkg=?", (pkg,)).fetchone() if res: e_suse_name = res[1] if e_suse_name is None else e_suse_name e_suse_spec = res[2] if e_suse_spec is None else e_suse_spec e_pypi = res[3] if e_pypi is None else e_pypi - con.execute('''REPLACE INTO etags + con.execute( + '''REPLACE INTO etags (pkg, suse_name_etag, suse_spec_etag, pypi_etag) - VALUES (?, ?, ?, ?)''', (pkg, e_suse_name, e_suse_spec, e_pypi)) + VALUES (?, ?, ?, ?)''', + (pkg, e_suse_name, e_suse_spec, e_pypi), + ) con.commit() @@ -130,9 +140,11 @@ def is_develpackage(proj: str, pkg: str) -> bool: xml_data = ET.parse(resp) for pel in xml_data.iter('package'): for delem in pel.iter('devel'): - if pel.attrib['name'] == pkg and \ - delem.attrib['package'] == pkg and \ - delem.attrib['project'] == proj: + if ( + pel.attrib['name'] == pkg + and delem.attrib['package'] == pkg + and delem.attrib['project'] == proj + ): return True return False except HTTPError as ex: @@ -150,14 +162,13 @@ def parse_spec(spec_file: Union[str, bytes]) -> LooseVersion: rest_of_line = '' for line in spec_file.splitlines(): if line.startswith('Version:'): - rest_of_line = line[len('Version:'):].strip() + rest_of_line = line[len('Version:') :].strip() break return LooseVersion(rest_of_line) -def get_spec_name(req: Request, proj: str, pkg: str, etag: OStr = None) -> \ - OStr: +def get_spec_name(req: Request, proj: str, pkg: str, etag: OStr = None) -> OStr: """Acquire version from the listing of the project directory. """ spec_files = [] # type: List[str] @@ -196,13 +207,15 @@ def get_spec_name(req: Request, proj: str, pkg: str, etag: OStr = None) -> \ return fname except IndexError: log.error( - f'{pkg} is most likely not a branch, but a link: ' + - f'use osc linktobranch {proj} {pkg} to convert it.') + f'{pkg} is most likely not a branch, but a link: ' + + f'use osc linktobranch {proj} {pkg} to convert it.' + ) return None -def get_version_from_pypi(name: str, con: DBConnType = None) -> \ - Optional[LooseVersion]: +def get_version_from_pypi( + name: str, con: DBConnType = None +) -> Optional[LooseVersion]: """ For the given name of module return the latest version available on PyPI. """ @@ -236,8 +249,9 @@ def get_version_from_pypi(name: str, con: DBConnType = None) -> \ return None -def package_version(proj: str, pkgn: str, - con: DBConnType = None) -> Optional[LooseVersion]: +def package_version( + proj: str, pkgn: str, con: DBConnType = None +) -> Optional[LooseVersion]: """ Return the version of the given package in the given proj. @@ -256,8 +270,9 @@ def package_version(proj: str, pkgn: str, if spc_fname is None: return None - req_spec = Request(url=OBS_base + - f'/source/{proj}/{pkgn}/{spc_fname}?expand=1') + req_spec = Request( + url=OBS_base + f'/source/{proj}/{pkgn}/{spc_fname}?expand=1' + ) if etag_spcf is not None: req_spc_name.add_header('ETag', etag_spcf) @@ -338,12 +353,16 @@ def main(prj): if __name__ == '__main__': - parser = argparse.ArgumentParser(description='Check available versions ' - 'of the upstream packages on PyPI') - parser.add_argument('project', nargs='?', - default='devel:languages:python:numeric', - help='The OpenBuildService project. Defaults ' - 'to %(default)s') + parser = argparse.ArgumentParser( + description='Check available versions ' + 'of the upstream packages on PyPI' + ) + parser.add_argument( + 'project', + nargs='?', + default='devel:languages:python:numeric', + help='The OpenBuildService project. Defaults ' 'to %(default)s', + ) args = parser.parse_args() sys.exit(main(args.project)) |