aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2019-03-04 15:05:48 +0100
committerMatěj Cepl <mcepl@cepl.eu>2019-03-04 15:05:48 +0100
commit073609f2db76c08d26b6084427eb4b76c27dda55 (patch)
treeebe1a0a81c6adb0f73514f4be63ab65d7df952bd
parent73ac215ce8de9cfc372b02189503d3c40e9d1df0 (diff)
downloaddlp_check_version_PyPI-073609f2db76c08d26b6084427eb4b76c27dda55.tar.gz
Improve reporting
-rwxr-xr-xdlpcvp.py34
1 files changed, 20 insertions, 14 deletions
diff --git a/dlpcvp.py b/dlpcvp.py
index cc6e9c0..33fec00 100755
--- a/dlpcvp.py
+++ b/dlpcvp.py
@@ -95,6 +95,7 @@ def get_etags(con: DBConnType, pkg: str) -> \
# pkg, suse_name_etag, suse_spec_etag, pypi_etag
cur = con.execute("SELECT * FROM etags WHERE pkg=?", (pkg,))
ret = cur.fetchone()
+ log.debug(f'ret = {ret}')
if ret is None:
return None, None, None, None
else:
@@ -127,7 +128,7 @@ def parse_spec(spec_file: str, pkg: str) -> LooseVersion:
return LooseVersion(rest_of_line)
-def get_spec_name(req: Request, pkg: str, etag: str = None) -> OStr:
+def get_spec_name(req: Request, proj: str, pkg: str, etag: str = None) -> OStr:
"""Acquire version from the listing of the project directory.
"""
spec_files = [] # type: List[str]
@@ -158,8 +159,9 @@ def get_spec_name(req: Request, pkg: str, etag: str = None) -> OStr:
fname = sorted(spec_files, key=len)[0]
return fname
except IndexError:
- log.exception(
- f'Cannot find correct spec_files: {spec_files} ({type(spec_files)}) for {pkg}')
+ log.error(
+ f'{pkg} is most likely not a branch, but a link: ' +
+ f'use osc linktobranch {proj} {pkg} to convert it.')
return None
@@ -181,8 +183,9 @@ def get_version_from_pypi(name: str, con: DBConnType = None) -> Optional[LooseVe
with urlopen(req) as resp:
data = json.load(resp)
info_dict = data['info']
- if con:
- update_etags(con, name, None, None, str(resp.info()['ETag']))
+ curr_etag = str(resp.info()['ETag'])
+ if curr_etag:
+ update_etags(con, name, None, None, curr_etag)
return LooseVersion(info_dict['version'])
except HTTPError as ex:
if ex.getcode() == 404:
@@ -192,7 +195,7 @@ def get_version_from_pypi(name: str, con: DBConnType = None) -> Optional[LooseVe
return None
-def package_version(proj: str, pkg_name: str,
+def package_version(proj: str, pkgn: str,
con: DBConnType = None) -> Optional[LooseVersion]:
"""
Return the version of the given package in the given proj.
@@ -201,15 +204,16 @@ def package_version(proj: str, pkg_name: str,
"""
# pkg, suse_name_etag, suse_spec_etag, pypi_etag
if con:
- _, etag_fn, etag_spcf, _ = get_etags(con, pkg_name)
+ _, etag_fn, etag_spcf, _ = get_etags(con, pkgn)
else:
etag_fn, etag_spcf = None, None
# Get listing of the package repository
- req_spc_name = Request(url=OBS_base + f'/source/{proj}/{pkg_name}')
- spc_fname = get_spec_name(req_spc_name, pkg_name, etag_fn)
+ req_spc_name = Request(url=OBS_base + f'/source/{proj}/{pkgn}?expand=1')
+ spc_fname = get_spec_name(req_spc_name, proj, pkgn, etag_fn)
- req_spec = Request(url=OBS_base + f'/source/{proj}/{pkg_name}/{spc_fname}')
+ 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)
@@ -217,14 +221,15 @@ def package_version(proj: str, pkg_name: str,
try:
with opener.open(req_spec) as resp:
etag_spcf = str(resp.info()['ETag'])
+ etag_spcf = None if not etag_spcf else etag_spcf
spec_file_str = resp.read().decode()
- if con:
- update_etags(con, pkg_name, etag_fn, etag_spcf, None)
- return parse_spec(spec_file_str, pkg_name)
+ if etag_spcf or etag_fn:
+ update_etags(con, pkgn, etag_fn, etag_spcf, None)
+ return parse_spec(spec_file_str, pkgn)
except HTTPError as ex:
if ex.getcode() == 404:
- log.warning(f'Cannot parse SPEC file {spc_fname} for {pkg_name}')
+ log.warning(f'Cannot parse SPEC file {spc_fname} for {pkgn}')
else:
raise
return None
@@ -285,3 +290,4 @@ if __name__ == '__main__':
args = parser.parse_args()
sys.exit(main(args.project))
+