This repository has been archived by the owner on Sep 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
patchwork cleanups and enhacements #137
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bea14be
Composition fixups for _get_project_id
veruu 289d3fb
Removed unused nsince attribute
veruu 33badb3
Make exception format strings non-lazy
veruu 1505e91
Remove unsolvable FIXMEs
veruu 6414e2a
Unify lastpatch option between Patchwork versions
veruu e72f715
Unify get_patch_by_id
veruu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -418,33 +418,46 @@ def _get_mbox_url_sfx(self): | |
|
||
return "mbox" | ||
|
||
def _get_project_id(self, project_name): | ||
""" | ||
Get project ID based on its name. Child classes need to implement | ||
this method. | ||
|
||
Args: | ||
project_name: The name of the project to retrieve. | ||
|
||
Returns: | ||
Integer representing project's ID. | ||
""" | ||
raise NotImplementedError | ||
|
||
|
||
class PatchworkV2Project(PatchworkProject): | ||
""" | ||
A Patchwork REST interface | ||
""" | ||
def __init__(self, baseurl, projectname, since, apikey=None, skip=[]): | ||
def __init__(self, baseurl, projectname, lastpatch, apikey=None, skip=[]): | ||
""" | ||
Initialize a Patchwork REST interface. | ||
|
||
Args: | ||
baseurl: Patchwork base URL. | ||
projectname: Patchwork project name, or None. | ||
since: Last processed patch timestamp in a format | ||
accepted by dateutil.parser.parse. Patches with | ||
this or earlier timestamp will be ignored. | ||
lastpatch: ID of the last processed patch. Only patches newer | ||
than this one will be processed. | ||
apikey: Patchwork API authentication token. | ||
skip: List of additional regex patterns to skip in patch | ||
names, case insensitive. | ||
""" | ||
# Last processed patch timestamp in a dateutil.parser.parse format | ||
self.since = since | ||
# TODO Describe | ||
self.nsince = None | ||
# Patchwork API authentication token. | ||
self.apikey = apikey | ||
# JSON representation of API URLs retrieved from the Patchwork server | ||
self.apiurls = self.__get_apiurls(baseurl) | ||
# Get the datetime of the passed lastpatch to use in patch filtering | ||
if lastpatch: | ||
self.since = self.get_patch_by_id(lastpatch).get('date') | ||
else: | ||
self.since = None | ||
super(PatchworkV2Project, self).__init__(baseurl, projectname, skip) | ||
|
||
def _get_project_id(self, project_name): | ||
|
@@ -749,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 | ||
|
||
|
@@ -819,7 +831,7 @@ def __get_rpc(self, baseurl): | |
ver = rpc.pw_rpc_version() | ||
# check for normal patchwork1 xmlrpc version numbers | ||
if not (ver == [1, 3, 0] or ver == 1): | ||
raise Exception("Unknown xmlrpc version %s", ver) | ||
raise Exception("Unknown xmlrpc version %s" % ver) | ||
|
||
except xmlrpclib.Fault as err: | ||
if err.faultCode == 1 and \ | ||
|
@@ -828,14 +840,14 @@ def __get_rpc(self, baseurl): | |
rpc = RpcWrapper(rpc) | ||
ver = rpc.pw_rpc_version() | ||
if ver < 1010: | ||
raise Exception("Unsupported xmlrpc version %s", ver) | ||
raise Exception("Unsupported xmlrpc version %s" % ver) | ||
|
||
# grab extra info for later parsing | ||
self.fields = ['id', 'name', 'submitter', 'msgid', | ||
['root_comment', ['headers']], | ||
'date', 'project_id'] | ||
else: | ||
raise Exception("Unknown xmlrpc fault: %s", err.faultString) | ||
raise Exception("Unknown xmlrpc fault: %s" % err.faultString) | ||
|
||
return rpc | ||
|
||
|
@@ -895,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)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Niiice 👍 |
||
|
||
self.__update_patch_name(patch) | ||
|
||
|
@@ -942,28 +953,28 @@ def set_patch_check(self, pid, jurl, result): | |
pass | ||
|
||
# TODO Move this to __init__ or make it a class method | ||
def _get_project_id(self, projectname): | ||
def _get_project_id(self, project_name): | ||
""" | ||
Retrieve ID of the project with the specified name. | ||
|
||
Args: | ||
projectname: The name of the project to retrieve ID for. | ||
project_name: The name of the project to retrieve ID for. | ||
|
||
Returns: | ||
The project name. | ||
Integer representing project's ID. | ||
|
||
Raises: | ||
A string containing an error message, if the project with the | ||
specified name was not found. | ||
""" | ||
plist = self.rpc.project_list(projectname) | ||
plist = self.rpc.project_list(project_name) | ||
for project in plist: | ||
if project.get("linkname") == projectname: | ||
if project.get("linkname") == project_name: | ||
pid = int(project.get("id")) | ||
logging.debug("%s -> %d", projectname, pid) | ||
logging.debug("%s -> %d", project_name, pid) | ||
return pid | ||
|
||
raise Exception("Couldn't find project %s" % projectname) | ||
raise Exception("Couldn't find project %s" % project_name) | ||
|
||
# FIXME This doesn't just parse a patch. Name/refactor accordingly. | ||
def __parse_patch(self, patch): | ||
|
@@ -1156,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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aaah, finally, thank you 😌