aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xdlpcvp.py19
1 files changed, 13 insertions, 6 deletions
diff --git a/dlpcvp.py b/dlpcvp.py
index bc47082..32702eb 100755
--- a/dlpcvp.py
+++ b/dlpcvp.py
@@ -13,7 +13,6 @@ from typing import Iterable, List, Optional, Tuple, Union
from urllib.error import HTTPError
from urllib.request import Request, urlopen
-
# PyPI API documentation https://warehouse.readthedocs.io/api-reference/
PyPI_base = "https://pypi.org/pypi/{}/json"
# https://github.com/openSUSE/open-build-service/blob/master/docs/api/api/api.txt
@@ -76,6 +75,10 @@ def suse_packages(proj: str) -> Iterable[str]:
root = raw_xml_data.getroot()
for elem in root.iter('entry'):
pkg_name = elem.get('name')
+ # Invalid packages are skipped
+ if pkg_name is None:
+ log.warning(f"Package {elem} doesn’t have a name!")
+ continue
# We don't want -doc subpackages
if pkg_name.endswith('-doc'):
continue
@@ -167,6 +170,10 @@ def get_spec_name(req: Request, proj: str, pkg: str, etag: OStr = None) -> OStr:
root = raw_xml_data.getroot()
for elem in root.iter('entry'):
name = elem.get('name')
+ # Invalid package
+ if name is None:
+ log.warning(f"Package {elem} doesn’t have a name!")
+ return None
if name.endswith('.spec'):
spec_files.append(name)
if name == '_aggregate':
@@ -194,10 +201,10 @@ def get_version_from_pypi(name: str, con: DBConnType = None) -> Optional[LooseVe
For the given name of module return the latest version available on PyPI.
"""
# pkg, suse_name_etag, suse_spec_etag, pypi_etag
- if con:
- _, _, _, etag = get_etags(con, name)
- else:
+ if con is None:
etag = None
+ else:
+ _, _, _, etag = get_etags(con, name)
req = Request(url=PyPI_base.format(name))
if etag is not None:
@@ -208,7 +215,7 @@ def get_version_from_pypi(name: str, con: DBConnType = None) -> Optional[LooseVe
data = json.load(resp)
info_dict = data['info']
curr_etag = str(resp.info()['ETag'])
- if curr_etag:
+ if (con is not None) and curr_etag:
update_etags(con, name, None, None, curr_etag)
# Cleanup version
@@ -255,7 +262,7 @@ def package_version(proj: str, pkgn: str,
etag_spcf = None if not etag_spcf else etag_spcf
spec_file_str = resp.read().decode()
- if etag_spcf or etag_fn:
+ if (con is not None) and (etag_spcf or etag_fn):
update_etags(con, pkgn, etag_fn, etag_spcf, None)
return parse_spec(spec_file_str)
except HTTPError as ex: