diff options
Diffstat (limited to 'dlpcvp.py')
-rwxr-xr-x | dlpcvp.py | 54 |
1 files changed, 30 insertions, 24 deletions
@@ -65,7 +65,7 @@ def get_version_from_pypi(name: str, etag: str = None) -> Tuple[str, str, str]: raise -def suse_packages(proj:str) -> Iterable[str]: +def suse_packages(proj: str) -> Iterable[str]: """ Iterator returning names of all packages in the given proj @@ -87,7 +87,30 @@ def suse_packages(proj:str) -> Iterable[str]: raise -def package_version(proj:str, pkg_name:str, +def parse_spec_in_dev_null(spec_file_name, pkg_name, etag_fn, etag_spcf): + # rpm library generates awfull lot of nonsensical goo on + # stderr + with open(os.devnull, 'wb') as nullf: + old_stderr = sys.stderr + old_stdout = sys.stdout + sys.stderr = nullf + sys.stdout = nullf + try: + spc = rpm.spec(spec_file_name) + except Exception: + log.error("Cannot parse {}".format(pkg_name)) + else: + try: + return spc.packages[0].header['Version'].decode(), \ + etag_fn, etag_spcf + except IndexError: + pass + finally: + sys.stderr = old_stderr + sys.stdout = old_stdout + + +def package_version(proj: str, pkg_name: str, etag_fn: str = None, etag_spcf: str = None) \ -> Optional[Tuple[str, str, str]]: """ @@ -122,7 +145,7 @@ def package_version(proj:str, pkg_name:str, try: spc_fname = sorted(spec_files, key=len)[0] except IndexError: - log.exception(f'Wrong value of spec_files: {spec_files}') + log.exception(f'Cannot find correct spec_files: {spec_files}') return req_spec = Request(url=OBS_base + f'/source/{proj}/{pkg_name}/{spc_fname}') @@ -141,32 +164,15 @@ def package_version(proj:str, pkg_name:str, spf.flush() os.fsync(spf.fileno()) - # rpm library generates awfull lot of nonsensical goo on - # stderr - with open(os.devnull, 'wb') as nullf: - old_stderr = sys.stderr - old_stdout = sys.stdout - sys.stderr = nullf - sys.stdout = nullf - try: - spc = rpm.spec(spec_file_name) - except Exception as ex: - log.error("Cannot parse {}".format(pkg_name)) - else: - try: - return spc.packages[0].header['Version'].decode(), \ - etag_fn, etag_spcf - except IndexError: - pass - finally: - sys.stderr = old_stderr - sys.stdout = old_stdout + return parse_spec_in_dev_null(spec_file_name, pkg_name, + etag_fn, etag_spcf) except HTTPError as ex: if ex.getcode() == 404: log.error(f'Cannot parse SPEC file {spc_fname} for {pkg_name}') else: raise + def main(prj): for pkg in suse_packages(prj): log.debug(f'pkg = {pkg}') @@ -182,7 +188,7 @@ def main(prj): print(f'Is {pkg} on PyPI?') -if __name__=='__main__': +if __name__ == '__main__': parser = argparse.ArgumentParser(description='Check available versions ' 'of the upstream packages on PyPI') parser.add_argument('--opensuse-project', |