From e72f715531044efddf7d59af8eacb724abba403d Mon Sep 17 00:00:00 2001 From: Veronika Kabatova Date: Mon, 3 Sep 2018 16:56:20 +0200 Subject: [PATCH] Unify get_patch_by_id Throw an exception if the requested patch can't be retrieved. This was already done for PatchworkV2Project but not PatchworkV1Project. Being unable to retrieve a patch previously known as existing signals a possible problem in sktm's logic, and it should be handled as such. The unification also allows to remove the return value checks when this method is used. Signed-off-by: Veronika Kabatova --- sktm/__init__.py | 3 --- sktm/patchwork.py | 29 +++++++++++++---------------- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/sktm/__init__.py b/sktm/__init__.py index 23dc84f..3a9fb96 100644 --- a/sktm/__init__.py +++ b/sktm/__init__.py @@ -206,9 +206,6 @@ def get_patch_info_from_url(self, interface, patch_url): baseurl = match.group(1) patch_id = int(match.group(2)) patch = interface.get_patch_by_id(patch_id) - if patch is None: - raise Exception('Can\'t get data for %s' % patch_url) - logging.info('patch: [%d] %s', patch_id, patch.get('name')) if isinstance(interface, sktm.patchwork.PatchworkV2Project): diff --git a/sktm/patchwork.py b/sktm/patchwork.py index 215913a..b5a729e 100644 --- a/sktm/patchwork.py +++ b/sktm/patchwork.py @@ -762,16 +762,15 @@ def get_patchsets(self, patchlist): # For each patch ID for pid in patchlist: patch = self.get_patch_by_id(pid) - if patch: - # For each series the patch belongs to - for series in patch.get("series"): - sid = series.get("id") - if sid not in seen: - series_list += self.__get_series_from_url( - join_with_slash(self.apiurls.get("series"), - str(sid)) - ) - seen.add(sid) + # For each series the patch belongs to + for series in patch.get("series"): + sid = series.get("id") + if sid not in seen: + series_list += self.__get_series_from_url( + join_with_slash(self.apiurls.get("series"), + str(sid)) + ) + seen.add(sid) return series_list @@ -908,8 +907,7 @@ def get_patch_by_id(self, pid): patch = self.rpc.patch_get(pid, self.fields) if patch is None or patch == {}: - logging.warning("Failed to get data for patch %d", pid) - patch = None + raise Exception('Can\'t get patch by id %d)'.format(pid)) self.__update_patch_name(patch) @@ -1169,8 +1167,7 @@ def get_patchsets(self, patchlist): logging.debug("get_patchsets: %s", patchlist) for pid in patchlist: patch = self.get_patch_by_id(pid) - if patch: - pset = self.__parse_patch(patch) - if pset: - series_list.append(pset) + pset = self.__parse_patch(patch) + if pset: + series_list.append(pset) return series_list