partition
stringclasses 3
values | func_name
stringlengths 1
134
| docstring
stringlengths 1
46.9k
| path
stringlengths 4
223
| original_string
stringlengths 75
104k
| code
stringlengths 75
104k
| docstring_tokens
listlengths 1
1.97k
| repo
stringlengths 7
55
| language
stringclasses 1
value | url
stringlengths 87
315
| code_tokens
listlengths 19
28.4k
| sha
stringlengths 40
40
|
|---|---|---|---|---|---|---|---|---|---|---|---|
test
|
GitLab.__get_award_emoji
|
Get award emojis for issue/merge request
|
perceval/backends/core/gitlab.py
|
def __get_award_emoji(self, item_type, item_id):
"""Get award emojis for issue/merge request"""
emojis = []
group_emojis = self.client.emojis(item_type, item_id)
for raw_emojis in group_emojis:
for emoji in json.loads(raw_emojis):
emojis.append(emoji)
return emojis
|
def __get_award_emoji(self, item_type, item_id):
"""Get award emojis for issue/merge request"""
emojis = []
group_emojis = self.client.emojis(item_type, item_id)
for raw_emojis in group_emojis:
for emoji in json.loads(raw_emojis):
emojis.append(emoji)
return emojis
|
[
"Get",
"award",
"emojis",
"for",
"issue",
"/",
"merge",
"request"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/gitlab.py#L311-L322
|
[
"def",
"__get_award_emoji",
"(",
"self",
",",
"item_type",
",",
"item_id",
")",
":",
"emojis",
"=",
"[",
"]",
"group_emojis",
"=",
"self",
".",
"client",
".",
"emojis",
"(",
"item_type",
",",
"item_id",
")",
"for",
"raw_emojis",
"in",
"group_emojis",
":",
"for",
"emoji",
"in",
"json",
".",
"loads",
"(",
"raw_emojis",
")",
":",
"emojis",
".",
"append",
"(",
"emoji",
")",
"return",
"emojis"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
GitLab.__get_note_award_emoji
|
Fetch emojis for a note of an issue/merge request
|
perceval/backends/core/gitlab.py
|
def __get_note_award_emoji(self, item_type, item_id, note_id):
"""Fetch emojis for a note of an issue/merge request"""
emojis = []
group_emojis = self.client.note_emojis(item_type, item_id, note_id)
try:
for raw_emojis in group_emojis:
for emoji in json.loads(raw_emojis):
emojis.append(emoji)
except requests.exceptions.HTTPError as error:
if error.response.status_code == 404:
logger.warning("Emojis not available for %s ",
urijoin(item_type, str(item_id), GitLabClient.NOTES,
str(note_id), GitLabClient.EMOJI))
return emojis
return emojis
|
def __get_note_award_emoji(self, item_type, item_id, note_id):
"""Fetch emojis for a note of an issue/merge request"""
emojis = []
group_emojis = self.client.note_emojis(item_type, item_id, note_id)
try:
for raw_emojis in group_emojis:
for emoji in json.loads(raw_emojis):
emojis.append(emoji)
except requests.exceptions.HTTPError as error:
if error.response.status_code == 404:
logger.warning("Emojis not available for %s ",
urijoin(item_type, str(item_id), GitLabClient.NOTES,
str(note_id), GitLabClient.EMOJI))
return emojis
return emojis
|
[
"Fetch",
"emojis",
"for",
"a",
"note",
"of",
"an",
"issue",
"/",
"merge",
"request"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/gitlab.py#L324-L342
|
[
"def",
"__get_note_award_emoji",
"(",
"self",
",",
"item_type",
",",
"item_id",
",",
"note_id",
")",
":",
"emojis",
"=",
"[",
"]",
"group_emojis",
"=",
"self",
".",
"client",
".",
"note_emojis",
"(",
"item_type",
",",
"item_id",
",",
"note_id",
")",
"try",
":",
"for",
"raw_emojis",
"in",
"group_emojis",
":",
"for",
"emoji",
"in",
"json",
".",
"loads",
"(",
"raw_emojis",
")",
":",
"emojis",
".",
"append",
"(",
"emoji",
")",
"except",
"requests",
".",
"exceptions",
".",
"HTTPError",
"as",
"error",
":",
"if",
"error",
".",
"response",
".",
"status_code",
"==",
"404",
":",
"logger",
".",
"warning",
"(",
"\"Emojis not available for %s \"",
",",
"urijoin",
"(",
"item_type",
",",
"str",
"(",
"item_id",
")",
",",
"GitLabClient",
".",
"NOTES",
",",
"str",
"(",
"note_id",
")",
",",
"GitLabClient",
".",
"EMOJI",
")",
")",
"return",
"emojis",
"return",
"emojis"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
GitLabClient.issues
|
Get the issues from pagination
|
perceval/backends/core/gitlab.py
|
def issues(self, from_date=None):
"""Get the issues from pagination"""
payload = {
'state': 'all',
'order_by': 'updated_at',
'sort': 'asc',
'per_page': PER_PAGE
}
if from_date:
payload['updated_after'] = from_date.isoformat()
return self.fetch_items(GitLabClient.ISSUES, payload)
|
def issues(self, from_date=None):
"""Get the issues from pagination"""
payload = {
'state': 'all',
'order_by': 'updated_at',
'sort': 'asc',
'per_page': PER_PAGE
}
if from_date:
payload['updated_after'] = from_date.isoformat()
return self.fetch_items(GitLabClient.ISSUES, payload)
|
[
"Get",
"the",
"issues",
"from",
"pagination"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/gitlab.py#L416-L429
|
[
"def",
"issues",
"(",
"self",
",",
"from_date",
"=",
"None",
")",
":",
"payload",
"=",
"{",
"'state'",
":",
"'all'",
",",
"'order_by'",
":",
"'updated_at'",
",",
"'sort'",
":",
"'asc'",
",",
"'per_page'",
":",
"PER_PAGE",
"}",
"if",
"from_date",
":",
"payload",
"[",
"'updated_after'",
"]",
"=",
"from_date",
".",
"isoformat",
"(",
")",
"return",
"self",
".",
"fetch_items",
"(",
"GitLabClient",
".",
"ISSUES",
",",
"payload",
")"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
GitLabClient.merges
|
Get the merge requests from pagination
|
perceval/backends/core/gitlab.py
|
def merges(self, from_date=None):
"""Get the merge requests from pagination"""
payload = {
'state': 'all',
'order_by': 'updated_at',
'sort': 'asc',
'view': 'simple',
'per_page': PER_PAGE
}
if from_date:
payload['updated_after'] = from_date.isoformat()
return self.fetch_items(GitLabClient.MERGES, payload)
|
def merges(self, from_date=None):
"""Get the merge requests from pagination"""
payload = {
'state': 'all',
'order_by': 'updated_at',
'sort': 'asc',
'view': 'simple',
'per_page': PER_PAGE
}
if from_date:
payload['updated_after'] = from_date.isoformat()
return self.fetch_items(GitLabClient.MERGES, payload)
|
[
"Get",
"the",
"merge",
"requests",
"from",
"pagination"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/gitlab.py#L431-L445
|
[
"def",
"merges",
"(",
"self",
",",
"from_date",
"=",
"None",
")",
":",
"payload",
"=",
"{",
"'state'",
":",
"'all'",
",",
"'order_by'",
":",
"'updated_at'",
",",
"'sort'",
":",
"'asc'",
",",
"'view'",
":",
"'simple'",
",",
"'per_page'",
":",
"PER_PAGE",
"}",
"if",
"from_date",
":",
"payload",
"[",
"'updated_after'",
"]",
"=",
"from_date",
".",
"isoformat",
"(",
")",
"return",
"self",
".",
"fetch_items",
"(",
"GitLabClient",
".",
"MERGES",
",",
"payload",
")"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
GitLabClient.merge
|
Get the merge full data
|
perceval/backends/core/gitlab.py
|
def merge(self, merge_id):
"""Get the merge full data"""
path = urijoin(self.base_url,
GitLabClient.PROJECTS, self.owner + '%2F' + self.repository,
GitLabClient.MERGES, merge_id)
response = self.fetch(path)
return response.text
|
def merge(self, merge_id):
"""Get the merge full data"""
path = urijoin(self.base_url,
GitLabClient.PROJECTS, self.owner + '%2F' + self.repository,
GitLabClient.MERGES, merge_id)
response = self.fetch(path)
return response.text
|
[
"Get",
"the",
"merge",
"full",
"data"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/gitlab.py#L447-L456
|
[
"def",
"merge",
"(",
"self",
",",
"merge_id",
")",
":",
"path",
"=",
"urijoin",
"(",
"self",
".",
"base_url",
",",
"GitLabClient",
".",
"PROJECTS",
",",
"self",
".",
"owner",
"+",
"'%2F'",
"+",
"self",
".",
"repository",
",",
"GitLabClient",
".",
"MERGES",
",",
"merge_id",
")",
"response",
"=",
"self",
".",
"fetch",
"(",
"path",
")",
"return",
"response",
".",
"text"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
GitLabClient.merge_versions
|
Get the merge versions from pagination
|
perceval/backends/core/gitlab.py
|
def merge_versions(self, merge_id):
"""Get the merge versions from pagination"""
payload = {
'order_by': 'updated_at',
'sort': 'asc',
'per_page': PER_PAGE
}
path = urijoin(GitLabClient.MERGES, str(merge_id), GitLabClient.VERSIONS)
return self.fetch_items(path, payload)
|
def merge_versions(self, merge_id):
"""Get the merge versions from pagination"""
payload = {
'order_by': 'updated_at',
'sort': 'asc',
'per_page': PER_PAGE
}
path = urijoin(GitLabClient.MERGES, str(merge_id), GitLabClient.VERSIONS)
return self.fetch_items(path, payload)
|
[
"Get",
"the",
"merge",
"versions",
"from",
"pagination"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/gitlab.py#L458-L468
|
[
"def",
"merge_versions",
"(",
"self",
",",
"merge_id",
")",
":",
"payload",
"=",
"{",
"'order_by'",
":",
"'updated_at'",
",",
"'sort'",
":",
"'asc'",
",",
"'per_page'",
":",
"PER_PAGE",
"}",
"path",
"=",
"urijoin",
"(",
"GitLabClient",
".",
"MERGES",
",",
"str",
"(",
"merge_id",
")",
",",
"GitLabClient",
".",
"VERSIONS",
")",
"return",
"self",
".",
"fetch_items",
"(",
"path",
",",
"payload",
")"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
GitLabClient.merge_version
|
Get merge version detail
|
perceval/backends/core/gitlab.py
|
def merge_version(self, merge_id, version_id):
"""Get merge version detail"""
path = urijoin(self.base_url,
GitLabClient.PROJECTS, self.owner + '%2F' + self.repository,
GitLabClient.MERGES, merge_id, GitLabClient.VERSIONS, version_id)
response = self.fetch(path)
return response.text
|
def merge_version(self, merge_id, version_id):
"""Get merge version detail"""
path = urijoin(self.base_url,
GitLabClient.PROJECTS, self.owner + '%2F' + self.repository,
GitLabClient.MERGES, merge_id, GitLabClient.VERSIONS, version_id)
response = self.fetch(path)
return response.text
|
[
"Get",
"merge",
"version",
"detail"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/gitlab.py#L470-L479
|
[
"def",
"merge_version",
"(",
"self",
",",
"merge_id",
",",
"version_id",
")",
":",
"path",
"=",
"urijoin",
"(",
"self",
".",
"base_url",
",",
"GitLabClient",
".",
"PROJECTS",
",",
"self",
".",
"owner",
"+",
"'%2F'",
"+",
"self",
".",
"repository",
",",
"GitLabClient",
".",
"MERGES",
",",
"merge_id",
",",
"GitLabClient",
".",
"VERSIONS",
",",
"version_id",
")",
"response",
"=",
"self",
".",
"fetch",
"(",
"path",
")",
"return",
"response",
".",
"text"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
GitLabClient.notes
|
Get the notes from pagination
|
perceval/backends/core/gitlab.py
|
def notes(self, item_type, item_id):
"""Get the notes from pagination"""
payload = {
'order_by': 'updated_at',
'sort': 'asc',
'per_page': PER_PAGE
}
path = urijoin(item_type, str(item_id), GitLabClient.NOTES)
return self.fetch_items(path, payload)
|
def notes(self, item_type, item_id):
"""Get the notes from pagination"""
payload = {
'order_by': 'updated_at',
'sort': 'asc',
'per_page': PER_PAGE
}
path = urijoin(item_type, str(item_id), GitLabClient.NOTES)
return self.fetch_items(path, payload)
|
[
"Get",
"the",
"notes",
"from",
"pagination"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/gitlab.py#L481-L492
|
[
"def",
"notes",
"(",
"self",
",",
"item_type",
",",
"item_id",
")",
":",
"payload",
"=",
"{",
"'order_by'",
":",
"'updated_at'",
",",
"'sort'",
":",
"'asc'",
",",
"'per_page'",
":",
"PER_PAGE",
"}",
"path",
"=",
"urijoin",
"(",
"item_type",
",",
"str",
"(",
"item_id",
")",
",",
"GitLabClient",
".",
"NOTES",
")",
"return",
"self",
".",
"fetch_items",
"(",
"path",
",",
"payload",
")"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
GitLabClient.emojis
|
Get emojis from pagination
|
perceval/backends/core/gitlab.py
|
def emojis(self, item_type, item_id):
"""Get emojis from pagination"""
payload = {
'order_by': 'updated_at',
'sort': 'asc',
'per_page': PER_PAGE
}
path = urijoin(item_type, str(item_id), GitLabClient.EMOJI)
return self.fetch_items(path, payload)
|
def emojis(self, item_type, item_id):
"""Get emojis from pagination"""
payload = {
'order_by': 'updated_at',
'sort': 'asc',
'per_page': PER_PAGE
}
path = urijoin(item_type, str(item_id), GitLabClient.EMOJI)
return self.fetch_items(path, payload)
|
[
"Get",
"emojis",
"from",
"pagination"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/gitlab.py#L494-L505
|
[
"def",
"emojis",
"(",
"self",
",",
"item_type",
",",
"item_id",
")",
":",
"payload",
"=",
"{",
"'order_by'",
":",
"'updated_at'",
",",
"'sort'",
":",
"'asc'",
",",
"'per_page'",
":",
"PER_PAGE",
"}",
"path",
"=",
"urijoin",
"(",
"item_type",
",",
"str",
"(",
"item_id",
")",
",",
"GitLabClient",
".",
"EMOJI",
")",
"return",
"self",
".",
"fetch_items",
"(",
"path",
",",
"payload",
")"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
GitLabClient.note_emojis
|
Get emojis of a note
|
perceval/backends/core/gitlab.py
|
def note_emojis(self, item_type, item_id, note_id):
"""Get emojis of a note"""
payload = {
'order_by': 'updated_at',
'sort': 'asc',
'per_page': PER_PAGE
}
path = urijoin(item_type, str(item_id), GitLabClient.NOTES,
str(note_id), GitLabClient.EMOJI)
return self.fetch_items(path, payload)
|
def note_emojis(self, item_type, item_id, note_id):
"""Get emojis of a note"""
payload = {
'order_by': 'updated_at',
'sort': 'asc',
'per_page': PER_PAGE
}
path = urijoin(item_type, str(item_id), GitLabClient.NOTES,
str(note_id), GitLabClient.EMOJI)
return self.fetch_items(path, payload)
|
[
"Get",
"emojis",
"of",
"a",
"note"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/gitlab.py#L507-L519
|
[
"def",
"note_emojis",
"(",
"self",
",",
"item_type",
",",
"item_id",
",",
"note_id",
")",
":",
"payload",
"=",
"{",
"'order_by'",
":",
"'updated_at'",
",",
"'sort'",
":",
"'asc'",
",",
"'per_page'",
":",
"PER_PAGE",
"}",
"path",
"=",
"urijoin",
"(",
"item_type",
",",
"str",
"(",
"item_id",
")",
",",
"GitLabClient",
".",
"NOTES",
",",
"str",
"(",
"note_id",
")",
",",
"GitLabClient",
".",
"EMOJI",
")",
"return",
"self",
".",
"fetch_items",
"(",
"path",
",",
"payload",
")"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
GitLabClient.calculate_time_to_reset
|
Calculate the seconds to reset the token requests, by obtaining the different
between the current date and the next date when the token is fully regenerated.
|
perceval/backends/core/gitlab.py
|
def calculate_time_to_reset(self):
"""Calculate the seconds to reset the token requests, by obtaining the different
between the current date and the next date when the token is fully regenerated.
"""
time_to_reset = self.rate_limit_reset_ts - (datetime_utcnow().replace(microsecond=0).timestamp() + 1)
if time_to_reset < 0:
time_to_reset = 0
return time_to_reset
|
def calculate_time_to_reset(self):
"""Calculate the seconds to reset the token requests, by obtaining the different
between the current date and the next date when the token is fully regenerated.
"""
time_to_reset = self.rate_limit_reset_ts - (datetime_utcnow().replace(microsecond=0).timestamp() + 1)
if time_to_reset < 0:
time_to_reset = 0
return time_to_reset
|
[
"Calculate",
"the",
"seconds",
"to",
"reset",
"the",
"token",
"requests",
"by",
"obtaining",
"the",
"different",
"between",
"the",
"current",
"date",
"and",
"the",
"next",
"date",
"when",
"the",
"token",
"is",
"fully",
"regenerated",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/gitlab.py#L521-L531
|
[
"def",
"calculate_time_to_reset",
"(",
"self",
")",
":",
"time_to_reset",
"=",
"self",
".",
"rate_limit_reset_ts",
"-",
"(",
"datetime_utcnow",
"(",
")",
".",
"replace",
"(",
"microsecond",
"=",
"0",
")",
".",
"timestamp",
"(",
")",
"+",
"1",
")",
"if",
"time_to_reset",
"<",
"0",
":",
"time_to_reset",
"=",
"0",
"return",
"time_to_reset"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
GitLabClient.fetch
|
Fetch the data from a given URL.
:param url: link to the resource
:param payload: payload of the request
:param headers: headers of the request
:param method: type of request call (GET or POST)
:param stream: defer downloading the response body until the response content is available
:returns a response object
|
perceval/backends/core/gitlab.py
|
def fetch(self, url, payload=None, headers=None, method=HttpClient.GET, stream=False):
"""Fetch the data from a given URL.
:param url: link to the resource
:param payload: payload of the request
:param headers: headers of the request
:param method: type of request call (GET or POST)
:param stream: defer downloading the response body until the response content is available
:returns a response object
"""
if not self.from_archive:
self.sleep_for_rate_limit()
response = super().fetch(url, payload, headers, method, stream)
if not self.from_archive:
self.update_rate_limit(response)
return response
|
def fetch(self, url, payload=None, headers=None, method=HttpClient.GET, stream=False):
"""Fetch the data from a given URL.
:param url: link to the resource
:param payload: payload of the request
:param headers: headers of the request
:param method: type of request call (GET or POST)
:param stream: defer downloading the response body until the response content is available
:returns a response object
"""
if not self.from_archive:
self.sleep_for_rate_limit()
response = super().fetch(url, payload, headers, method, stream)
if not self.from_archive:
self.update_rate_limit(response)
return response
|
[
"Fetch",
"the",
"data",
"from",
"a",
"given",
"URL",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/gitlab.py#L533-L552
|
[
"def",
"fetch",
"(",
"self",
",",
"url",
",",
"payload",
"=",
"None",
",",
"headers",
"=",
"None",
",",
"method",
"=",
"HttpClient",
".",
"GET",
",",
"stream",
"=",
"False",
")",
":",
"if",
"not",
"self",
".",
"from_archive",
":",
"self",
".",
"sleep_for_rate_limit",
"(",
")",
"response",
"=",
"super",
"(",
")",
".",
"fetch",
"(",
"url",
",",
"payload",
",",
"headers",
",",
"method",
",",
"stream",
")",
"if",
"not",
"self",
".",
"from_archive",
":",
"self",
".",
"update_rate_limit",
"(",
"response",
")",
"return",
"response"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
GitLabClient.fetch_items
|
Return the items from GitLab API using links pagination
|
perceval/backends/core/gitlab.py
|
def fetch_items(self, path, payload):
"""Return the items from GitLab API using links pagination"""
page = 0 # current page
last_page = None # last page
url_next = urijoin(self.base_url, GitLabClient.PROJECTS, self.owner + '%2F' + self.repository, path)
logger.debug("Get GitLab paginated items from " + url_next)
response = self.fetch(url_next, payload=payload)
items = response.text
page += 1
if 'last' in response.links:
last_url = response.links['last']['url']
last_page = last_url.split('&page=')[1].split('&')[0]
last_page = int(last_page)
logger.debug("Page: %i/%i" % (page, last_page))
while items:
yield items
items = None
if 'next' in response.links:
url_next = response.links['next']['url'] # Loving requests :)
response = self.fetch(url_next, payload=payload)
page += 1
items = response.text
logger.debug("Page: %i/%i" % (page, last_page))
|
def fetch_items(self, path, payload):
"""Return the items from GitLab API using links pagination"""
page = 0 # current page
last_page = None # last page
url_next = urijoin(self.base_url, GitLabClient.PROJECTS, self.owner + '%2F' + self.repository, path)
logger.debug("Get GitLab paginated items from " + url_next)
response = self.fetch(url_next, payload=payload)
items = response.text
page += 1
if 'last' in response.links:
last_url = response.links['last']['url']
last_page = last_url.split('&page=')[1].split('&')[0]
last_page = int(last_page)
logger.debug("Page: %i/%i" % (page, last_page))
while items:
yield items
items = None
if 'next' in response.links:
url_next = response.links['next']['url'] # Loving requests :)
response = self.fetch(url_next, payload=payload)
page += 1
items = response.text
logger.debug("Page: %i/%i" % (page, last_page))
|
[
"Return",
"the",
"items",
"from",
"GitLab",
"API",
"using",
"links",
"pagination"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/gitlab.py#L554-L585
|
[
"def",
"fetch_items",
"(",
"self",
",",
"path",
",",
"payload",
")",
":",
"page",
"=",
"0",
"# current page",
"last_page",
"=",
"None",
"# last page",
"url_next",
"=",
"urijoin",
"(",
"self",
".",
"base_url",
",",
"GitLabClient",
".",
"PROJECTS",
",",
"self",
".",
"owner",
"+",
"'%2F'",
"+",
"self",
".",
"repository",
",",
"path",
")",
"logger",
".",
"debug",
"(",
"\"Get GitLab paginated items from \"",
"+",
"url_next",
")",
"response",
"=",
"self",
".",
"fetch",
"(",
"url_next",
",",
"payload",
"=",
"payload",
")",
"items",
"=",
"response",
".",
"text",
"page",
"+=",
"1",
"if",
"'last'",
"in",
"response",
".",
"links",
":",
"last_url",
"=",
"response",
".",
"links",
"[",
"'last'",
"]",
"[",
"'url'",
"]",
"last_page",
"=",
"last_url",
".",
"split",
"(",
"'&page='",
")",
"[",
"1",
"]",
".",
"split",
"(",
"'&'",
")",
"[",
"0",
"]",
"last_page",
"=",
"int",
"(",
"last_page",
")",
"logger",
".",
"debug",
"(",
"\"Page: %i/%i\"",
"%",
"(",
"page",
",",
"last_page",
")",
")",
"while",
"items",
":",
"yield",
"items",
"items",
"=",
"None",
"if",
"'next'",
"in",
"response",
".",
"links",
":",
"url_next",
"=",
"response",
".",
"links",
"[",
"'next'",
"]",
"[",
"'url'",
"]",
"# Loving requests :)",
"response",
"=",
"self",
".",
"fetch",
"(",
"url_next",
",",
"payload",
"=",
"payload",
")",
"page",
"+=",
"1",
"items",
"=",
"response",
".",
"text",
"logger",
".",
"debug",
"(",
"\"Page: %i/%i\"",
"%",
"(",
"page",
",",
"last_page",
")",
")"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
GitLabClient.sanitize_for_archive
|
Sanitize payload of a HTTP request by removing the token information
before storing/retrieving archived items
:param: url: HTTP url request
:param: headers: HTTP headers request
:param: payload: HTTP payload request
:returns url, headers and the sanitized payload
|
perceval/backends/core/gitlab.py
|
def sanitize_for_archive(url, headers, payload):
"""Sanitize payload of a HTTP request by removing the token information
before storing/retrieving archived items
:param: url: HTTP url request
:param: headers: HTTP headers request
:param: payload: HTTP payload request
:returns url, headers and the sanitized payload
"""
if headers and 'PRIVATE-TOKEN' in headers:
headers.pop('PRIVATE-TOKEN', None)
return url, headers, payload
|
def sanitize_for_archive(url, headers, payload):
"""Sanitize payload of a HTTP request by removing the token information
before storing/retrieving archived items
:param: url: HTTP url request
:param: headers: HTTP headers request
:param: payload: HTTP payload request
:returns url, headers and the sanitized payload
"""
if headers and 'PRIVATE-TOKEN' in headers:
headers.pop('PRIVATE-TOKEN', None)
return url, headers, payload
|
[
"Sanitize",
"payload",
"of",
"a",
"HTTP",
"request",
"by",
"removing",
"the",
"token",
"information",
"before",
"storing",
"/",
"retrieving",
"archived",
"items"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/gitlab.py#L588-L601
|
[
"def",
"sanitize_for_archive",
"(",
"url",
",",
"headers",
",",
"payload",
")",
":",
"if",
"headers",
"and",
"'PRIVATE-TOKEN'",
"in",
"headers",
":",
"headers",
".",
"pop",
"(",
"'PRIVATE-TOKEN'",
",",
"None",
")",
"return",
"url",
",",
"headers",
",",
"payload"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
GitLabClient._init_rate_limit
|
Initialize rate limit information
|
perceval/backends/core/gitlab.py
|
def _init_rate_limit(self):
"""Initialize rate limit information"""
url = urijoin(self.base_url, 'projects', self.owner + '%2F' + self.repository)
try:
response = super().fetch(url)
self.update_rate_limit(response)
except requests.exceptions.HTTPError as error:
if error.response.status_code == 401:
raise error
else:
logger.warning("Rate limit not initialized: %s", error)
|
def _init_rate_limit(self):
"""Initialize rate limit information"""
url = urijoin(self.base_url, 'projects', self.owner + '%2F' + self.repository)
try:
response = super().fetch(url)
self.update_rate_limit(response)
except requests.exceptions.HTTPError as error:
if error.response.status_code == 401:
raise error
else:
logger.warning("Rate limit not initialized: %s", error)
|
[
"Initialize",
"rate",
"limit",
"information"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/gitlab.py#L612-L623
|
[
"def",
"_init_rate_limit",
"(",
"self",
")",
":",
"url",
"=",
"urijoin",
"(",
"self",
".",
"base_url",
",",
"'projects'",
",",
"self",
".",
"owner",
"+",
"'%2F'",
"+",
"self",
".",
"repository",
")",
"try",
":",
"response",
"=",
"super",
"(",
")",
".",
"fetch",
"(",
"url",
")",
"self",
".",
"update_rate_limit",
"(",
"response",
")",
"except",
"requests",
".",
"exceptions",
".",
"HTTPError",
"as",
"error",
":",
"if",
"error",
".",
"response",
".",
"status_code",
"==",
"401",
":",
"raise",
"error",
"else",
":",
"logger",
".",
"warning",
"(",
"\"Rate limit not initialized: %s\"",
",",
"error",
")"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
GitLabCommand.setup_cmd_parser
|
Returns the GitLab argument parser.
|
perceval/backends/core/gitlab.py
|
def setup_cmd_parser(cls):
"""Returns the GitLab argument parser."""
parser = BackendCommandArgumentParser(cls.BACKEND.CATEGORIES,
from_date=True,
token_auth=True,
archive=True)
# GitLab options
group = parser.parser.add_argument_group('GitLab arguments')
group.add_argument('--enterprise-url', dest='base_url',
help="Base URL for GitLab Enterprise instance")
group.add_argument('--sleep-for-rate', dest='sleep_for_rate',
action='store_true',
help="sleep for getting more rate")
group.add_argument('--min-rate-to-sleep', dest='min_rate_to_sleep',
default=MIN_RATE_LIMIT, type=int,
help="sleep until reset when the rate limit \
reaches this value")
group.add_argument('--blacklist-ids', dest='blacklist_ids',
nargs='*', type=int,
help="Ids of items that must not be retrieved.")
# Generic client options
group.add_argument('--max-retries', dest='max_retries',
default=MAX_RETRIES, type=int,
help="number of API call retries")
group.add_argument('--sleep-time', dest='sleep_time',
default=DEFAULT_SLEEP_TIME, type=int,
help="sleeping time between API call retries")
# Positional arguments
parser.parser.add_argument('owner',
help="GitLab owner")
parser.parser.add_argument('repository',
help="GitLab repository")
return parser
|
def setup_cmd_parser(cls):
"""Returns the GitLab argument parser."""
parser = BackendCommandArgumentParser(cls.BACKEND.CATEGORIES,
from_date=True,
token_auth=True,
archive=True)
# GitLab options
group = parser.parser.add_argument_group('GitLab arguments')
group.add_argument('--enterprise-url', dest='base_url',
help="Base URL for GitLab Enterprise instance")
group.add_argument('--sleep-for-rate', dest='sleep_for_rate',
action='store_true',
help="sleep for getting more rate")
group.add_argument('--min-rate-to-sleep', dest='min_rate_to_sleep',
default=MIN_RATE_LIMIT, type=int,
help="sleep until reset when the rate limit \
reaches this value")
group.add_argument('--blacklist-ids', dest='blacklist_ids',
nargs='*', type=int,
help="Ids of items that must not be retrieved.")
# Generic client options
group.add_argument('--max-retries', dest='max_retries',
default=MAX_RETRIES, type=int,
help="number of API call retries")
group.add_argument('--sleep-time', dest='sleep_time',
default=DEFAULT_SLEEP_TIME, type=int,
help="sleeping time between API call retries")
# Positional arguments
parser.parser.add_argument('owner',
help="GitLab owner")
parser.parser.add_argument('repository',
help="GitLab repository")
return parser
|
[
"Returns",
"the",
"GitLab",
"argument",
"parser",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/gitlab.py#L632-L669
|
[
"def",
"setup_cmd_parser",
"(",
"cls",
")",
":",
"parser",
"=",
"BackendCommandArgumentParser",
"(",
"cls",
".",
"BACKEND",
".",
"CATEGORIES",
",",
"from_date",
"=",
"True",
",",
"token_auth",
"=",
"True",
",",
"archive",
"=",
"True",
")",
"# GitLab options",
"group",
"=",
"parser",
".",
"parser",
".",
"add_argument_group",
"(",
"'GitLab arguments'",
")",
"group",
".",
"add_argument",
"(",
"'--enterprise-url'",
",",
"dest",
"=",
"'base_url'",
",",
"help",
"=",
"\"Base URL for GitLab Enterprise instance\"",
")",
"group",
".",
"add_argument",
"(",
"'--sleep-for-rate'",
",",
"dest",
"=",
"'sleep_for_rate'",
",",
"action",
"=",
"'store_true'",
",",
"help",
"=",
"\"sleep for getting more rate\"",
")",
"group",
".",
"add_argument",
"(",
"'--min-rate-to-sleep'",
",",
"dest",
"=",
"'min_rate_to_sleep'",
",",
"default",
"=",
"MIN_RATE_LIMIT",
",",
"type",
"=",
"int",
",",
"help",
"=",
"\"sleep until reset when the rate limit \\\n reaches this value\"",
")",
"group",
".",
"add_argument",
"(",
"'--blacklist-ids'",
",",
"dest",
"=",
"'blacklist_ids'",
",",
"nargs",
"=",
"'*'",
",",
"type",
"=",
"int",
",",
"help",
"=",
"\"Ids of items that must not be retrieved.\"",
")",
"# Generic client options",
"group",
".",
"add_argument",
"(",
"'--max-retries'",
",",
"dest",
"=",
"'max_retries'",
",",
"default",
"=",
"MAX_RETRIES",
",",
"type",
"=",
"int",
",",
"help",
"=",
"\"number of API call retries\"",
")",
"group",
".",
"add_argument",
"(",
"'--sleep-time'",
",",
"dest",
"=",
"'sleep_time'",
",",
"default",
"=",
"DEFAULT_SLEEP_TIME",
",",
"type",
"=",
"int",
",",
"help",
"=",
"\"sleeping time between API call retries\"",
")",
"# Positional arguments",
"parser",
".",
"parser",
".",
"add_argument",
"(",
"'owner'",
",",
"help",
"=",
"\"GitLab owner\"",
")",
"parser",
".",
"parser",
".",
"add_argument",
"(",
"'repository'",
",",
"help",
"=",
"\"GitLab repository\"",
")",
"return",
"parser"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
Slack.fetch
|
Fetch the messages from the channel.
This method fetches the messages stored on the channel that were
sent since the given date.
:param category: the category of items to fetch
:param from_date: obtain messages sent since this date
:returns: a generator of messages
|
perceval/backends/core/slack.py
|
def fetch(self, category=CATEGORY_MESSAGE, from_date=DEFAULT_DATETIME):
"""Fetch the messages from the channel.
This method fetches the messages stored on the channel that were
sent since the given date.
:param category: the category of items to fetch
:param from_date: obtain messages sent since this date
:returns: a generator of messages
"""
if not from_date:
from_date = DEFAULT_DATETIME
from_date = datetime_to_utc(from_date)
latest = datetime_utcnow().timestamp()
kwargs = {'from_date': from_date, 'latest': latest}
items = super().fetch(category, **kwargs)
return items
|
def fetch(self, category=CATEGORY_MESSAGE, from_date=DEFAULT_DATETIME):
"""Fetch the messages from the channel.
This method fetches the messages stored on the channel that were
sent since the given date.
:param category: the category of items to fetch
:param from_date: obtain messages sent since this date
:returns: a generator of messages
"""
if not from_date:
from_date = DEFAULT_DATETIME
from_date = datetime_to_utc(from_date)
latest = datetime_utcnow().timestamp()
kwargs = {'from_date': from_date, 'latest': latest}
items = super().fetch(category, **kwargs)
return items
|
[
"Fetch",
"the",
"messages",
"from",
"the",
"channel",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/slack.py#L76-L96
|
[
"def",
"fetch",
"(",
"self",
",",
"category",
"=",
"CATEGORY_MESSAGE",
",",
"from_date",
"=",
"DEFAULT_DATETIME",
")",
":",
"if",
"not",
"from_date",
":",
"from_date",
"=",
"DEFAULT_DATETIME",
"from_date",
"=",
"datetime_to_utc",
"(",
"from_date",
")",
"latest",
"=",
"datetime_utcnow",
"(",
")",
".",
"timestamp",
"(",
")",
"kwargs",
"=",
"{",
"'from_date'",
":",
"from_date",
",",
"'latest'",
":",
"latest",
"}",
"items",
"=",
"super",
"(",
")",
".",
"fetch",
"(",
"category",
",",
"*",
"*",
"kwargs",
")",
"return",
"items"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
Slack.fetch_items
|
Fetch the messages
:param category: the category of items to fetch
:param kwargs: backend arguments
:returns: a generator of items
|
perceval/backends/core/slack.py
|
def fetch_items(self, category, **kwargs):
"""Fetch the messages
:param category: the category of items to fetch
:param kwargs: backend arguments
:returns: a generator of items
"""
from_date = kwargs['from_date']
latest = kwargs['latest']
logger.info("Fetching messages of '%s' channel from %s",
self.channel, str(from_date))
raw_info = self.client.channel_info(self.channel)
channel_info = self.parse_channel_info(raw_info)
channel_info['num_members'] = self.client.conversation_members(self.channel)
oldest = datetime_to_utc(from_date).timestamp()
# Minimum value supported by Slack is 0 not 0.0
if oldest == 0.0:
oldest = 0
# Slack does not include on its result the lower limit
# of the search if it has the same date of 'oldest'. To get
# this messages too, we substract a low value to be sure
# the dates are not the same. To avoid precision problems
# it is substracted by five decimals and not by six.
if oldest > 0.0:
oldest -= .00001
fetching = True
nmsgs = 0
while fetching:
raw_history = self.client.history(self.channel,
oldest=oldest, latest=latest)
messages, fetching = self.parse_history(raw_history)
for message in messages:
# Fetch user data
user_id = None
if 'user' in message:
user_id = message['user']
elif 'comment' in message:
user_id = message['comment']['user']
if user_id:
message['user_data'] = self.__get_or_fetch_user(user_id)
message['channel_info'] = channel_info
yield message
nmsgs += 1
if fetching:
latest = float(message['ts'])
logger.info("Fetch process completed: %s message fetched", nmsgs)
|
def fetch_items(self, category, **kwargs):
"""Fetch the messages
:param category: the category of items to fetch
:param kwargs: backend arguments
:returns: a generator of items
"""
from_date = kwargs['from_date']
latest = kwargs['latest']
logger.info("Fetching messages of '%s' channel from %s",
self.channel, str(from_date))
raw_info = self.client.channel_info(self.channel)
channel_info = self.parse_channel_info(raw_info)
channel_info['num_members'] = self.client.conversation_members(self.channel)
oldest = datetime_to_utc(from_date).timestamp()
# Minimum value supported by Slack is 0 not 0.0
if oldest == 0.0:
oldest = 0
# Slack does not include on its result the lower limit
# of the search if it has the same date of 'oldest'. To get
# this messages too, we substract a low value to be sure
# the dates are not the same. To avoid precision problems
# it is substracted by five decimals and not by six.
if oldest > 0.0:
oldest -= .00001
fetching = True
nmsgs = 0
while fetching:
raw_history = self.client.history(self.channel,
oldest=oldest, latest=latest)
messages, fetching = self.parse_history(raw_history)
for message in messages:
# Fetch user data
user_id = None
if 'user' in message:
user_id = message['user']
elif 'comment' in message:
user_id = message['comment']['user']
if user_id:
message['user_data'] = self.__get_or_fetch_user(user_id)
message['channel_info'] = channel_info
yield message
nmsgs += 1
if fetching:
latest = float(message['ts'])
logger.info("Fetch process completed: %s message fetched", nmsgs)
|
[
"Fetch",
"the",
"messages"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/slack.py#L98-L158
|
[
"def",
"fetch_items",
"(",
"self",
",",
"category",
",",
"*",
"*",
"kwargs",
")",
":",
"from_date",
"=",
"kwargs",
"[",
"'from_date'",
"]",
"latest",
"=",
"kwargs",
"[",
"'latest'",
"]",
"logger",
".",
"info",
"(",
"\"Fetching messages of '%s' channel from %s\"",
",",
"self",
".",
"channel",
",",
"str",
"(",
"from_date",
")",
")",
"raw_info",
"=",
"self",
".",
"client",
".",
"channel_info",
"(",
"self",
".",
"channel",
")",
"channel_info",
"=",
"self",
".",
"parse_channel_info",
"(",
"raw_info",
")",
"channel_info",
"[",
"'num_members'",
"]",
"=",
"self",
".",
"client",
".",
"conversation_members",
"(",
"self",
".",
"channel",
")",
"oldest",
"=",
"datetime_to_utc",
"(",
"from_date",
")",
".",
"timestamp",
"(",
")",
"# Minimum value supported by Slack is 0 not 0.0",
"if",
"oldest",
"==",
"0.0",
":",
"oldest",
"=",
"0",
"# Slack does not include on its result the lower limit",
"# of the search if it has the same date of 'oldest'. To get",
"# this messages too, we substract a low value to be sure",
"# the dates are not the same. To avoid precision problems",
"# it is substracted by five decimals and not by six.",
"if",
"oldest",
">",
"0.0",
":",
"oldest",
"-=",
".00001",
"fetching",
"=",
"True",
"nmsgs",
"=",
"0",
"while",
"fetching",
":",
"raw_history",
"=",
"self",
".",
"client",
".",
"history",
"(",
"self",
".",
"channel",
",",
"oldest",
"=",
"oldest",
",",
"latest",
"=",
"latest",
")",
"messages",
",",
"fetching",
"=",
"self",
".",
"parse_history",
"(",
"raw_history",
")",
"for",
"message",
"in",
"messages",
":",
"# Fetch user data",
"user_id",
"=",
"None",
"if",
"'user'",
"in",
"message",
":",
"user_id",
"=",
"message",
"[",
"'user'",
"]",
"elif",
"'comment'",
"in",
"message",
":",
"user_id",
"=",
"message",
"[",
"'comment'",
"]",
"[",
"'user'",
"]",
"if",
"user_id",
":",
"message",
"[",
"'user_data'",
"]",
"=",
"self",
".",
"__get_or_fetch_user",
"(",
"user_id",
")",
"message",
"[",
"'channel_info'",
"]",
"=",
"channel_info",
"yield",
"message",
"nmsgs",
"+=",
"1",
"if",
"fetching",
":",
"latest",
"=",
"float",
"(",
"message",
"[",
"'ts'",
"]",
")",
"logger",
".",
"info",
"(",
"\"Fetch process completed: %s message fetched\"",
",",
"nmsgs",
")"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
Slack.metadata_id
|
Extracts the identifier from a Slack item.
This identifier will be the mix of two fields because Slack
messages does not have any unique identifier. In this case,
'ts' and 'user' values (or 'bot_id' when the message is sent by a bot)
are combined because there have been cases where two messages were sent
by different users at the same time.
|
perceval/backends/core/slack.py
|
def metadata_id(item):
"""Extracts the identifier from a Slack item.
This identifier will be the mix of two fields because Slack
messages does not have any unique identifier. In this case,
'ts' and 'user' values (or 'bot_id' when the message is sent by a bot)
are combined because there have been cases where two messages were sent
by different users at the same time.
"""
if 'user' in item:
nick = item['user']
elif 'comment' in item:
nick = item['comment']['user']
else:
nick = item['bot_id']
return item['ts'] + nick
|
def metadata_id(item):
"""Extracts the identifier from a Slack item.
This identifier will be the mix of two fields because Slack
messages does not have any unique identifier. In this case,
'ts' and 'user' values (or 'bot_id' when the message is sent by a bot)
are combined because there have been cases where two messages were sent
by different users at the same time.
"""
if 'user' in item:
nick = item['user']
elif 'comment' in item:
nick = item['comment']['user']
else:
nick = item['bot_id']
return item['ts'] + nick
|
[
"Extracts",
"the",
"identifier",
"from",
"a",
"Slack",
"item",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/slack.py#L177-L193
|
[
"def",
"metadata_id",
"(",
"item",
")",
":",
"if",
"'user'",
"in",
"item",
":",
"nick",
"=",
"item",
"[",
"'user'",
"]",
"elif",
"'comment'",
"in",
"item",
":",
"nick",
"=",
"item",
"[",
"'comment'",
"]",
"[",
"'user'",
"]",
"else",
":",
"nick",
"=",
"item",
"[",
"'bot_id'",
"]",
"return",
"item",
"[",
"'ts'",
"]",
"+",
"nick"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
Slack._init_client
|
Init client
|
perceval/backends/core/slack.py
|
def _init_client(self, from_archive=False):
"""Init client"""
return SlackClient(self.api_token, self.max_items, self.archive, from_archive)
|
def _init_client(self, from_archive=False):
"""Init client"""
return SlackClient(self.api_token, self.max_items, self.archive, from_archive)
|
[
"Init",
"client"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/slack.py#L264-L267
|
[
"def",
"_init_client",
"(",
"self",
",",
"from_archive",
"=",
"False",
")",
":",
"return",
"SlackClient",
"(",
"self",
".",
"api_token",
",",
"self",
".",
"max_items",
",",
"self",
".",
"archive",
",",
"from_archive",
")"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
SlackClient.conversation_members
|
Fetch the number of members in a conversation, which is a supertype for public and
private ones, DM and group DM.
:param conversation: the ID of the conversation
|
perceval/backends/core/slack.py
|
def conversation_members(self, conversation):
"""Fetch the number of members in a conversation, which is a supertype for public and
private ones, DM and group DM.
:param conversation: the ID of the conversation
"""
members = 0
resource = self.RCONVERSATION_INFO
params = {
self.PCHANNEL: conversation,
}
raw_response = self._fetch(resource, params)
response = json.loads(raw_response)
members += len(response["members"])
while 'next_cursor' in response['response_metadata'] and response['response_metadata']['next_cursor']:
params['cursor'] = response['response_metadata']['next_cursor']
raw_response = self._fetch(resource, params)
response = json.loads(raw_response)
members += len(response["members"])
return members
|
def conversation_members(self, conversation):
"""Fetch the number of members in a conversation, which is a supertype for public and
private ones, DM and group DM.
:param conversation: the ID of the conversation
"""
members = 0
resource = self.RCONVERSATION_INFO
params = {
self.PCHANNEL: conversation,
}
raw_response = self._fetch(resource, params)
response = json.loads(raw_response)
members += len(response["members"])
while 'next_cursor' in response['response_metadata'] and response['response_metadata']['next_cursor']:
params['cursor'] = response['response_metadata']['next_cursor']
raw_response = self._fetch(resource, params)
response = json.loads(raw_response)
members += len(response["members"])
return members
|
[
"Fetch",
"the",
"number",
"of",
"members",
"in",
"a",
"conversation",
"which",
"is",
"a",
"supertype",
"for",
"public",
"and",
"private",
"ones",
"DM",
"and",
"group",
"DM",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/slack.py#L318-L342
|
[
"def",
"conversation_members",
"(",
"self",
",",
"conversation",
")",
":",
"members",
"=",
"0",
"resource",
"=",
"self",
".",
"RCONVERSATION_INFO",
"params",
"=",
"{",
"self",
".",
"PCHANNEL",
":",
"conversation",
",",
"}",
"raw_response",
"=",
"self",
".",
"_fetch",
"(",
"resource",
",",
"params",
")",
"response",
"=",
"json",
".",
"loads",
"(",
"raw_response",
")",
"members",
"+=",
"len",
"(",
"response",
"[",
"\"members\"",
"]",
")",
"while",
"'next_cursor'",
"in",
"response",
"[",
"'response_metadata'",
"]",
"and",
"response",
"[",
"'response_metadata'",
"]",
"[",
"'next_cursor'",
"]",
":",
"params",
"[",
"'cursor'",
"]",
"=",
"response",
"[",
"'response_metadata'",
"]",
"[",
"'next_cursor'",
"]",
"raw_response",
"=",
"self",
".",
"_fetch",
"(",
"resource",
",",
"params",
")",
"response",
"=",
"json",
".",
"loads",
"(",
"raw_response",
")",
"members",
"+=",
"len",
"(",
"response",
"[",
"\"members\"",
"]",
")",
"return",
"members"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
SlackClient.channel_info
|
Fetch information about a channel.
|
perceval/backends/core/slack.py
|
def channel_info(self, channel):
"""Fetch information about a channel."""
resource = self.RCHANNEL_INFO
params = {
self.PCHANNEL: channel,
}
response = self._fetch(resource, params)
return response
|
def channel_info(self, channel):
"""Fetch information about a channel."""
resource = self.RCHANNEL_INFO
params = {
self.PCHANNEL: channel,
}
response = self._fetch(resource, params)
return response
|
[
"Fetch",
"information",
"about",
"a",
"channel",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/slack.py#L344-L355
|
[
"def",
"channel_info",
"(",
"self",
",",
"channel",
")",
":",
"resource",
"=",
"self",
".",
"RCHANNEL_INFO",
"params",
"=",
"{",
"self",
".",
"PCHANNEL",
":",
"channel",
",",
"}",
"response",
"=",
"self",
".",
"_fetch",
"(",
"resource",
",",
"params",
")",
"return",
"response"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
SlackClient.history
|
Fetch the history of a channel.
|
perceval/backends/core/slack.py
|
def history(self, channel, oldest=None, latest=None):
"""Fetch the history of a channel."""
resource = self.RCHANNEL_HISTORY
params = {
self.PCHANNEL: channel,
self.PCOUNT: self.max_items
}
if oldest is not None:
params[self.POLDEST] = oldest
if latest is not None:
params[self.PLATEST] = latest
response = self._fetch(resource, params)
return response
|
def history(self, channel, oldest=None, latest=None):
"""Fetch the history of a channel."""
resource = self.RCHANNEL_HISTORY
params = {
self.PCHANNEL: channel,
self.PCOUNT: self.max_items
}
if oldest is not None:
params[self.POLDEST] = oldest
if latest is not None:
params[self.PLATEST] = latest
response = self._fetch(resource, params)
return response
|
[
"Fetch",
"the",
"history",
"of",
"a",
"channel",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/slack.py#L357-L374
|
[
"def",
"history",
"(",
"self",
",",
"channel",
",",
"oldest",
"=",
"None",
",",
"latest",
"=",
"None",
")",
":",
"resource",
"=",
"self",
".",
"RCHANNEL_HISTORY",
"params",
"=",
"{",
"self",
".",
"PCHANNEL",
":",
"channel",
",",
"self",
".",
"PCOUNT",
":",
"self",
".",
"max_items",
"}",
"if",
"oldest",
"is",
"not",
"None",
":",
"params",
"[",
"self",
".",
"POLDEST",
"]",
"=",
"oldest",
"if",
"latest",
"is",
"not",
"None",
":",
"params",
"[",
"self",
".",
"PLATEST",
"]",
"=",
"latest",
"response",
"=",
"self",
".",
"_fetch",
"(",
"resource",
",",
"params",
")",
"return",
"response"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
SlackClient.user
|
Fetch user info.
|
perceval/backends/core/slack.py
|
def user(self, user_id):
"""Fetch user info."""
resource = self.RUSER_INFO
params = {
self.PUSER: user_id
}
response = self._fetch(resource, params)
return response
|
def user(self, user_id):
"""Fetch user info."""
resource = self.RUSER_INFO
params = {
self.PUSER: user_id
}
response = self._fetch(resource, params)
return response
|
[
"Fetch",
"user",
"info",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/slack.py#L376-L387
|
[
"def",
"user",
"(",
"self",
",",
"user_id",
")",
":",
"resource",
"=",
"self",
".",
"RUSER_INFO",
"params",
"=",
"{",
"self",
".",
"PUSER",
":",
"user_id",
"}",
"response",
"=",
"self",
".",
"_fetch",
"(",
"resource",
",",
"params",
")",
"return",
"response"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
SlackClient.sanitize_for_archive
|
Sanitize payload of a HTTP request by removing the token information
before storing/retrieving archived items
:param: url: HTTP url request
:param: headers: HTTP headers request
:param: payload: HTTP payload request
:returns url, headers and the sanitized payload
|
perceval/backends/core/slack.py
|
def sanitize_for_archive(url, headers, payload):
"""Sanitize payload of a HTTP request by removing the token information
before storing/retrieving archived items
:param: url: HTTP url request
:param: headers: HTTP headers request
:param: payload: HTTP payload request
:returns url, headers and the sanitized payload
"""
if SlackClient.PTOKEN in payload:
payload.pop(SlackClient.PTOKEN)
return url, headers, payload
|
def sanitize_for_archive(url, headers, payload):
"""Sanitize payload of a HTTP request by removing the token information
before storing/retrieving archived items
:param: url: HTTP url request
:param: headers: HTTP headers request
:param: payload: HTTP payload request
:returns url, headers and the sanitized payload
"""
if SlackClient.PTOKEN in payload:
payload.pop(SlackClient.PTOKEN)
return url, headers, payload
|
[
"Sanitize",
"payload",
"of",
"a",
"HTTP",
"request",
"by",
"removing",
"the",
"token",
"information",
"before",
"storing",
"/",
"retrieving",
"archived",
"items"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/slack.py#L390-L403
|
[
"def",
"sanitize_for_archive",
"(",
"url",
",",
"headers",
",",
"payload",
")",
":",
"if",
"SlackClient",
".",
"PTOKEN",
"in",
"payload",
":",
"payload",
".",
"pop",
"(",
"SlackClient",
".",
"PTOKEN",
")",
"return",
"url",
",",
"headers",
",",
"payload"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
SlackClient._fetch
|
Fetch a resource.
:param resource: resource to get
:param params: dict with the HTTP parameters needed to get
the given resource
|
perceval/backends/core/slack.py
|
def _fetch(self, resource, params):
"""Fetch a resource.
:param resource: resource to get
:param params: dict with the HTTP parameters needed to get
the given resource
"""
url = self.URL % {'resource': resource}
params[self.PTOKEN] = self.api_token
logger.debug("Slack client requests: %s params: %s",
resource, str(params))
r = self.fetch(url, payload=params)
# Check for possible API errors
result = r.json()
if not result['ok']:
raise SlackClientError(error=result['error'])
return r.text
|
def _fetch(self, resource, params):
"""Fetch a resource.
:param resource: resource to get
:param params: dict with the HTTP parameters needed to get
the given resource
"""
url = self.URL % {'resource': resource}
params[self.PTOKEN] = self.api_token
logger.debug("Slack client requests: %s params: %s",
resource, str(params))
r = self.fetch(url, payload=params)
# Check for possible API errors
result = r.json()
if not result['ok']:
raise SlackClientError(error=result['error'])
return r.text
|
[
"Fetch",
"a",
"resource",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/slack.py#L405-L426
|
[
"def",
"_fetch",
"(",
"self",
",",
"resource",
",",
"params",
")",
":",
"url",
"=",
"self",
".",
"URL",
"%",
"{",
"'resource'",
":",
"resource",
"}",
"params",
"[",
"self",
".",
"PTOKEN",
"]",
"=",
"self",
".",
"api_token",
"logger",
".",
"debug",
"(",
"\"Slack client requests: %s params: %s\"",
",",
"resource",
",",
"str",
"(",
"params",
")",
")",
"r",
"=",
"self",
".",
"fetch",
"(",
"url",
",",
"payload",
"=",
"params",
")",
"# Check for possible API errors",
"result",
"=",
"r",
".",
"json",
"(",
")",
"if",
"not",
"result",
"[",
"'ok'",
"]",
":",
"raise",
"SlackClientError",
"(",
"error",
"=",
"result",
"[",
"'error'",
"]",
")",
"return",
"r",
".",
"text"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
SlackCommand.setup_cmd_parser
|
Returns the Slack argument parser.
|
perceval/backends/core/slack.py
|
def setup_cmd_parser(cls):
"""Returns the Slack argument parser."""
parser = BackendCommandArgumentParser(cls.BACKEND.CATEGORIES,
from_date=True,
token_auth=True,
archive=True)
# Backend token is required
action = parser.parser._option_string_actions['--api-token']
action.required = True
# Slack options
group = parser.parser.add_argument_group('Slack arguments')
group.add_argument('--max-items', dest='max_items',
type=int, default=MAX_ITEMS,
help="Maximum number of items requested on the same query")
# Required arguments
parser.parser.add_argument('channel',
help="Slack channel identifier")
return parser
|
def setup_cmd_parser(cls):
"""Returns the Slack argument parser."""
parser = BackendCommandArgumentParser(cls.BACKEND.CATEGORIES,
from_date=True,
token_auth=True,
archive=True)
# Backend token is required
action = parser.parser._option_string_actions['--api-token']
action.required = True
# Slack options
group = parser.parser.add_argument_group('Slack arguments')
group.add_argument('--max-items', dest='max_items',
type=int, default=MAX_ITEMS,
help="Maximum number of items requested on the same query")
# Required arguments
parser.parser.add_argument('channel',
help="Slack channel identifier")
return parser
|
[
"Returns",
"the",
"Slack",
"argument",
"parser",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/slack.py#L435-L457
|
[
"def",
"setup_cmd_parser",
"(",
"cls",
")",
":",
"parser",
"=",
"BackendCommandArgumentParser",
"(",
"cls",
".",
"BACKEND",
".",
"CATEGORIES",
",",
"from_date",
"=",
"True",
",",
"token_auth",
"=",
"True",
",",
"archive",
"=",
"True",
")",
"# Backend token is required",
"action",
"=",
"parser",
".",
"parser",
".",
"_option_string_actions",
"[",
"'--api-token'",
"]",
"action",
".",
"required",
"=",
"True",
"# Slack options",
"group",
"=",
"parser",
".",
"parser",
".",
"add_argument_group",
"(",
"'Slack arguments'",
")",
"group",
".",
"add_argument",
"(",
"'--max-items'",
",",
"dest",
"=",
"'max_items'",
",",
"type",
"=",
"int",
",",
"default",
"=",
"MAX_ITEMS",
",",
"help",
"=",
"\"Maximum number of items requested on the same query\"",
")",
"# Required arguments",
"parser",
".",
"parser",
".",
"add_argument",
"(",
"'channel'",
",",
"help",
"=",
"\"Slack channel identifier\"",
")",
"return",
"parser"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
Bugzilla.fetch_items
|
Fetch the bugs
:param category: the category of items to fetch
:param kwargs: backend arguments
:returns: a generator of items
|
perceval/backends/core/bugzilla.py
|
def fetch_items(self, category, **kwargs):
"""Fetch the bugs
:param category: the category of items to fetch
:param kwargs: backend arguments
:returns: a generator of items
"""
from_date = kwargs['from_date']
logger.info("Looking for bugs: '%s' updated from '%s'",
self.url, str(from_date))
buglist = [bug for bug in self.__fetch_buglist(from_date)]
nbugs = 0
tbugs = len(buglist)
for i in range(0, tbugs, self.max_bugs):
chunk = buglist[i:i + self.max_bugs]
bugs_ids = [b['bug_id'] for b in chunk]
logger.info("Fetching bugs: %s/%s", i, tbugs)
bugs = self.__fetch_and_parse_bugs_details(bugs_ids)
for bug in bugs:
bug_id = bug['bug_id'][0]['__text__']
bug['activity'] = self.__fetch_and_parse_bug_activity(bug_id)
nbugs += 1
yield bug
logger.info("Fetch process completed: %s/%s bugs fetched",
nbugs, tbugs)
|
def fetch_items(self, category, **kwargs):
"""Fetch the bugs
:param category: the category of items to fetch
:param kwargs: backend arguments
:returns: a generator of items
"""
from_date = kwargs['from_date']
logger.info("Looking for bugs: '%s' updated from '%s'",
self.url, str(from_date))
buglist = [bug for bug in self.__fetch_buglist(from_date)]
nbugs = 0
tbugs = len(buglist)
for i in range(0, tbugs, self.max_bugs):
chunk = buglist[i:i + self.max_bugs]
bugs_ids = [b['bug_id'] for b in chunk]
logger.info("Fetching bugs: %s/%s", i, tbugs)
bugs = self.__fetch_and_parse_bugs_details(bugs_ids)
for bug in bugs:
bug_id = bug['bug_id'][0]['__text__']
bug['activity'] = self.__fetch_and_parse_bug_activity(bug_id)
nbugs += 1
yield bug
logger.info("Fetch process completed: %s/%s bugs fetched",
nbugs, tbugs)
|
[
"Fetch",
"the",
"bugs"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/bugzilla.py#L99-L132
|
[
"def",
"fetch_items",
"(",
"self",
",",
"category",
",",
"*",
"*",
"kwargs",
")",
":",
"from_date",
"=",
"kwargs",
"[",
"'from_date'",
"]",
"logger",
".",
"info",
"(",
"\"Looking for bugs: '%s' updated from '%s'\"",
",",
"self",
".",
"url",
",",
"str",
"(",
"from_date",
")",
")",
"buglist",
"=",
"[",
"bug",
"for",
"bug",
"in",
"self",
".",
"__fetch_buglist",
"(",
"from_date",
")",
"]",
"nbugs",
"=",
"0",
"tbugs",
"=",
"len",
"(",
"buglist",
")",
"for",
"i",
"in",
"range",
"(",
"0",
",",
"tbugs",
",",
"self",
".",
"max_bugs",
")",
":",
"chunk",
"=",
"buglist",
"[",
"i",
":",
"i",
"+",
"self",
".",
"max_bugs",
"]",
"bugs_ids",
"=",
"[",
"b",
"[",
"'bug_id'",
"]",
"for",
"b",
"in",
"chunk",
"]",
"logger",
".",
"info",
"(",
"\"Fetching bugs: %s/%s\"",
",",
"i",
",",
"tbugs",
")",
"bugs",
"=",
"self",
".",
"__fetch_and_parse_bugs_details",
"(",
"bugs_ids",
")",
"for",
"bug",
"in",
"bugs",
":",
"bug_id",
"=",
"bug",
"[",
"'bug_id'",
"]",
"[",
"0",
"]",
"[",
"'__text__'",
"]",
"bug",
"[",
"'activity'",
"]",
"=",
"self",
".",
"__fetch_and_parse_bug_activity",
"(",
"bug_id",
")",
"nbugs",
"+=",
"1",
"yield",
"bug",
"logger",
".",
"info",
"(",
"\"Fetch process completed: %s/%s bugs fetched\"",
",",
"nbugs",
",",
"tbugs",
")"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
Bugzilla.metadata_updated_on
|
Extracts and coverts the update time from a Bugzilla item.
The timestamp is extracted from 'delta_ts' field. This date is
converted to UNIX timestamp format. Due Bugzilla servers ignore
the timezone on HTTP requests, it will be ignored during the
conversion, too.
:param item: item generated by the backend
:returns: a UNIX timestamp
|
perceval/backends/core/bugzilla.py
|
def metadata_updated_on(item):
"""Extracts and coverts the update time from a Bugzilla item.
The timestamp is extracted from 'delta_ts' field. This date is
converted to UNIX timestamp format. Due Bugzilla servers ignore
the timezone on HTTP requests, it will be ignored during the
conversion, too.
:param item: item generated by the backend
:returns: a UNIX timestamp
"""
ts = item['delta_ts'][0]['__text__']
ts = str_to_datetime(ts)
ts = ts.replace(tzinfo=dateutil.tz.tzutc())
return ts.timestamp()
|
def metadata_updated_on(item):
"""Extracts and coverts the update time from a Bugzilla item.
The timestamp is extracted from 'delta_ts' field. This date is
converted to UNIX timestamp format. Due Bugzilla servers ignore
the timezone on HTTP requests, it will be ignored during the
conversion, too.
:param item: item generated by the backend
:returns: a UNIX timestamp
"""
ts = item['delta_ts'][0]['__text__']
ts = str_to_datetime(ts)
ts = ts.replace(tzinfo=dateutil.tz.tzutc())
return ts.timestamp()
|
[
"Extracts",
"and",
"coverts",
"the",
"update",
"time",
"from",
"a",
"Bugzilla",
"item",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/bugzilla.py#L157-L173
|
[
"def",
"metadata_updated_on",
"(",
"item",
")",
":",
"ts",
"=",
"item",
"[",
"'delta_ts'",
"]",
"[",
"0",
"]",
"[",
"'__text__'",
"]",
"ts",
"=",
"str_to_datetime",
"(",
"ts",
")",
"ts",
"=",
"ts",
".",
"replace",
"(",
"tzinfo",
"=",
"dateutil",
".",
"tz",
".",
"tzutc",
"(",
")",
")",
"return",
"ts",
".",
"timestamp",
"(",
")"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
Bugzilla.parse_buglist
|
Parse a Bugzilla CSV bug list.
The method parses the CSV file and returns an iterator of
dictionaries. Each one of this, contains the summary of a bug.
:param raw_csv: CSV string to parse
:returns: a generator of parsed bugs
|
perceval/backends/core/bugzilla.py
|
def parse_buglist(raw_csv):
"""Parse a Bugzilla CSV bug list.
The method parses the CSV file and returns an iterator of
dictionaries. Each one of this, contains the summary of a bug.
:param raw_csv: CSV string to parse
:returns: a generator of parsed bugs
"""
reader = csv.DictReader(raw_csv.split('\n'),
delimiter=',', quotechar='"')
for row in reader:
yield row
|
def parse_buglist(raw_csv):
"""Parse a Bugzilla CSV bug list.
The method parses the CSV file and returns an iterator of
dictionaries. Each one of this, contains the summary of a bug.
:param raw_csv: CSV string to parse
:returns: a generator of parsed bugs
"""
reader = csv.DictReader(raw_csv.split('\n'),
delimiter=',', quotechar='"')
for row in reader:
yield row
|
[
"Parse",
"a",
"Bugzilla",
"CSV",
"bug",
"list",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/bugzilla.py#L185-L198
|
[
"def",
"parse_buglist",
"(",
"raw_csv",
")",
":",
"reader",
"=",
"csv",
".",
"DictReader",
"(",
"raw_csv",
".",
"split",
"(",
"'\\n'",
")",
",",
"delimiter",
"=",
"','",
",",
"quotechar",
"=",
"'\"'",
")",
"for",
"row",
"in",
"reader",
":",
"yield",
"row"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
Bugzilla.parse_bugs_details
|
Parse a Bugilla bugs details XML stream.
This method returns a generator which parses the given XML,
producing an iterator of dictionaries. Each dictionary stores
the information related to a parsed bug.
If the given XML is invalid or does not contains any bug, the
method will raise a ParseError exception.
:param raw_xml: XML string to parse
:returns: a generator of parsed bugs
:raises ParseError: raised when an error occurs parsing
the given XML stream
|
perceval/backends/core/bugzilla.py
|
def parse_bugs_details(raw_xml):
"""Parse a Bugilla bugs details XML stream.
This method returns a generator which parses the given XML,
producing an iterator of dictionaries. Each dictionary stores
the information related to a parsed bug.
If the given XML is invalid or does not contains any bug, the
method will raise a ParseError exception.
:param raw_xml: XML string to parse
:returns: a generator of parsed bugs
:raises ParseError: raised when an error occurs parsing
the given XML stream
"""
bugs = xml_to_dict(raw_xml)
if 'bug' not in bugs:
cause = "No bugs found. XML stream seems to be invalid."
raise ParseError(cause=cause)
for bug in bugs['bug']:
yield bug
|
def parse_bugs_details(raw_xml):
"""Parse a Bugilla bugs details XML stream.
This method returns a generator which parses the given XML,
producing an iterator of dictionaries. Each dictionary stores
the information related to a parsed bug.
If the given XML is invalid or does not contains any bug, the
method will raise a ParseError exception.
:param raw_xml: XML string to parse
:returns: a generator of parsed bugs
:raises ParseError: raised when an error occurs parsing
the given XML stream
"""
bugs = xml_to_dict(raw_xml)
if 'bug' not in bugs:
cause = "No bugs found. XML stream seems to be invalid."
raise ParseError(cause=cause)
for bug in bugs['bug']:
yield bug
|
[
"Parse",
"a",
"Bugilla",
"bugs",
"details",
"XML",
"stream",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/bugzilla.py#L201-L225
|
[
"def",
"parse_bugs_details",
"(",
"raw_xml",
")",
":",
"bugs",
"=",
"xml_to_dict",
"(",
"raw_xml",
")",
"if",
"'bug'",
"not",
"in",
"bugs",
":",
"cause",
"=",
"\"No bugs found. XML stream seems to be invalid.\"",
"raise",
"ParseError",
"(",
"cause",
"=",
"cause",
")",
"for",
"bug",
"in",
"bugs",
"[",
"'bug'",
"]",
":",
"yield",
"bug"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
Bugzilla.parse_bug_activity
|
Parse a Bugzilla bug activity HTML stream.
This method extracts the information about activity from the
given HTML stream. The bug activity is stored into a HTML
table. Each parsed activity event is returned into a dictionary.
If the given HTML is invalid, the method will raise a ParseError
exception.
:param raw_html: HTML string to parse
:returns: a generator of parsed activity events
:raises ParseError: raised when an error occurs parsing
the given HTML stream
|
perceval/backends/core/bugzilla.py
|
def parse_bug_activity(raw_html):
"""Parse a Bugzilla bug activity HTML stream.
This method extracts the information about activity from the
given HTML stream. The bug activity is stored into a HTML
table. Each parsed activity event is returned into a dictionary.
If the given HTML is invalid, the method will raise a ParseError
exception.
:param raw_html: HTML string to parse
:returns: a generator of parsed activity events
:raises ParseError: raised when an error occurs parsing
the given HTML stream
"""
def is_activity_empty(bs):
EMPTY_ACTIVITY = "No changes have been made to this (?:bug|issue) yet."
tag = bs.find(text=re.compile(EMPTY_ACTIVITY))
return tag is not None
def find_activity_table(bs):
# The first table with 5 columns is the table of activity
tables = bs.find_all('table')
for tb in tables:
nheaders = len(tb.tr.find_all('th', recursive=False))
if nheaders == 5:
return tb
raise ParseError(cause="Table of bug activity not found.")
def remove_tags(bs):
HTML_TAGS_TO_REMOVE = ['a', 'i', 'span']
for tag in bs.find_all(HTML_TAGS_TO_REMOVE):
tag.replaceWith(tag.text)
def format_text(bs):
strings = [s.strip(' \n\t') for s in bs.stripped_strings]
s = ' '.join(strings)
return s
# Parsing starts here
bs = bs4.BeautifulSoup(raw_html, 'html.parser')
if is_activity_empty(bs):
fields = []
else:
activity_tb = find_activity_table(bs)
remove_tags(activity_tb)
fields = activity_tb.find_all('td')
while fields:
# First two fields: 'Who' and 'When'.
who = fields.pop(0)
when = fields.pop(0)
# The attribute 'rowspan' of 'who' field tells how many
# changes were made on the same date.
n = int(who.get('rowspan'))
# Next fields are split into chunks of three elements:
# 'What', 'Removed' and 'Added'. These chunks share
# 'Who' and 'When' values.
for _ in range(n):
what = fields.pop(0)
removed = fields.pop(0)
added = fields.pop(0)
event = {'Who': format_text(who),
'When': format_text(when),
'What': format_text(what),
'Removed': format_text(removed),
'Added': format_text(added)}
yield event
|
def parse_bug_activity(raw_html):
"""Parse a Bugzilla bug activity HTML stream.
This method extracts the information about activity from the
given HTML stream. The bug activity is stored into a HTML
table. Each parsed activity event is returned into a dictionary.
If the given HTML is invalid, the method will raise a ParseError
exception.
:param raw_html: HTML string to parse
:returns: a generator of parsed activity events
:raises ParseError: raised when an error occurs parsing
the given HTML stream
"""
def is_activity_empty(bs):
EMPTY_ACTIVITY = "No changes have been made to this (?:bug|issue) yet."
tag = bs.find(text=re.compile(EMPTY_ACTIVITY))
return tag is not None
def find_activity_table(bs):
# The first table with 5 columns is the table of activity
tables = bs.find_all('table')
for tb in tables:
nheaders = len(tb.tr.find_all('th', recursive=False))
if nheaders == 5:
return tb
raise ParseError(cause="Table of bug activity not found.")
def remove_tags(bs):
HTML_TAGS_TO_REMOVE = ['a', 'i', 'span']
for tag in bs.find_all(HTML_TAGS_TO_REMOVE):
tag.replaceWith(tag.text)
def format_text(bs):
strings = [s.strip(' \n\t') for s in bs.stripped_strings]
s = ' '.join(strings)
return s
# Parsing starts here
bs = bs4.BeautifulSoup(raw_html, 'html.parser')
if is_activity_empty(bs):
fields = []
else:
activity_tb = find_activity_table(bs)
remove_tags(activity_tb)
fields = activity_tb.find_all('td')
while fields:
# First two fields: 'Who' and 'When'.
who = fields.pop(0)
when = fields.pop(0)
# The attribute 'rowspan' of 'who' field tells how many
# changes were made on the same date.
n = int(who.get('rowspan'))
# Next fields are split into chunks of three elements:
# 'What', 'Removed' and 'Added'. These chunks share
# 'Who' and 'When' values.
for _ in range(n):
what = fields.pop(0)
removed = fields.pop(0)
added = fields.pop(0)
event = {'Who': format_text(who),
'When': format_text(when),
'What': format_text(what),
'Removed': format_text(removed),
'Added': format_text(added)}
yield event
|
[
"Parse",
"a",
"Bugzilla",
"bug",
"activity",
"HTML",
"stream",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/bugzilla.py#L228-L302
|
[
"def",
"parse_bug_activity",
"(",
"raw_html",
")",
":",
"def",
"is_activity_empty",
"(",
"bs",
")",
":",
"EMPTY_ACTIVITY",
"=",
"\"No changes have been made to this (?:bug|issue) yet.\"",
"tag",
"=",
"bs",
".",
"find",
"(",
"text",
"=",
"re",
".",
"compile",
"(",
"EMPTY_ACTIVITY",
")",
")",
"return",
"tag",
"is",
"not",
"None",
"def",
"find_activity_table",
"(",
"bs",
")",
":",
"# The first table with 5 columns is the table of activity",
"tables",
"=",
"bs",
".",
"find_all",
"(",
"'table'",
")",
"for",
"tb",
"in",
"tables",
":",
"nheaders",
"=",
"len",
"(",
"tb",
".",
"tr",
".",
"find_all",
"(",
"'th'",
",",
"recursive",
"=",
"False",
")",
")",
"if",
"nheaders",
"==",
"5",
":",
"return",
"tb",
"raise",
"ParseError",
"(",
"cause",
"=",
"\"Table of bug activity not found.\"",
")",
"def",
"remove_tags",
"(",
"bs",
")",
":",
"HTML_TAGS_TO_REMOVE",
"=",
"[",
"'a'",
",",
"'i'",
",",
"'span'",
"]",
"for",
"tag",
"in",
"bs",
".",
"find_all",
"(",
"HTML_TAGS_TO_REMOVE",
")",
":",
"tag",
".",
"replaceWith",
"(",
"tag",
".",
"text",
")",
"def",
"format_text",
"(",
"bs",
")",
":",
"strings",
"=",
"[",
"s",
".",
"strip",
"(",
"' \\n\\t'",
")",
"for",
"s",
"in",
"bs",
".",
"stripped_strings",
"]",
"s",
"=",
"' '",
".",
"join",
"(",
"strings",
")",
"return",
"s",
"# Parsing starts here",
"bs",
"=",
"bs4",
".",
"BeautifulSoup",
"(",
"raw_html",
",",
"'html.parser'",
")",
"if",
"is_activity_empty",
"(",
"bs",
")",
":",
"fields",
"=",
"[",
"]",
"else",
":",
"activity_tb",
"=",
"find_activity_table",
"(",
"bs",
")",
"remove_tags",
"(",
"activity_tb",
")",
"fields",
"=",
"activity_tb",
".",
"find_all",
"(",
"'td'",
")",
"while",
"fields",
":",
"# First two fields: 'Who' and 'When'.",
"who",
"=",
"fields",
".",
"pop",
"(",
"0",
")",
"when",
"=",
"fields",
".",
"pop",
"(",
"0",
")",
"# The attribute 'rowspan' of 'who' field tells how many",
"# changes were made on the same date.",
"n",
"=",
"int",
"(",
"who",
".",
"get",
"(",
"'rowspan'",
")",
")",
"# Next fields are split into chunks of three elements:",
"# 'What', 'Removed' and 'Added'. These chunks share",
"# 'Who' and 'When' values.",
"for",
"_",
"in",
"range",
"(",
"n",
")",
":",
"what",
"=",
"fields",
".",
"pop",
"(",
"0",
")",
"removed",
"=",
"fields",
".",
"pop",
"(",
"0",
")",
"added",
"=",
"fields",
".",
"pop",
"(",
"0",
")",
"event",
"=",
"{",
"'Who'",
":",
"format_text",
"(",
"who",
")",
",",
"'When'",
":",
"format_text",
"(",
"when",
")",
",",
"'What'",
":",
"format_text",
"(",
"what",
")",
",",
"'Removed'",
":",
"format_text",
"(",
"removed",
")",
",",
"'Added'",
":",
"format_text",
"(",
"added",
")",
"}",
"yield",
"event"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
Bugzilla._init_client
|
Init client
|
perceval/backends/core/bugzilla.py
|
def _init_client(self, from_archive=False):
"""Init client"""
return BugzillaClient(self.url, user=self.user, password=self.password,
max_bugs_csv=self.max_bugs_csv,
archive=self.archive, from_archive=from_archive)
|
def _init_client(self, from_archive=False):
"""Init client"""
return BugzillaClient(self.url, user=self.user, password=self.password,
max_bugs_csv=self.max_bugs_csv,
archive=self.archive, from_archive=from_archive)
|
[
"Init",
"client"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/bugzilla.py#L304-L309
|
[
"def",
"_init_client",
"(",
"self",
",",
"from_archive",
"=",
"False",
")",
":",
"return",
"BugzillaClient",
"(",
"self",
".",
"url",
",",
"user",
"=",
"self",
".",
"user",
",",
"password",
"=",
"self",
".",
"password",
",",
"max_bugs_csv",
"=",
"self",
".",
"max_bugs_csv",
",",
"archive",
"=",
"self",
".",
"archive",
",",
"from_archive",
"=",
"from_archive",
")"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
BugzillaClient.login
|
Authenticate a user in the server.
:param user: Bugzilla user
:param password: user password
|
perceval/backends/core/bugzilla.py
|
def login(self, user, password):
"""Authenticate a user in the server.
:param user: Bugzilla user
:param password: user password
"""
url = self.URL % {'base': self.base_url, 'cgi': self.CGI_LOGIN}
payload = {
self.PBUGZILLA_LOGIN: user,
self.PBUGZILLA_PASSWORD: password,
self.PLOGIN: 'Log in'
}
headers = {'Referer': self.base_url}
req = self.fetch(url, payload=payload, headers=headers, method=HttpClient.POST)
# Check if the authentication went OK. When this string
# is found means that the authentication was successful
if req.text.find("index.cgi?logout=1") < 0:
cause = ("Bugzilla client could not authenticate user %s. "
"Please check user and password parameters. "
"URLs may also need a trailing '/'.") % user
raise BackendError(cause=cause)
logger.debug("Bugzilla user %s authenticated in %s",
user, self.base_url)
|
def login(self, user, password):
"""Authenticate a user in the server.
:param user: Bugzilla user
:param password: user password
"""
url = self.URL % {'base': self.base_url, 'cgi': self.CGI_LOGIN}
payload = {
self.PBUGZILLA_LOGIN: user,
self.PBUGZILLA_PASSWORD: password,
self.PLOGIN: 'Log in'
}
headers = {'Referer': self.base_url}
req = self.fetch(url, payload=payload, headers=headers, method=HttpClient.POST)
# Check if the authentication went OK. When this string
# is found means that the authentication was successful
if req.text.find("index.cgi?logout=1") < 0:
cause = ("Bugzilla client could not authenticate user %s. "
"Please check user and password parameters. "
"URLs may also need a trailing '/'.") % user
raise BackendError(cause=cause)
logger.debug("Bugzilla user %s authenticated in %s",
user, self.base_url)
|
[
"Authenticate",
"a",
"user",
"in",
"the",
"server",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/bugzilla.py#L436-L463
|
[
"def",
"login",
"(",
"self",
",",
"user",
",",
"password",
")",
":",
"url",
"=",
"self",
".",
"URL",
"%",
"{",
"'base'",
":",
"self",
".",
"base_url",
",",
"'cgi'",
":",
"self",
".",
"CGI_LOGIN",
"}",
"payload",
"=",
"{",
"self",
".",
"PBUGZILLA_LOGIN",
":",
"user",
",",
"self",
".",
"PBUGZILLA_PASSWORD",
":",
"password",
",",
"self",
".",
"PLOGIN",
":",
"'Log in'",
"}",
"headers",
"=",
"{",
"'Referer'",
":",
"self",
".",
"base_url",
"}",
"req",
"=",
"self",
".",
"fetch",
"(",
"url",
",",
"payload",
"=",
"payload",
",",
"headers",
"=",
"headers",
",",
"method",
"=",
"HttpClient",
".",
"POST",
")",
"# Check if the authentication went OK. When this string",
"# is found means that the authentication was successful",
"if",
"req",
".",
"text",
".",
"find",
"(",
"\"index.cgi?logout=1\"",
")",
"<",
"0",
":",
"cause",
"=",
"(",
"\"Bugzilla client could not authenticate user %s. \"",
"\"Please check user and password parameters. \"",
"\"URLs may also need a trailing '/'.\"",
")",
"%",
"user",
"raise",
"BackendError",
"(",
"cause",
"=",
"cause",
")",
"logger",
".",
"debug",
"(",
"\"Bugzilla user %s authenticated in %s\"",
",",
"user",
",",
"self",
".",
"base_url",
")"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
BugzillaClient.logout
|
Logout from the server.
|
perceval/backends/core/bugzilla.py
|
def logout(self):
"""Logout from the server."""
params = {
self.PLOGOUT: '1'
}
self.call(self.CGI_LOGIN, params)
self._close_http_session()
logger.debug("Bugzilla user logged out from %s",
self.base_url)
|
def logout(self):
"""Logout from the server."""
params = {
self.PLOGOUT: '1'
}
self.call(self.CGI_LOGIN, params)
self._close_http_session()
logger.debug("Bugzilla user logged out from %s",
self.base_url)
|
[
"Logout",
"from",
"the",
"server",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/bugzilla.py#L465-L476
|
[
"def",
"logout",
"(",
"self",
")",
":",
"params",
"=",
"{",
"self",
".",
"PLOGOUT",
":",
"'1'",
"}",
"self",
".",
"call",
"(",
"self",
".",
"CGI_LOGIN",
",",
"params",
")",
"self",
".",
"_close_http_session",
"(",
")",
"logger",
".",
"debug",
"(",
"\"Bugzilla user logged out from %s\"",
",",
"self",
".",
"base_url",
")"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
BugzillaClient.metadata
|
Get metadata information in XML format.
|
perceval/backends/core/bugzilla.py
|
def metadata(self):
"""Get metadata information in XML format."""
params = {
self.PCTYPE: self.CTYPE_XML
}
response = self.call(self.CGI_BUG, params)
return response
|
def metadata(self):
"""Get metadata information in XML format."""
params = {
self.PCTYPE: self.CTYPE_XML
}
response = self.call(self.CGI_BUG, params)
return response
|
[
"Get",
"metadata",
"information",
"in",
"XML",
"format",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/bugzilla.py#L478-L487
|
[
"def",
"metadata",
"(",
"self",
")",
":",
"params",
"=",
"{",
"self",
".",
"PCTYPE",
":",
"self",
".",
"CTYPE_XML",
"}",
"response",
"=",
"self",
".",
"call",
"(",
"self",
".",
"CGI_BUG",
",",
"params",
")",
"return",
"response"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
BugzillaClient.buglist
|
Get a summary of bugs in CSV format.
:param from_date: retrieve bugs that where updated from that date
|
perceval/backends/core/bugzilla.py
|
def buglist(self, from_date=DEFAULT_DATETIME):
"""Get a summary of bugs in CSV format.
:param from_date: retrieve bugs that where updated from that date
"""
if not self.version:
self.version = self.__fetch_version()
if self.version in self.OLD_STYLE_VERSIONS:
order = 'Last+Changed'
else:
order = 'changeddate'
date = from_date.strftime("%Y-%m-%d %H:%M:%S")
params = {
self.PCHFIELD_FROM: date,
self.PCTYPE: self.CTYPE_CSV,
self.PLIMIT: self.max_bugs_csv,
self.PORDER: order
}
response = self.call(self.CGI_BUGLIST, params)
return response
|
def buglist(self, from_date=DEFAULT_DATETIME):
"""Get a summary of bugs in CSV format.
:param from_date: retrieve bugs that where updated from that date
"""
if not self.version:
self.version = self.__fetch_version()
if self.version in self.OLD_STYLE_VERSIONS:
order = 'Last+Changed'
else:
order = 'changeddate'
date = from_date.strftime("%Y-%m-%d %H:%M:%S")
params = {
self.PCHFIELD_FROM: date,
self.PCTYPE: self.CTYPE_CSV,
self.PLIMIT: self.max_bugs_csv,
self.PORDER: order
}
response = self.call(self.CGI_BUGLIST, params)
return response
|
[
"Get",
"a",
"summary",
"of",
"bugs",
"in",
"CSV",
"format",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/bugzilla.py#L489-L513
|
[
"def",
"buglist",
"(",
"self",
",",
"from_date",
"=",
"DEFAULT_DATETIME",
")",
":",
"if",
"not",
"self",
".",
"version",
":",
"self",
".",
"version",
"=",
"self",
".",
"__fetch_version",
"(",
")",
"if",
"self",
".",
"version",
"in",
"self",
".",
"OLD_STYLE_VERSIONS",
":",
"order",
"=",
"'Last+Changed'",
"else",
":",
"order",
"=",
"'changeddate'",
"date",
"=",
"from_date",
".",
"strftime",
"(",
"\"%Y-%m-%d %H:%M:%S\"",
")",
"params",
"=",
"{",
"self",
".",
"PCHFIELD_FROM",
":",
"date",
",",
"self",
".",
"PCTYPE",
":",
"self",
".",
"CTYPE_CSV",
",",
"self",
".",
"PLIMIT",
":",
"self",
".",
"max_bugs_csv",
",",
"self",
".",
"PORDER",
":",
"order",
"}",
"response",
"=",
"self",
".",
"call",
"(",
"self",
".",
"CGI_BUGLIST",
",",
"params",
")",
"return",
"response"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
BugzillaClient.bugs
|
Get the information of a list of bugs in XML format.
:param bug_ids: list of bug identifiers
|
perceval/backends/core/bugzilla.py
|
def bugs(self, *bug_ids):
"""Get the information of a list of bugs in XML format.
:param bug_ids: list of bug identifiers
"""
params = {
self.PBUG_ID: bug_ids,
self.PCTYPE: self.CTYPE_XML,
self.PEXCLUDE_FIELD: 'attachmentdata'
}
response = self.call(self.CGI_BUG, params)
return response
|
def bugs(self, *bug_ids):
"""Get the information of a list of bugs in XML format.
:param bug_ids: list of bug identifiers
"""
params = {
self.PBUG_ID: bug_ids,
self.PCTYPE: self.CTYPE_XML,
self.PEXCLUDE_FIELD: 'attachmentdata'
}
response = self.call(self.CGI_BUG, params)
return response
|
[
"Get",
"the",
"information",
"of",
"a",
"list",
"of",
"bugs",
"in",
"XML",
"format",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/bugzilla.py#L515-L528
|
[
"def",
"bugs",
"(",
"self",
",",
"*",
"bug_ids",
")",
":",
"params",
"=",
"{",
"self",
".",
"PBUG_ID",
":",
"bug_ids",
",",
"self",
".",
"PCTYPE",
":",
"self",
".",
"CTYPE_XML",
",",
"self",
".",
"PEXCLUDE_FIELD",
":",
"'attachmentdata'",
"}",
"response",
"=",
"self",
".",
"call",
"(",
"self",
".",
"CGI_BUG",
",",
"params",
")",
"return",
"response"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
BugzillaClient.bug_activity
|
Get the activity of a bug in HTML format.
:param bug_id: bug identifier
|
perceval/backends/core/bugzilla.py
|
def bug_activity(self, bug_id):
"""Get the activity of a bug in HTML format.
:param bug_id: bug identifier
"""
params = {
self.PBUG_ID: bug_id
}
response = self.call(self.CGI_BUG_ACTIVITY, params)
return response
|
def bug_activity(self, bug_id):
"""Get the activity of a bug in HTML format.
:param bug_id: bug identifier
"""
params = {
self.PBUG_ID: bug_id
}
response = self.call(self.CGI_BUG_ACTIVITY, params)
return response
|
[
"Get",
"the",
"activity",
"of",
"a",
"bug",
"in",
"HTML",
"format",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/bugzilla.py#L530-L541
|
[
"def",
"bug_activity",
"(",
"self",
",",
"bug_id",
")",
":",
"params",
"=",
"{",
"self",
".",
"PBUG_ID",
":",
"bug_id",
"}",
"response",
"=",
"self",
".",
"call",
"(",
"self",
".",
"CGI_BUG_ACTIVITY",
",",
"params",
")",
"return",
"response"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
BugzillaClient.call
|
Run an API command.
:param cgi: cgi command to run on the server
:param params: dict with the HTTP parameters needed to run
the given command
|
perceval/backends/core/bugzilla.py
|
def call(self, cgi, params):
"""Run an API command.
:param cgi: cgi command to run on the server
:param params: dict with the HTTP parameters needed to run
the given command
"""
url = self.URL % {'base': self.base_url, 'cgi': cgi}
logger.debug("Bugzilla client calls command: %s params: %s",
cgi, str(params))
req = self.fetch(url, payload=params)
return req.text
|
def call(self, cgi, params):
"""Run an API command.
:param cgi: cgi command to run on the server
:param params: dict with the HTTP parameters needed to run
the given command
"""
url = self.URL % {'base': self.base_url, 'cgi': cgi}
logger.debug("Bugzilla client calls command: %s params: %s",
cgi, str(params))
req = self.fetch(url, payload=params)
return req.text
|
[
"Run",
"an",
"API",
"command",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/bugzilla.py#L543-L557
|
[
"def",
"call",
"(",
"self",
",",
"cgi",
",",
"params",
")",
":",
"url",
"=",
"self",
".",
"URL",
"%",
"{",
"'base'",
":",
"self",
".",
"base_url",
",",
"'cgi'",
":",
"cgi",
"}",
"logger",
".",
"debug",
"(",
"\"Bugzilla client calls command: %s params: %s\"",
",",
"cgi",
",",
"str",
"(",
"params",
")",
")",
"req",
"=",
"self",
".",
"fetch",
"(",
"url",
",",
"payload",
"=",
"params",
")",
"return",
"req",
".",
"text"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
BugzillaClient.sanitize_for_archive
|
Sanitize payload of a HTTP request by removing the login and password information
before storing/retrieving archived items
:param: url: HTTP url request
:param: headers: HTTP headers request
:param: payload: HTTP payload request
:returns url, headers and the sanitized payload
|
perceval/backends/core/bugzilla.py
|
def sanitize_for_archive(url, headers, payload):
"""Sanitize payload of a HTTP request by removing the login and password information
before storing/retrieving archived items
:param: url: HTTP url request
:param: headers: HTTP headers request
:param: payload: HTTP payload request
:returns url, headers and the sanitized payload
"""
if BugzillaClient.PBUGZILLA_LOGIN in payload:
payload.pop(BugzillaClient.PBUGZILLA_LOGIN)
if BugzillaClient.PBUGZILLA_PASSWORD in payload:
payload.pop(BugzillaClient.PBUGZILLA_PASSWORD)
if BugzillaClient.PLOGIN in payload:
payload.pop(BugzillaClient.PLOGIN)
return url, headers, payload
|
def sanitize_for_archive(url, headers, payload):
"""Sanitize payload of a HTTP request by removing the login and password information
before storing/retrieving archived items
:param: url: HTTP url request
:param: headers: HTTP headers request
:param: payload: HTTP payload request
:returns url, headers and the sanitized payload
"""
if BugzillaClient.PBUGZILLA_LOGIN in payload:
payload.pop(BugzillaClient.PBUGZILLA_LOGIN)
if BugzillaClient.PBUGZILLA_PASSWORD in payload:
payload.pop(BugzillaClient.PBUGZILLA_PASSWORD)
if BugzillaClient.PLOGIN in payload:
payload.pop(BugzillaClient.PLOGIN)
return url, headers, payload
|
[
"Sanitize",
"payload",
"of",
"a",
"HTTP",
"request",
"by",
"removing",
"the",
"login",
"and",
"password",
"information",
"before",
"storing",
"/",
"retrieving",
"archived",
"items"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/bugzilla.py#L560-L579
|
[
"def",
"sanitize_for_archive",
"(",
"url",
",",
"headers",
",",
"payload",
")",
":",
"if",
"BugzillaClient",
".",
"PBUGZILLA_LOGIN",
"in",
"payload",
":",
"payload",
".",
"pop",
"(",
"BugzillaClient",
".",
"PBUGZILLA_LOGIN",
")",
"if",
"BugzillaClient",
".",
"PBUGZILLA_PASSWORD",
"in",
"payload",
":",
"payload",
".",
"pop",
"(",
"BugzillaClient",
".",
"PBUGZILLA_PASSWORD",
")",
"if",
"BugzillaClient",
".",
"PLOGIN",
"in",
"payload",
":",
"payload",
".",
"pop",
"(",
"BugzillaClient",
".",
"PLOGIN",
")",
"return",
"url",
",",
"headers",
",",
"payload"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
Meetup.fetch
|
Fetch the events from the server.
This method fetches those events of a group stored on the server
that were updated since the given date. Data comments and rsvps
are included within each event.
:param category: the category of items to fetch
:param from_date: obtain events updated since this date
:param to_date: obtain events updated before this date
:param filter_classified: remove classified fields from the resulting items
:returns: a generator of events
|
perceval/backends/core/meetup.py
|
def fetch(self, category=CATEGORY_EVENT, from_date=DEFAULT_DATETIME, to_date=None,
filter_classified=False):
"""Fetch the events from the server.
This method fetches those events of a group stored on the server
that were updated since the given date. Data comments and rsvps
are included within each event.
:param category: the category of items to fetch
:param from_date: obtain events updated since this date
:param to_date: obtain events updated before this date
:param filter_classified: remove classified fields from the resulting items
:returns: a generator of events
"""
if not from_date:
from_date = DEFAULT_DATETIME
from_date = datetime_to_utc(from_date)
kwargs = {"from_date": from_date, "to_date": to_date}
items = super().fetch(category,
filter_classified=filter_classified,
**kwargs)
return items
|
def fetch(self, category=CATEGORY_EVENT, from_date=DEFAULT_DATETIME, to_date=None,
filter_classified=False):
"""Fetch the events from the server.
This method fetches those events of a group stored on the server
that were updated since the given date. Data comments and rsvps
are included within each event.
:param category: the category of items to fetch
:param from_date: obtain events updated since this date
:param to_date: obtain events updated before this date
:param filter_classified: remove classified fields from the resulting items
:returns: a generator of events
"""
if not from_date:
from_date = DEFAULT_DATETIME
from_date = datetime_to_utc(from_date)
kwargs = {"from_date": from_date, "to_date": to_date}
items = super().fetch(category,
filter_classified=filter_classified,
**kwargs)
return items
|
[
"Fetch",
"the",
"events",
"from",
"the",
"server",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/meetup.py#L97-L122
|
[
"def",
"fetch",
"(",
"self",
",",
"category",
"=",
"CATEGORY_EVENT",
",",
"from_date",
"=",
"DEFAULT_DATETIME",
",",
"to_date",
"=",
"None",
",",
"filter_classified",
"=",
"False",
")",
":",
"if",
"not",
"from_date",
":",
"from_date",
"=",
"DEFAULT_DATETIME",
"from_date",
"=",
"datetime_to_utc",
"(",
"from_date",
")",
"kwargs",
"=",
"{",
"\"from_date\"",
":",
"from_date",
",",
"\"to_date\"",
":",
"to_date",
"}",
"items",
"=",
"super",
"(",
")",
".",
"fetch",
"(",
"category",
",",
"filter_classified",
"=",
"filter_classified",
",",
"*",
"*",
"kwargs",
")",
"return",
"items"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
Meetup.fetch_items
|
Fetch the events
:param category: the category of items to fetch
:param kwargs: backend arguments
:returns: a generator of items
|
perceval/backends/core/meetup.py
|
def fetch_items(self, category, **kwargs):
"""Fetch the events
:param category: the category of items to fetch
:param kwargs: backend arguments
:returns: a generator of items
"""
from_date = kwargs['from_date']
to_date = kwargs['to_date']
logger.info("Fetching events of '%s' group from %s to %s",
self.group, str(from_date),
str(to_date) if to_date else '--')
to_date_ts = datetime_to_utc(to_date).timestamp() if to_date else None
nevents = 0
stop_fetching = False
ev_pages = self.client.events(self.group, from_date=from_date)
for evp in ev_pages:
events = [event for event in self.parse_json(evp)]
for event in events:
event_id = event['id']
event['comments'] = self.__fetch_and_parse_comments(event_id)
event['rsvps'] = self.__fetch_and_parse_rsvps(event_id)
# Check events updated before 'to_date'
event_ts = self.metadata_updated_on(event)
if to_date_ts and event_ts >= to_date_ts:
stop_fetching = True
continue
yield event
nevents += 1
if stop_fetching:
break
logger.info("Fetch process completed: %s events fetched", nevents)
|
def fetch_items(self, category, **kwargs):
"""Fetch the events
:param category: the category of items to fetch
:param kwargs: backend arguments
:returns: a generator of items
"""
from_date = kwargs['from_date']
to_date = kwargs['to_date']
logger.info("Fetching events of '%s' group from %s to %s",
self.group, str(from_date),
str(to_date) if to_date else '--')
to_date_ts = datetime_to_utc(to_date).timestamp() if to_date else None
nevents = 0
stop_fetching = False
ev_pages = self.client.events(self.group, from_date=from_date)
for evp in ev_pages:
events = [event for event in self.parse_json(evp)]
for event in events:
event_id = event['id']
event['comments'] = self.__fetch_and_parse_comments(event_id)
event['rsvps'] = self.__fetch_and_parse_rsvps(event_id)
# Check events updated before 'to_date'
event_ts = self.metadata_updated_on(event)
if to_date_ts and event_ts >= to_date_ts:
stop_fetching = True
continue
yield event
nevents += 1
if stop_fetching:
break
logger.info("Fetch process completed: %s events fetched", nevents)
|
[
"Fetch",
"the",
"events"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/meetup.py#L124-L168
|
[
"def",
"fetch_items",
"(",
"self",
",",
"category",
",",
"*",
"*",
"kwargs",
")",
":",
"from_date",
"=",
"kwargs",
"[",
"'from_date'",
"]",
"to_date",
"=",
"kwargs",
"[",
"'to_date'",
"]",
"logger",
".",
"info",
"(",
"\"Fetching events of '%s' group from %s to %s\"",
",",
"self",
".",
"group",
",",
"str",
"(",
"from_date",
")",
",",
"str",
"(",
"to_date",
")",
"if",
"to_date",
"else",
"'--'",
")",
"to_date_ts",
"=",
"datetime_to_utc",
"(",
"to_date",
")",
".",
"timestamp",
"(",
")",
"if",
"to_date",
"else",
"None",
"nevents",
"=",
"0",
"stop_fetching",
"=",
"False",
"ev_pages",
"=",
"self",
".",
"client",
".",
"events",
"(",
"self",
".",
"group",
",",
"from_date",
"=",
"from_date",
")",
"for",
"evp",
"in",
"ev_pages",
":",
"events",
"=",
"[",
"event",
"for",
"event",
"in",
"self",
".",
"parse_json",
"(",
"evp",
")",
"]",
"for",
"event",
"in",
"events",
":",
"event_id",
"=",
"event",
"[",
"'id'",
"]",
"event",
"[",
"'comments'",
"]",
"=",
"self",
".",
"__fetch_and_parse_comments",
"(",
"event_id",
")",
"event",
"[",
"'rsvps'",
"]",
"=",
"self",
".",
"__fetch_and_parse_rsvps",
"(",
"event_id",
")",
"# Check events updated before 'to_date'",
"event_ts",
"=",
"self",
".",
"metadata_updated_on",
"(",
"event",
")",
"if",
"to_date_ts",
"and",
"event_ts",
">=",
"to_date_ts",
":",
"stop_fetching",
"=",
"True",
"continue",
"yield",
"event",
"nevents",
"+=",
"1",
"if",
"stop_fetching",
":",
"break",
"logger",
".",
"info",
"(",
"\"Fetch process completed: %s events fetched\"",
",",
"nevents",
")"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
MeetupClient.events
|
Fetch the events pages of a given group.
|
perceval/backends/core/meetup.py
|
def events(self, group, from_date=DEFAULT_DATETIME):
"""Fetch the events pages of a given group."""
date = datetime_to_utc(from_date)
date = date.strftime("since:%Y-%m-%dT%H:%M:%S.000Z")
resource = urijoin(group, self.REVENTS)
# Hack required due to Metup API does not support list
# values with the format `?param=value1¶m=value2`.
# It only works with `?param=value1,value2`.
# Morever, urrlib3 encodes comma characters when values
# are given using params dict, which it doesn't work
# with Meetup, either.
fixed_params = '?' + self.PFIELDS + '=' + ','.join(self.VEVENT_FIELDS)
fixed_params += '&' + self.PSTATUS + '=' + ','.join(self.VSTATUS)
resource += fixed_params
params = {
self.PORDER: self.VUPDATED,
self.PSCROLL: date,
self.PPAGE: self.max_items
}
try:
for page in self._fetch(resource, params):
yield page
except requests.exceptions.HTTPError as error:
if error.response.status_code == 410:
msg = "Group is no longer accessible: {}".format(error)
raise RepositoryError(cause=msg)
else:
raise error
|
def events(self, group, from_date=DEFAULT_DATETIME):
"""Fetch the events pages of a given group."""
date = datetime_to_utc(from_date)
date = date.strftime("since:%Y-%m-%dT%H:%M:%S.000Z")
resource = urijoin(group, self.REVENTS)
# Hack required due to Metup API does not support list
# values with the format `?param=value1¶m=value2`.
# It only works with `?param=value1,value2`.
# Morever, urrlib3 encodes comma characters when values
# are given using params dict, which it doesn't work
# with Meetup, either.
fixed_params = '?' + self.PFIELDS + '=' + ','.join(self.VEVENT_FIELDS)
fixed_params += '&' + self.PSTATUS + '=' + ','.join(self.VSTATUS)
resource += fixed_params
params = {
self.PORDER: self.VUPDATED,
self.PSCROLL: date,
self.PPAGE: self.max_items
}
try:
for page in self._fetch(resource, params):
yield page
except requests.exceptions.HTTPError as error:
if error.response.status_code == 410:
msg = "Group is no longer accessible: {}".format(error)
raise RepositoryError(cause=msg)
else:
raise error
|
[
"Fetch",
"the",
"events",
"pages",
"of",
"a",
"given",
"group",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/meetup.py#L361-L393
|
[
"def",
"events",
"(",
"self",
",",
"group",
",",
"from_date",
"=",
"DEFAULT_DATETIME",
")",
":",
"date",
"=",
"datetime_to_utc",
"(",
"from_date",
")",
"date",
"=",
"date",
".",
"strftime",
"(",
"\"since:%Y-%m-%dT%H:%M:%S.000Z\"",
")",
"resource",
"=",
"urijoin",
"(",
"group",
",",
"self",
".",
"REVENTS",
")",
"# Hack required due to Metup API does not support list",
"# values with the format `?param=value1¶m=value2`.",
"# It only works with `?param=value1,value2`.",
"# Morever, urrlib3 encodes comma characters when values",
"# are given using params dict, which it doesn't work",
"# with Meetup, either.",
"fixed_params",
"=",
"'?'",
"+",
"self",
".",
"PFIELDS",
"+",
"'='",
"+",
"','",
".",
"join",
"(",
"self",
".",
"VEVENT_FIELDS",
")",
"fixed_params",
"+=",
"'&'",
"+",
"self",
".",
"PSTATUS",
"+",
"'='",
"+",
"','",
".",
"join",
"(",
"self",
".",
"VSTATUS",
")",
"resource",
"+=",
"fixed_params",
"params",
"=",
"{",
"self",
".",
"PORDER",
":",
"self",
".",
"VUPDATED",
",",
"self",
".",
"PSCROLL",
":",
"date",
",",
"self",
".",
"PPAGE",
":",
"self",
".",
"max_items",
"}",
"try",
":",
"for",
"page",
"in",
"self",
".",
"_fetch",
"(",
"resource",
",",
"params",
")",
":",
"yield",
"page",
"except",
"requests",
".",
"exceptions",
".",
"HTTPError",
"as",
"error",
":",
"if",
"error",
".",
"response",
".",
"status_code",
"==",
"410",
":",
"msg",
"=",
"\"Group is no longer accessible: {}\"",
".",
"format",
"(",
"error",
")",
"raise",
"RepositoryError",
"(",
"cause",
"=",
"msg",
")",
"else",
":",
"raise",
"error"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
MeetupClient.comments
|
Fetch the comments of a given event.
|
perceval/backends/core/meetup.py
|
def comments(self, group, event_id):
"""Fetch the comments of a given event."""
resource = urijoin(group, self.REVENTS, event_id, self.RCOMMENTS)
params = {
self.PPAGE: self.max_items
}
for page in self._fetch(resource, params):
yield page
|
def comments(self, group, event_id):
"""Fetch the comments of a given event."""
resource = urijoin(group, self.REVENTS, event_id, self.RCOMMENTS)
params = {
self.PPAGE: self.max_items
}
for page in self._fetch(resource, params):
yield page
|
[
"Fetch",
"the",
"comments",
"of",
"a",
"given",
"event",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/meetup.py#L395-L405
|
[
"def",
"comments",
"(",
"self",
",",
"group",
",",
"event_id",
")",
":",
"resource",
"=",
"urijoin",
"(",
"group",
",",
"self",
".",
"REVENTS",
",",
"event_id",
",",
"self",
".",
"RCOMMENTS",
")",
"params",
"=",
"{",
"self",
".",
"PPAGE",
":",
"self",
".",
"max_items",
"}",
"for",
"page",
"in",
"self",
".",
"_fetch",
"(",
"resource",
",",
"params",
")",
":",
"yield",
"page"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
MeetupClient.rsvps
|
Fetch the rsvps of a given event.
|
perceval/backends/core/meetup.py
|
def rsvps(self, group, event_id):
"""Fetch the rsvps of a given event."""
resource = urijoin(group, self.REVENTS, event_id, self.RRSVPS)
# Same hack that in 'events' method
fixed_params = '?' + self.PFIELDS + '=' + ','.join(self.VRSVP_FIELDS)
fixed_params += '&' + self.PRESPONSE + '=' + ','.join(self.VRESPONSE)
resource += fixed_params
params = {
self.PPAGE: self.max_items
}
for page in self._fetch(resource, params):
yield page
|
def rsvps(self, group, event_id):
"""Fetch the rsvps of a given event."""
resource = urijoin(group, self.REVENTS, event_id, self.RRSVPS)
# Same hack that in 'events' method
fixed_params = '?' + self.PFIELDS + '=' + ','.join(self.VRSVP_FIELDS)
fixed_params += '&' + self.PRESPONSE + '=' + ','.join(self.VRESPONSE)
resource += fixed_params
params = {
self.PPAGE: self.max_items
}
for page in self._fetch(resource, params):
yield page
|
[
"Fetch",
"the",
"rsvps",
"of",
"a",
"given",
"event",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/meetup.py#L407-L422
|
[
"def",
"rsvps",
"(",
"self",
",",
"group",
",",
"event_id",
")",
":",
"resource",
"=",
"urijoin",
"(",
"group",
",",
"self",
".",
"REVENTS",
",",
"event_id",
",",
"self",
".",
"RRSVPS",
")",
"# Same hack that in 'events' method",
"fixed_params",
"=",
"'?'",
"+",
"self",
".",
"PFIELDS",
"+",
"'='",
"+",
"','",
".",
"join",
"(",
"self",
".",
"VRSVP_FIELDS",
")",
"fixed_params",
"+=",
"'&'",
"+",
"self",
".",
"PRESPONSE",
"+",
"'='",
"+",
"','",
".",
"join",
"(",
"self",
".",
"VRESPONSE",
")",
"resource",
"+=",
"fixed_params",
"params",
"=",
"{",
"self",
".",
"PPAGE",
":",
"self",
".",
"max_items",
"}",
"for",
"page",
"in",
"self",
".",
"_fetch",
"(",
"resource",
",",
"params",
")",
":",
"yield",
"page"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
MeetupClient.sanitize_for_archive
|
Sanitize payload of a HTTP request by removing the token information
before storing/retrieving archived items
:param: url: HTTP url request
:param: headers: HTTP headers request
:param: payload: HTTP payload request
:returns url, headers and the sanitized payload
|
perceval/backends/core/meetup.py
|
def sanitize_for_archive(url, headers, payload):
"""Sanitize payload of a HTTP request by removing the token information
before storing/retrieving archived items
:param: url: HTTP url request
:param: headers: HTTP headers request
:param: payload: HTTP payload request
:returns url, headers and the sanitized payload
"""
if MeetupClient.PKEY in payload:
payload.pop(MeetupClient.PKEY)
if MeetupClient.PSIGN in payload:
payload.pop(MeetupClient.PSIGN)
return url, headers, payload
|
def sanitize_for_archive(url, headers, payload):
"""Sanitize payload of a HTTP request by removing the token information
before storing/retrieving archived items
:param: url: HTTP url request
:param: headers: HTTP headers request
:param: payload: HTTP payload request
:returns url, headers and the sanitized payload
"""
if MeetupClient.PKEY in payload:
payload.pop(MeetupClient.PKEY)
if MeetupClient.PSIGN in payload:
payload.pop(MeetupClient.PSIGN)
return url, headers, payload
|
[
"Sanitize",
"payload",
"of",
"a",
"HTTP",
"request",
"by",
"removing",
"the",
"token",
"information",
"before",
"storing",
"/",
"retrieving",
"archived",
"items"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/meetup.py#L425-L441
|
[
"def",
"sanitize_for_archive",
"(",
"url",
",",
"headers",
",",
"payload",
")",
":",
"if",
"MeetupClient",
".",
"PKEY",
"in",
"payload",
":",
"payload",
".",
"pop",
"(",
"MeetupClient",
".",
"PKEY",
")",
"if",
"MeetupClient",
".",
"PSIGN",
"in",
"payload",
":",
"payload",
".",
"pop",
"(",
"MeetupClient",
".",
"PSIGN",
")",
"return",
"url",
",",
"headers",
",",
"payload"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
MeetupClient._fetch
|
Fetch a resource.
Method to fetch and to iterate over the contents of a
type of resource. The method returns a generator of
pages for that resource and parameters.
:param resource: type of the resource
:param params: parameters to filter
:returns: a generator of pages for the requeste resource
|
perceval/backends/core/meetup.py
|
def _fetch(self, resource, params):
"""Fetch a resource.
Method to fetch and to iterate over the contents of a
type of resource. The method returns a generator of
pages for that resource and parameters.
:param resource: type of the resource
:param params: parameters to filter
:returns: a generator of pages for the requeste resource
"""
url = urijoin(self.base_url, resource)
params[self.PKEY] = self.api_key
params[self.PSIGN] = 'true',
do_fetch = True
while do_fetch:
logger.debug("Meetup client calls resource: %s params: %s",
resource, str(params))
if not self.from_archive:
self.sleep_for_rate_limit()
r = self.fetch(url, payload=params)
if not self.from_archive:
self.update_rate_limit(r)
yield r.text
if r.links and 'next' in r.links:
url = r.links['next']['url']
params = {
self.PKEY: self.api_key,
self.PSIGN: 'true'
}
else:
do_fetch = False
|
def _fetch(self, resource, params):
"""Fetch a resource.
Method to fetch and to iterate over the contents of a
type of resource. The method returns a generator of
pages for that resource and parameters.
:param resource: type of the resource
:param params: parameters to filter
:returns: a generator of pages for the requeste resource
"""
url = urijoin(self.base_url, resource)
params[self.PKEY] = self.api_key
params[self.PSIGN] = 'true',
do_fetch = True
while do_fetch:
logger.debug("Meetup client calls resource: %s params: %s",
resource, str(params))
if not self.from_archive:
self.sleep_for_rate_limit()
r = self.fetch(url, payload=params)
if not self.from_archive:
self.update_rate_limit(r)
yield r.text
if r.links and 'next' in r.links:
url = r.links['next']['url']
params = {
self.PKEY: self.api_key,
self.PSIGN: 'true'
}
else:
do_fetch = False
|
[
"Fetch",
"a",
"resource",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/meetup.py#L443-L483
|
[
"def",
"_fetch",
"(",
"self",
",",
"resource",
",",
"params",
")",
":",
"url",
"=",
"urijoin",
"(",
"self",
".",
"base_url",
",",
"resource",
")",
"params",
"[",
"self",
".",
"PKEY",
"]",
"=",
"self",
".",
"api_key",
"params",
"[",
"self",
".",
"PSIGN",
"]",
"=",
"'true'",
",",
"do_fetch",
"=",
"True",
"while",
"do_fetch",
":",
"logger",
".",
"debug",
"(",
"\"Meetup client calls resource: %s params: %s\"",
",",
"resource",
",",
"str",
"(",
"params",
")",
")",
"if",
"not",
"self",
".",
"from_archive",
":",
"self",
".",
"sleep_for_rate_limit",
"(",
")",
"r",
"=",
"self",
".",
"fetch",
"(",
"url",
",",
"payload",
"=",
"params",
")",
"if",
"not",
"self",
".",
"from_archive",
":",
"self",
".",
"update_rate_limit",
"(",
"r",
")",
"yield",
"r",
".",
"text",
"if",
"r",
".",
"links",
"and",
"'next'",
"in",
"r",
".",
"links",
":",
"url",
"=",
"r",
".",
"links",
"[",
"'next'",
"]",
"[",
"'url'",
"]",
"params",
"=",
"{",
"self",
".",
"PKEY",
":",
"self",
".",
"api_key",
",",
"self",
".",
"PSIGN",
":",
"'true'",
"}",
"else",
":",
"do_fetch",
"=",
"False"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
Askbot.fetch_items
|
Fetch the questions
:param category: the category of items to fetch
:param kwargs: backend arguments
:returns: a generator of items
|
perceval/backends/core/askbot.py
|
def fetch_items(self, category, **kwargs):
"""Fetch the questions
:param category: the category of items to fetch
:param kwargs: backend arguments
:returns: a generator of items
"""
from_date = datetime_to_utc(kwargs['from_date']).timestamp()
questions_groups = self.client.get_api_questions(AskbotClient.API_QUESTIONS)
for questions in questions_groups:
for question in questions['questions']:
updated_at = int(question['last_activity_at'])
if updated_at > from_date:
html_question = self.__fetch_question(question)
if not html_question:
continue
logger.debug("Fetching HTML question %s", question['id'])
comments = self.__fetch_comments(question)
question_obj = self.__build_question(html_question, question, comments)
question.update(question_obj)
yield question
|
def fetch_items(self, category, **kwargs):
"""Fetch the questions
:param category: the category of items to fetch
:param kwargs: backend arguments
:returns: a generator of items
"""
from_date = datetime_to_utc(kwargs['from_date']).timestamp()
questions_groups = self.client.get_api_questions(AskbotClient.API_QUESTIONS)
for questions in questions_groups:
for question in questions['questions']:
updated_at = int(question['last_activity_at'])
if updated_at > from_date:
html_question = self.__fetch_question(question)
if not html_question:
continue
logger.debug("Fetching HTML question %s", question['id'])
comments = self.__fetch_comments(question)
question_obj = self.__build_question(html_question, question, comments)
question.update(question_obj)
yield question
|
[
"Fetch",
"the",
"questions"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/askbot.py#L87-L112
|
[
"def",
"fetch_items",
"(",
"self",
",",
"category",
",",
"*",
"*",
"kwargs",
")",
":",
"from_date",
"=",
"datetime_to_utc",
"(",
"kwargs",
"[",
"'from_date'",
"]",
")",
".",
"timestamp",
"(",
")",
"questions_groups",
"=",
"self",
".",
"client",
".",
"get_api_questions",
"(",
"AskbotClient",
".",
"API_QUESTIONS",
")",
"for",
"questions",
"in",
"questions_groups",
":",
"for",
"question",
"in",
"questions",
"[",
"'questions'",
"]",
":",
"updated_at",
"=",
"int",
"(",
"question",
"[",
"'last_activity_at'",
"]",
")",
"if",
"updated_at",
">",
"from_date",
":",
"html_question",
"=",
"self",
".",
"__fetch_question",
"(",
"question",
")",
"if",
"not",
"html_question",
":",
"continue",
"logger",
".",
"debug",
"(",
"\"Fetching HTML question %s\"",
",",
"question",
"[",
"'id'",
"]",
")",
"comments",
"=",
"self",
".",
"__fetch_comments",
"(",
"question",
")",
"question_obj",
"=",
"self",
".",
"__build_question",
"(",
"html_question",
",",
"question",
",",
"comments",
")",
"question",
".",
"update",
"(",
"question_obj",
")",
"yield",
"question"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
Askbot._init_client
|
Init client
|
perceval/backends/core/askbot.py
|
def _init_client(self, from_archive=False):
"""Init client"""
return AskbotClient(self.url, self.archive, from_archive)
|
def _init_client(self, from_archive=False):
"""Init client"""
return AskbotClient(self.url, self.archive, from_archive)
|
[
"Init",
"client"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/askbot.py#L159-L162
|
[
"def",
"_init_client",
"(",
"self",
",",
"from_archive",
"=",
"False",
")",
":",
"return",
"AskbotClient",
"(",
"self",
".",
"url",
",",
"self",
".",
"archive",
",",
"from_archive",
")"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
Askbot.__fetch_question
|
Fetch an Askbot HTML question body.
The method fetchs the HTML question retrieving the
question body of the item question received
:param question: item with the question itself
:returns: a list of HTML page/s for the question
|
perceval/backends/core/askbot.py
|
def __fetch_question(self, question):
"""Fetch an Askbot HTML question body.
The method fetchs the HTML question retrieving the
question body of the item question received
:param question: item with the question itself
:returns: a list of HTML page/s for the question
"""
html_question_items = []
npages = 1
next_request = True
while next_request:
try:
html_question = self.client.get_html_question(question['id'], npages)
html_question_items.append(html_question)
tpages = self.ab_parser.parse_number_of_html_pages(html_question)
if npages == tpages:
next_request = False
npages = npages + 1
except requests.exceptions.TooManyRedirects as e:
logger.warning("%s, data not retrieved for question %s", e, question['id'])
next_request = False
return html_question_items
|
def __fetch_question(self, question):
"""Fetch an Askbot HTML question body.
The method fetchs the HTML question retrieving the
question body of the item question received
:param question: item with the question itself
:returns: a list of HTML page/s for the question
"""
html_question_items = []
npages = 1
next_request = True
while next_request:
try:
html_question = self.client.get_html_question(question['id'], npages)
html_question_items.append(html_question)
tpages = self.ab_parser.parse_number_of_html_pages(html_question)
if npages == tpages:
next_request = False
npages = npages + 1
except requests.exceptions.TooManyRedirects as e:
logger.warning("%s, data not retrieved for question %s", e, question['id'])
next_request = False
return html_question_items
|
[
"Fetch",
"an",
"Askbot",
"HTML",
"question",
"body",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/askbot.py#L164-L193
|
[
"def",
"__fetch_question",
"(",
"self",
",",
"question",
")",
":",
"html_question_items",
"=",
"[",
"]",
"npages",
"=",
"1",
"next_request",
"=",
"True",
"while",
"next_request",
":",
"try",
":",
"html_question",
"=",
"self",
".",
"client",
".",
"get_html_question",
"(",
"question",
"[",
"'id'",
"]",
",",
"npages",
")",
"html_question_items",
".",
"append",
"(",
"html_question",
")",
"tpages",
"=",
"self",
".",
"ab_parser",
".",
"parse_number_of_html_pages",
"(",
"html_question",
")",
"if",
"npages",
"==",
"tpages",
":",
"next_request",
"=",
"False",
"npages",
"=",
"npages",
"+",
"1",
"except",
"requests",
".",
"exceptions",
".",
"TooManyRedirects",
"as",
"e",
":",
"logger",
".",
"warning",
"(",
"\"%s, data not retrieved for question %s\"",
",",
"e",
",",
"question",
"[",
"'id'",
"]",
")",
"next_request",
"=",
"False",
"return",
"html_question_items"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
Askbot.__fetch_comments
|
Fetch all the comments of an Askbot question and answers.
The method fetchs the list of every comment existing in a question and
its answers.
:param question: item with the question itself
:returns: a list of comments with the ids as hashes
|
perceval/backends/core/askbot.py
|
def __fetch_comments(self, question):
"""Fetch all the comments of an Askbot question and answers.
The method fetchs the list of every comment existing in a question and
its answers.
:param question: item with the question itself
:returns: a list of comments with the ids as hashes
"""
comments = {}
comments[question['id']] = json.loads(self.client.get_comments(question['id']))
for object_id in question['answer_ids']:
comments[object_id] = json.loads(self.client.get_comments(object_id))
return comments
|
def __fetch_comments(self, question):
"""Fetch all the comments of an Askbot question and answers.
The method fetchs the list of every comment existing in a question and
its answers.
:param question: item with the question itself
:returns: a list of comments with the ids as hashes
"""
comments = {}
comments[question['id']] = json.loads(self.client.get_comments(question['id']))
for object_id in question['answer_ids']:
comments[object_id] = json.loads(self.client.get_comments(object_id))
return comments
|
[
"Fetch",
"all",
"the",
"comments",
"of",
"an",
"Askbot",
"question",
"and",
"answers",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/askbot.py#L195-L209
|
[
"def",
"__fetch_comments",
"(",
"self",
",",
"question",
")",
":",
"comments",
"=",
"{",
"}",
"comments",
"[",
"question",
"[",
"'id'",
"]",
"]",
"=",
"json",
".",
"loads",
"(",
"self",
".",
"client",
".",
"get_comments",
"(",
"question",
"[",
"'id'",
"]",
")",
")",
"for",
"object_id",
"in",
"question",
"[",
"'answer_ids'",
"]",
":",
"comments",
"[",
"object_id",
"]",
"=",
"json",
".",
"loads",
"(",
"self",
".",
"client",
".",
"get_comments",
"(",
"object_id",
")",
")",
"return",
"comments"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
Askbot.__build_question
|
Build an Askbot HTML response.
The method puts together all the information regarding a question
:param html_question: array of HTML raw pages
:param question: question object from the API
:param comments: list of comments to add
:returns: a dict item with the parsed question information
|
perceval/backends/core/askbot.py
|
def __build_question(html_question, question, comments):
"""Build an Askbot HTML response.
The method puts together all the information regarding a question
:param html_question: array of HTML raw pages
:param question: question object from the API
:param comments: list of comments to add
:returns: a dict item with the parsed question information
"""
question_object = {}
# Parse the user info from the soup container
question_container = AskbotParser.parse_question_container(html_question[0])
# Add the info to the question object
question_object.update(question_container)
# Add the comments of the question (if any)
if comments[int(question['id'])]:
question_object['comments'] = comments[int(question['id'])]
answers = []
for page in html_question:
answers.extend(AskbotParser.parse_answers(page))
if len(answers) != 0:
question_object['answers'] = answers
for answer in question_object['answers']:
if comments[int(answer['id'])]:
answer['comments'] = comments[int(answer['id'])]
return question_object
|
def __build_question(html_question, question, comments):
"""Build an Askbot HTML response.
The method puts together all the information regarding a question
:param html_question: array of HTML raw pages
:param question: question object from the API
:param comments: list of comments to add
:returns: a dict item with the parsed question information
"""
question_object = {}
# Parse the user info from the soup container
question_container = AskbotParser.parse_question_container(html_question[0])
# Add the info to the question object
question_object.update(question_container)
# Add the comments of the question (if any)
if comments[int(question['id'])]:
question_object['comments'] = comments[int(question['id'])]
answers = []
for page in html_question:
answers.extend(AskbotParser.parse_answers(page))
if len(answers) != 0:
question_object['answers'] = answers
for answer in question_object['answers']:
if comments[int(answer['id'])]:
answer['comments'] = comments[int(answer['id'])]
return question_object
|
[
"Build",
"an",
"Askbot",
"HTML",
"response",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/askbot.py#L212-L243
|
[
"def",
"__build_question",
"(",
"html_question",
",",
"question",
",",
"comments",
")",
":",
"question_object",
"=",
"{",
"}",
"# Parse the user info from the soup container",
"question_container",
"=",
"AskbotParser",
".",
"parse_question_container",
"(",
"html_question",
"[",
"0",
"]",
")",
"# Add the info to the question object",
"question_object",
".",
"update",
"(",
"question_container",
")",
"# Add the comments of the question (if any)",
"if",
"comments",
"[",
"int",
"(",
"question",
"[",
"'id'",
"]",
")",
"]",
":",
"question_object",
"[",
"'comments'",
"]",
"=",
"comments",
"[",
"int",
"(",
"question",
"[",
"'id'",
"]",
")",
"]",
"answers",
"=",
"[",
"]",
"for",
"page",
"in",
"html_question",
":",
"answers",
".",
"extend",
"(",
"AskbotParser",
".",
"parse_answers",
"(",
"page",
")",
")",
"if",
"len",
"(",
"answers",
")",
"!=",
"0",
":",
"question_object",
"[",
"'answers'",
"]",
"=",
"answers",
"for",
"answer",
"in",
"question_object",
"[",
"'answers'",
"]",
":",
"if",
"comments",
"[",
"int",
"(",
"answer",
"[",
"'id'",
"]",
")",
"]",
":",
"answer",
"[",
"'comments'",
"]",
"=",
"comments",
"[",
"int",
"(",
"answer",
"[",
"'id'",
"]",
")",
"]",
"return",
"question_object"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
AskbotClient.get_api_questions
|
Retrieve a question page using the API.
:param page: page to retrieve
|
perceval/backends/core/askbot.py
|
def get_api_questions(self, path):
"""Retrieve a question page using the API.
:param page: page to retrieve
"""
npages = 1
next_request = True
path = urijoin(self.base_url, path)
while next_request:
try:
params = {
'page': npages,
'sort': self.ORDER_API
}
response = self.fetch(path, payload=params)
whole_page = response.text
raw_questions = json.loads(whole_page)
tpages = raw_questions['pages']
logger.debug("Fetching questions from '%s': page %s/%s",
self.base_url, npages, tpages)
if npages == tpages:
next_request = False
npages = npages + 1
yield raw_questions
except requests.exceptions.TooManyRedirects as e:
logger.warning("%s, data not retrieved for resource %s", e, path)
next_request = False
|
def get_api_questions(self, path):
"""Retrieve a question page using the API.
:param page: page to retrieve
"""
npages = 1
next_request = True
path = urijoin(self.base_url, path)
while next_request:
try:
params = {
'page': npages,
'sort': self.ORDER_API
}
response = self.fetch(path, payload=params)
whole_page = response.text
raw_questions = json.loads(whole_page)
tpages = raw_questions['pages']
logger.debug("Fetching questions from '%s': page %s/%s",
self.base_url, npages, tpages)
if npages == tpages:
next_request = False
npages = npages + 1
yield raw_questions
except requests.exceptions.TooManyRedirects as e:
logger.warning("%s, data not retrieved for resource %s", e, path)
next_request = False
|
[
"Retrieve",
"a",
"question",
"page",
"using",
"the",
"API",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/askbot.py#L270-L305
|
[
"def",
"get_api_questions",
"(",
"self",
",",
"path",
")",
":",
"npages",
"=",
"1",
"next_request",
"=",
"True",
"path",
"=",
"urijoin",
"(",
"self",
".",
"base_url",
",",
"path",
")",
"while",
"next_request",
":",
"try",
":",
"params",
"=",
"{",
"'page'",
":",
"npages",
",",
"'sort'",
":",
"self",
".",
"ORDER_API",
"}",
"response",
"=",
"self",
".",
"fetch",
"(",
"path",
",",
"payload",
"=",
"params",
")",
"whole_page",
"=",
"response",
".",
"text",
"raw_questions",
"=",
"json",
".",
"loads",
"(",
"whole_page",
")",
"tpages",
"=",
"raw_questions",
"[",
"'pages'",
"]",
"logger",
".",
"debug",
"(",
"\"Fetching questions from '%s': page %s/%s\"",
",",
"self",
".",
"base_url",
",",
"npages",
",",
"tpages",
")",
"if",
"npages",
"==",
"tpages",
":",
"next_request",
"=",
"False",
"npages",
"=",
"npages",
"+",
"1",
"yield",
"raw_questions",
"except",
"requests",
".",
"exceptions",
".",
"TooManyRedirects",
"as",
"e",
":",
"logger",
".",
"warning",
"(",
"\"%s, data not retrieved for resource %s\"",
",",
"e",
",",
"path",
")",
"next_request",
"=",
"False"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
AskbotClient.get_html_question
|
Retrieve a raw HTML question and all it's information.
:param question_id: question identifier
:param page: page to retrieve
|
perceval/backends/core/askbot.py
|
def get_html_question(self, question_id, page=1):
"""Retrieve a raw HTML question and all it's information.
:param question_id: question identifier
:param page: page to retrieve
"""
path = urijoin(self.base_url, self.HTML_QUESTION, question_id)
params = {
'page': page,
'sort': self.ORDER_HTML
}
response = self.fetch(path, payload=params)
return response.text
|
def get_html_question(self, question_id, page=1):
"""Retrieve a raw HTML question and all it's information.
:param question_id: question identifier
:param page: page to retrieve
"""
path = urijoin(self.base_url, self.HTML_QUESTION, question_id)
params = {
'page': page,
'sort': self.ORDER_HTML
}
response = self.fetch(path, payload=params)
return response.text
|
[
"Retrieve",
"a",
"raw",
"HTML",
"question",
"and",
"all",
"it",
"s",
"information",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/askbot.py#L307-L320
|
[
"def",
"get_html_question",
"(",
"self",
",",
"question_id",
",",
"page",
"=",
"1",
")",
":",
"path",
"=",
"urijoin",
"(",
"self",
".",
"base_url",
",",
"self",
".",
"HTML_QUESTION",
",",
"question_id",
")",
"params",
"=",
"{",
"'page'",
":",
"page",
",",
"'sort'",
":",
"self",
".",
"ORDER_HTML",
"}",
"response",
"=",
"self",
".",
"fetch",
"(",
"path",
",",
"payload",
"=",
"params",
")",
"return",
"response",
".",
"text"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
AskbotClient.get_comments
|
Retrieve a list of comments by a given id.
:param object_id: object identifiere
|
perceval/backends/core/askbot.py
|
def get_comments(self, post_id):
"""Retrieve a list of comments by a given id.
:param object_id: object identifiere
"""
path = urijoin(self.base_url, self.COMMENTS if self._use_new_urls else self.COMMENTS_OLD)
params = {
'post_id': post_id,
'post_type': 'answer',
'avatar_size': 0
}
headers = {'X-Requested-With': 'XMLHttpRequest'}
try:
response = self.fetch(path, payload=params, headers=headers)
raw = response.text
except requests.exceptions.HTTPError as ex:
if ex.response.status_code == 404:
logger.debug("Comments URL did not work. Using old URL schema.")
self._use_new_urls = False
path = urijoin(self.base_url, self.COMMENTS_OLD)
response = self.fetch(path, payload=params, headers=headers)
raw = response.text
elif ex.response.status_code == 500:
logger.warning("Comments not retrieved due to %s", ex)
raw = '[]'
else:
raise ex
return raw
|
def get_comments(self, post_id):
"""Retrieve a list of comments by a given id.
:param object_id: object identifiere
"""
path = urijoin(self.base_url, self.COMMENTS if self._use_new_urls else self.COMMENTS_OLD)
params = {
'post_id': post_id,
'post_type': 'answer',
'avatar_size': 0
}
headers = {'X-Requested-With': 'XMLHttpRequest'}
try:
response = self.fetch(path, payload=params, headers=headers)
raw = response.text
except requests.exceptions.HTTPError as ex:
if ex.response.status_code == 404:
logger.debug("Comments URL did not work. Using old URL schema.")
self._use_new_urls = False
path = urijoin(self.base_url, self.COMMENTS_OLD)
response = self.fetch(path, payload=params, headers=headers)
raw = response.text
elif ex.response.status_code == 500:
logger.warning("Comments not retrieved due to %s", ex)
raw = '[]'
else:
raise ex
return raw
|
[
"Retrieve",
"a",
"list",
"of",
"comments",
"by",
"a",
"given",
"id",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/askbot.py#L322-L351
|
[
"def",
"get_comments",
"(",
"self",
",",
"post_id",
")",
":",
"path",
"=",
"urijoin",
"(",
"self",
".",
"base_url",
",",
"self",
".",
"COMMENTS",
"if",
"self",
".",
"_use_new_urls",
"else",
"self",
".",
"COMMENTS_OLD",
")",
"params",
"=",
"{",
"'post_id'",
":",
"post_id",
",",
"'post_type'",
":",
"'answer'",
",",
"'avatar_size'",
":",
"0",
"}",
"headers",
"=",
"{",
"'X-Requested-With'",
":",
"'XMLHttpRequest'",
"}",
"try",
":",
"response",
"=",
"self",
".",
"fetch",
"(",
"path",
",",
"payload",
"=",
"params",
",",
"headers",
"=",
"headers",
")",
"raw",
"=",
"response",
".",
"text",
"except",
"requests",
".",
"exceptions",
".",
"HTTPError",
"as",
"ex",
":",
"if",
"ex",
".",
"response",
".",
"status_code",
"==",
"404",
":",
"logger",
".",
"debug",
"(",
"\"Comments URL did not work. Using old URL schema.\"",
")",
"self",
".",
"_use_new_urls",
"=",
"False",
"path",
"=",
"urijoin",
"(",
"self",
".",
"base_url",
",",
"self",
".",
"COMMENTS_OLD",
")",
"response",
"=",
"self",
".",
"fetch",
"(",
"path",
",",
"payload",
"=",
"params",
",",
"headers",
"=",
"headers",
")",
"raw",
"=",
"response",
".",
"text",
"elif",
"ex",
".",
"response",
".",
"status_code",
"==",
"500",
":",
"logger",
".",
"warning",
"(",
"\"Comments not retrieved due to %s\"",
",",
"ex",
")",
"raw",
"=",
"'[]'",
"else",
":",
"raise",
"ex",
"return",
"raw"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
AskbotParser.parse_question_container
|
Parse the question info container of a given HTML question.
The method parses the information available in the question information
container. The container can have up to 2 elements: the first one
contains the information related with the user who generated the question
and the date (if any). The second one contains the date of the updated,
and the user who updated it (if not the same who generated the question).
:param html_question: raw HTML question element
:returns: an object with the parsed information
|
perceval/backends/core/askbot.py
|
def parse_question_container(html_question):
"""Parse the question info container of a given HTML question.
The method parses the information available in the question information
container. The container can have up to 2 elements: the first one
contains the information related with the user who generated the question
and the date (if any). The second one contains the date of the updated,
and the user who updated it (if not the same who generated the question).
:param html_question: raw HTML question element
:returns: an object with the parsed information
"""
container_info = {}
bs_question = bs4.BeautifulSoup(html_question, "html.parser")
question = AskbotParser._find_question_container(bs_question)
container = question.select("div.post-update-info")
created = container[0]
container_info['author'] = AskbotParser.parse_user_info(created)
try:
container[1]
except IndexError:
pass
else:
updated = container[1]
if AskbotParser.parse_user_info(updated):
container_info['updated_by'] = AskbotParser.parse_user_info(updated)
return container_info
|
def parse_question_container(html_question):
"""Parse the question info container of a given HTML question.
The method parses the information available in the question information
container. The container can have up to 2 elements: the first one
contains the information related with the user who generated the question
and the date (if any). The second one contains the date of the updated,
and the user who updated it (if not the same who generated the question).
:param html_question: raw HTML question element
:returns: an object with the parsed information
"""
container_info = {}
bs_question = bs4.BeautifulSoup(html_question, "html.parser")
question = AskbotParser._find_question_container(bs_question)
container = question.select("div.post-update-info")
created = container[0]
container_info['author'] = AskbotParser.parse_user_info(created)
try:
container[1]
except IndexError:
pass
else:
updated = container[1]
if AskbotParser.parse_user_info(updated):
container_info['updated_by'] = AskbotParser.parse_user_info(updated)
return container_info
|
[
"Parse",
"the",
"question",
"info",
"container",
"of",
"a",
"given",
"HTML",
"question",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/askbot.py#L362-L390
|
[
"def",
"parse_question_container",
"(",
"html_question",
")",
":",
"container_info",
"=",
"{",
"}",
"bs_question",
"=",
"bs4",
".",
"BeautifulSoup",
"(",
"html_question",
",",
"\"html.parser\"",
")",
"question",
"=",
"AskbotParser",
".",
"_find_question_container",
"(",
"bs_question",
")",
"container",
"=",
"question",
".",
"select",
"(",
"\"div.post-update-info\"",
")",
"created",
"=",
"container",
"[",
"0",
"]",
"container_info",
"[",
"'author'",
"]",
"=",
"AskbotParser",
".",
"parse_user_info",
"(",
"created",
")",
"try",
":",
"container",
"[",
"1",
"]",
"except",
"IndexError",
":",
"pass",
"else",
":",
"updated",
"=",
"container",
"[",
"1",
"]",
"if",
"AskbotParser",
".",
"parse_user_info",
"(",
"updated",
")",
":",
"container_info",
"[",
"'updated_by'",
"]",
"=",
"AskbotParser",
".",
"parse_user_info",
"(",
"updated",
")",
"return",
"container_info"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
AskbotParser.parse_answers
|
Parse the answers of a given HTML question.
The method parses the answers related with a given HTML question,
as well as all the comments related to the answer.
:param html_question: raw HTML question element
:returns: a list with the answers
|
perceval/backends/core/askbot.py
|
def parse_answers(html_question):
"""Parse the answers of a given HTML question.
The method parses the answers related with a given HTML question,
as well as all the comments related to the answer.
:param html_question: raw HTML question element
:returns: a list with the answers
"""
def parse_answer_container(update_info):
"""Parse the answer info container of a given HTML question.
The method parses the information available in the answer information
container. The container can have up to 2 elements: the first one
contains the information related with the user who generated the question
and the date (if any). The second one contains the date of the updated,
and the user who updated it (if not the same who generated the question).
:param update_info: beautiful soup update_info container element
:returns: an object with the parsed information
"""
container_info = {}
created = update_info[0]
answered_at = created.abbr.attrs["title"]
# Convert date to UNIX timestamp
container_info['added_at'] = str(str_to_datetime(answered_at).timestamp())
container_info['answered_by'] = AskbotParser.parse_user_info(created)
try:
update_info[1]
except IndexError:
pass
else:
updated = update_info[1]
updated_at = updated.abbr.attrs["title"]
# Convert date to UNIX timestamp
container_info['updated_at'] = str(str_to_datetime(updated_at).timestamp())
if AskbotParser.parse_user_info(updated):
container_info['updated_by'] = AskbotParser.parse_user_info(updated)
return container_info
answer_list = []
# Select all the answers
bs_question = bs4.BeautifulSoup(html_question, "html.parser")
bs_answers = bs_question.select("div.answer")
for bs_answer in bs_answers:
answer_id = bs_answer.attrs["data-post-id"]
votes_element = bs_answer.select("div.vote-number")[0].text
accepted_answer = bs_answer.select("div.answer-img-accept")[0].get('title').endswith("correct")
# Select the body of the answer
body = bs_answer.select("div.post-body")
# Get the user information container and parse it
update_info = body[0].select("div.post-update-info")
answer_container = parse_answer_container(update_info)
# Remove the update-info-container div to be able to get the body
body[0].div.extract().select("div.post-update-info-container")
# Override the body with a clean one
body = body[0].get_text(strip=True)
# Generate the answer object
answer = {'id': answer_id,
'score': votes_element,
'summary': body,
'accepted': accepted_answer
}
# Update the object with the information in the answer container
answer.update(answer_container)
answer_list.append(answer)
return answer_list
|
def parse_answers(html_question):
"""Parse the answers of a given HTML question.
The method parses the answers related with a given HTML question,
as well as all the comments related to the answer.
:param html_question: raw HTML question element
:returns: a list with the answers
"""
def parse_answer_container(update_info):
"""Parse the answer info container of a given HTML question.
The method parses the information available in the answer information
container. The container can have up to 2 elements: the first one
contains the information related with the user who generated the question
and the date (if any). The second one contains the date of the updated,
and the user who updated it (if not the same who generated the question).
:param update_info: beautiful soup update_info container element
:returns: an object with the parsed information
"""
container_info = {}
created = update_info[0]
answered_at = created.abbr.attrs["title"]
# Convert date to UNIX timestamp
container_info['added_at'] = str(str_to_datetime(answered_at).timestamp())
container_info['answered_by'] = AskbotParser.parse_user_info(created)
try:
update_info[1]
except IndexError:
pass
else:
updated = update_info[1]
updated_at = updated.abbr.attrs["title"]
# Convert date to UNIX timestamp
container_info['updated_at'] = str(str_to_datetime(updated_at).timestamp())
if AskbotParser.parse_user_info(updated):
container_info['updated_by'] = AskbotParser.parse_user_info(updated)
return container_info
answer_list = []
# Select all the answers
bs_question = bs4.BeautifulSoup(html_question, "html.parser")
bs_answers = bs_question.select("div.answer")
for bs_answer in bs_answers:
answer_id = bs_answer.attrs["data-post-id"]
votes_element = bs_answer.select("div.vote-number")[0].text
accepted_answer = bs_answer.select("div.answer-img-accept")[0].get('title').endswith("correct")
# Select the body of the answer
body = bs_answer.select("div.post-body")
# Get the user information container and parse it
update_info = body[0].select("div.post-update-info")
answer_container = parse_answer_container(update_info)
# Remove the update-info-container div to be able to get the body
body[0].div.extract().select("div.post-update-info-container")
# Override the body with a clean one
body = body[0].get_text(strip=True)
# Generate the answer object
answer = {'id': answer_id,
'score': votes_element,
'summary': body,
'accepted': accepted_answer
}
# Update the object with the information in the answer container
answer.update(answer_container)
answer_list.append(answer)
return answer_list
|
[
"Parse",
"the",
"answers",
"of",
"a",
"given",
"HTML",
"question",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/askbot.py#L393-L462
|
[
"def",
"parse_answers",
"(",
"html_question",
")",
":",
"def",
"parse_answer_container",
"(",
"update_info",
")",
":",
"\"\"\"Parse the answer info container of a given HTML question.\n\n The method parses the information available in the answer information\n container. The container can have up to 2 elements: the first one\n contains the information related with the user who generated the question\n and the date (if any). The second one contains the date of the updated,\n and the user who updated it (if not the same who generated the question).\n\n :param update_info: beautiful soup update_info container element\n\n :returns: an object with the parsed information\n \"\"\"",
"container_info",
"=",
"{",
"}",
"created",
"=",
"update_info",
"[",
"0",
"]",
"answered_at",
"=",
"created",
".",
"abbr",
".",
"attrs",
"[",
"\"title\"",
"]",
"# Convert date to UNIX timestamp",
"container_info",
"[",
"'added_at'",
"]",
"=",
"str",
"(",
"str_to_datetime",
"(",
"answered_at",
")",
".",
"timestamp",
"(",
")",
")",
"container_info",
"[",
"'answered_by'",
"]",
"=",
"AskbotParser",
".",
"parse_user_info",
"(",
"created",
")",
"try",
":",
"update_info",
"[",
"1",
"]",
"except",
"IndexError",
":",
"pass",
"else",
":",
"updated",
"=",
"update_info",
"[",
"1",
"]",
"updated_at",
"=",
"updated",
".",
"abbr",
".",
"attrs",
"[",
"\"title\"",
"]",
"# Convert date to UNIX timestamp",
"container_info",
"[",
"'updated_at'",
"]",
"=",
"str",
"(",
"str_to_datetime",
"(",
"updated_at",
")",
".",
"timestamp",
"(",
")",
")",
"if",
"AskbotParser",
".",
"parse_user_info",
"(",
"updated",
")",
":",
"container_info",
"[",
"'updated_by'",
"]",
"=",
"AskbotParser",
".",
"parse_user_info",
"(",
"updated",
")",
"return",
"container_info",
"answer_list",
"=",
"[",
"]",
"# Select all the answers",
"bs_question",
"=",
"bs4",
".",
"BeautifulSoup",
"(",
"html_question",
",",
"\"html.parser\"",
")",
"bs_answers",
"=",
"bs_question",
".",
"select",
"(",
"\"div.answer\"",
")",
"for",
"bs_answer",
"in",
"bs_answers",
":",
"answer_id",
"=",
"bs_answer",
".",
"attrs",
"[",
"\"data-post-id\"",
"]",
"votes_element",
"=",
"bs_answer",
".",
"select",
"(",
"\"div.vote-number\"",
")",
"[",
"0",
"]",
".",
"text",
"accepted_answer",
"=",
"bs_answer",
".",
"select",
"(",
"\"div.answer-img-accept\"",
")",
"[",
"0",
"]",
".",
"get",
"(",
"'title'",
")",
".",
"endswith",
"(",
"\"correct\"",
")",
"# Select the body of the answer",
"body",
"=",
"bs_answer",
".",
"select",
"(",
"\"div.post-body\"",
")",
"# Get the user information container and parse it",
"update_info",
"=",
"body",
"[",
"0",
"]",
".",
"select",
"(",
"\"div.post-update-info\"",
")",
"answer_container",
"=",
"parse_answer_container",
"(",
"update_info",
")",
"# Remove the update-info-container div to be able to get the body",
"body",
"[",
"0",
"]",
".",
"div",
".",
"extract",
"(",
")",
".",
"select",
"(",
"\"div.post-update-info-container\"",
")",
"# Override the body with a clean one",
"body",
"=",
"body",
"[",
"0",
"]",
".",
"get_text",
"(",
"strip",
"=",
"True",
")",
"# Generate the answer object",
"answer",
"=",
"{",
"'id'",
":",
"answer_id",
",",
"'score'",
":",
"votes_element",
",",
"'summary'",
":",
"body",
",",
"'accepted'",
":",
"accepted_answer",
"}",
"# Update the object with the information in the answer container",
"answer",
".",
"update",
"(",
"answer_container",
")",
"answer_list",
".",
"append",
"(",
"answer",
")",
"return",
"answer_list"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
AskbotParser.parse_number_of_html_pages
|
Parse number of answer pages to paginate over them.
:param html_question: raw HTML question element
:returns: an integer with the number of pages
|
perceval/backends/core/askbot.py
|
def parse_number_of_html_pages(html_question):
"""Parse number of answer pages to paginate over them.
:param html_question: raw HTML question element
:returns: an integer with the number of pages
"""
bs_question = bs4.BeautifulSoup(html_question, "html.parser")
try:
bs_question.select('div.paginator')[0]
except IndexError:
return 1
else:
return int(bs_question.select('div.paginator')[0].attrs['data-num-pages'])
|
def parse_number_of_html_pages(html_question):
"""Parse number of answer pages to paginate over them.
:param html_question: raw HTML question element
:returns: an integer with the number of pages
"""
bs_question = bs4.BeautifulSoup(html_question, "html.parser")
try:
bs_question.select('div.paginator')[0]
except IndexError:
return 1
else:
return int(bs_question.select('div.paginator')[0].attrs['data-num-pages'])
|
[
"Parse",
"number",
"of",
"answer",
"pages",
"to",
"paginate",
"over",
"them",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/askbot.py#L465-L478
|
[
"def",
"parse_number_of_html_pages",
"(",
"html_question",
")",
":",
"bs_question",
"=",
"bs4",
".",
"BeautifulSoup",
"(",
"html_question",
",",
"\"html.parser\"",
")",
"try",
":",
"bs_question",
".",
"select",
"(",
"'div.paginator'",
")",
"[",
"0",
"]",
"except",
"IndexError",
":",
"return",
"1",
"else",
":",
"return",
"int",
"(",
"bs_question",
".",
"select",
"(",
"'div.paginator'",
")",
"[",
"0",
"]",
".",
"attrs",
"[",
"'data-num-pages'",
"]",
")"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
AskbotParser.parse_user_info
|
Parse the user information of a given HTML container.
The method parses all the available user information in the container.
If the class "user-info" exists, the method will get all the available
information in the container. If not, if a class "tip" exists, it will be
a wiki post with no user associated. Else, it can be an empty container.
:param update_info: beautiful soup answer container element
:returns: an object with the parsed information
|
perceval/backends/core/askbot.py
|
def parse_user_info(update_info):
"""Parse the user information of a given HTML container.
The method parses all the available user information in the container.
If the class "user-info" exists, the method will get all the available
information in the container. If not, if a class "tip" exists, it will be
a wiki post with no user associated. Else, it can be an empty container.
:param update_info: beautiful soup answer container element
:returns: an object with the parsed information
"""
user_info = {}
if update_info.select("div.user-info"):
# Get all the <a> elements in the container. First <a> contains the user
# information, second one (if exists), the website of the user.
elements = update_info.select("div.user-info")[0].find_all("a")
href = elements[0].attrs["href"]
user_info['id'] = re.search(r'\d+', href).group(0)
user_info['username'] = elements[0].text
user_info['reputation'] = update_info.select('span.reputation-score')[0].text
user_info['badges'] = update_info.select("span.badges")[0].attrs["title"]
try:
elements[1]
except IndexError:
pass
else:
user_info['website'] = elements[1].attrs["href"]
if update_info.select("img.flag"):
flag = update_info.select("img.flag")[0].attrs["alt"]
user_info['country'] = re.sub("flag of ", "", flag)
return user_info
|
def parse_user_info(update_info):
"""Parse the user information of a given HTML container.
The method parses all the available user information in the container.
If the class "user-info" exists, the method will get all the available
information in the container. If not, if a class "tip" exists, it will be
a wiki post with no user associated. Else, it can be an empty container.
:param update_info: beautiful soup answer container element
:returns: an object with the parsed information
"""
user_info = {}
if update_info.select("div.user-info"):
# Get all the <a> elements in the container. First <a> contains the user
# information, second one (if exists), the website of the user.
elements = update_info.select("div.user-info")[0].find_all("a")
href = elements[0].attrs["href"]
user_info['id'] = re.search(r'\d+', href).group(0)
user_info['username'] = elements[0].text
user_info['reputation'] = update_info.select('span.reputation-score')[0].text
user_info['badges'] = update_info.select("span.badges")[0].attrs["title"]
try:
elements[1]
except IndexError:
pass
else:
user_info['website'] = elements[1].attrs["href"]
if update_info.select("img.flag"):
flag = update_info.select("img.flag")[0].attrs["alt"]
user_info['country'] = re.sub("flag of ", "", flag)
return user_info
|
[
"Parse",
"the",
"user",
"information",
"of",
"a",
"given",
"HTML",
"container",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/askbot.py#L481-L513
|
[
"def",
"parse_user_info",
"(",
"update_info",
")",
":",
"user_info",
"=",
"{",
"}",
"if",
"update_info",
".",
"select",
"(",
"\"div.user-info\"",
")",
":",
"# Get all the <a> elements in the container. First <a> contains the user",
"# information, second one (if exists), the website of the user.",
"elements",
"=",
"update_info",
".",
"select",
"(",
"\"div.user-info\"",
")",
"[",
"0",
"]",
".",
"find_all",
"(",
"\"a\"",
")",
"href",
"=",
"elements",
"[",
"0",
"]",
".",
"attrs",
"[",
"\"href\"",
"]",
"user_info",
"[",
"'id'",
"]",
"=",
"re",
".",
"search",
"(",
"r'\\d+'",
",",
"href",
")",
".",
"group",
"(",
"0",
")",
"user_info",
"[",
"'username'",
"]",
"=",
"elements",
"[",
"0",
"]",
".",
"text",
"user_info",
"[",
"'reputation'",
"]",
"=",
"update_info",
".",
"select",
"(",
"'span.reputation-score'",
")",
"[",
"0",
"]",
".",
"text",
"user_info",
"[",
"'badges'",
"]",
"=",
"update_info",
".",
"select",
"(",
"\"span.badges\"",
")",
"[",
"0",
"]",
".",
"attrs",
"[",
"\"title\"",
"]",
"try",
":",
"elements",
"[",
"1",
"]",
"except",
"IndexError",
":",
"pass",
"else",
":",
"user_info",
"[",
"'website'",
"]",
"=",
"elements",
"[",
"1",
"]",
".",
"attrs",
"[",
"\"href\"",
"]",
"if",
"update_info",
".",
"select",
"(",
"\"img.flag\"",
")",
":",
"flag",
"=",
"update_info",
".",
"select",
"(",
"\"img.flag\"",
")",
"[",
"0",
"]",
".",
"attrs",
"[",
"\"alt\"",
"]",
"user_info",
"[",
"'country'",
"]",
"=",
"re",
".",
"sub",
"(",
"\"flag of \"",
",",
"\"\"",
",",
"flag",
")",
"return",
"user_info"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
Gerrit.fetch_items
|
Fetch the reviews
:param category: the category of items to fetch
:param kwargs: backend arguments
:returns: a generator of items
|
perceval/backends/core/gerrit.py
|
def fetch_items(self, category, **kwargs):
"""Fetch the reviews
:param category: the category of items to fetch
:param kwargs: backend arguments
:returns: a generator of items
"""
from_date = kwargs['from_date']
if self.client.version[0] == 2 and self.client.version[1] == 8:
fetcher = self._fetch_gerrit28(from_date)
else:
fetcher = self._fetch_gerrit(from_date)
for review in fetcher:
yield review
|
def fetch_items(self, category, **kwargs):
"""Fetch the reviews
:param category: the category of items to fetch
:param kwargs: backend arguments
:returns: a generator of items
"""
from_date = kwargs['from_date']
if self.client.version[0] == 2 and self.client.version[1] == 8:
fetcher = self._fetch_gerrit28(from_date)
else:
fetcher = self._fetch_gerrit(from_date)
for review in fetcher:
yield review
|
[
"Fetch",
"the",
"reviews"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/gerrit.py#L102-L118
|
[
"def",
"fetch_items",
"(",
"self",
",",
"category",
",",
"*",
"*",
"kwargs",
")",
":",
"from_date",
"=",
"kwargs",
"[",
"'from_date'",
"]",
"if",
"self",
".",
"client",
".",
"version",
"[",
"0",
"]",
"==",
"2",
"and",
"self",
".",
"client",
".",
"version",
"[",
"1",
"]",
"==",
"8",
":",
"fetcher",
"=",
"self",
".",
"_fetch_gerrit28",
"(",
"from_date",
")",
"else",
":",
"fetcher",
"=",
"self",
".",
"_fetch_gerrit",
"(",
"from_date",
")",
"for",
"review",
"in",
"fetcher",
":",
"yield",
"review"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
Gerrit.parse_reviews
|
Parse a Gerrit reviews list.
|
perceval/backends/core/gerrit.py
|
def parse_reviews(raw_data):
"""Parse a Gerrit reviews list."""
# Join isolated reviews in JSON in array for parsing
items_raw = "[" + raw_data.replace("\n", ",") + "]"
items_raw = items_raw.replace(",]", "]")
items = json.loads(items_raw)
reviews = []
for item in items:
if 'project' in item.keys():
reviews.append(item)
return reviews
|
def parse_reviews(raw_data):
"""Parse a Gerrit reviews list."""
# Join isolated reviews in JSON in array for parsing
items_raw = "[" + raw_data.replace("\n", ",") + "]"
items_raw = items_raw.replace(",]", "]")
items = json.loads(items_raw)
reviews = []
for item in items:
if 'project' in item.keys():
reviews.append(item)
return reviews
|
[
"Parse",
"a",
"Gerrit",
"reviews",
"list",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/gerrit.py#L165-L178
|
[
"def",
"parse_reviews",
"(",
"raw_data",
")",
":",
"# Join isolated reviews in JSON in array for parsing",
"items_raw",
"=",
"\"[\"",
"+",
"raw_data",
".",
"replace",
"(",
"\"\\n\"",
",",
"\",\"",
")",
"+",
"\"]\"",
"items_raw",
"=",
"items_raw",
".",
"replace",
"(",
"\",]\"",
",",
"\"]\"",
")",
"items",
"=",
"json",
".",
"loads",
"(",
"items_raw",
")",
"reviews",
"=",
"[",
"]",
"for",
"item",
"in",
"items",
":",
"if",
"'project'",
"in",
"item",
".",
"keys",
"(",
")",
":",
"reviews",
".",
"append",
"(",
"item",
")",
"return",
"reviews"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
Gerrit._fetch_gerrit28
|
Specific fetch for gerrit 2.8 version.
Get open and closed reviews in different queries.
Take the newer review from both lists and iterate.
|
perceval/backends/core/gerrit.py
|
def _fetch_gerrit28(self, from_date=DEFAULT_DATETIME):
""" Specific fetch for gerrit 2.8 version.
Get open and closed reviews in different queries.
Take the newer review from both lists and iterate.
"""
# Convert date to Unix time
from_ut = datetime_to_utc(from_date)
from_ut = from_ut.timestamp()
filter_open = "status:open"
filter_closed = "status:closed"
last_item_open = self.client.next_retrieve_group_item()
last_item_closed = self.client.next_retrieve_group_item()
reviews_open = self._get_reviews(last_item_open, filter_open)
reviews_closed = self._get_reviews(last_item_closed, filter_closed)
last_nreviews_open = len(reviews_open)
last_nreviews_closed = len(reviews_closed)
while reviews_open or reviews_closed:
if reviews_open and reviews_closed:
if reviews_open[0]['lastUpdated'] >= reviews_closed[0]['lastUpdated']:
review_open = reviews_open.pop(0)
review = review_open
else:
review_closed = reviews_closed.pop(0)
review = review_closed
elif reviews_closed:
review_closed = reviews_closed.pop(0)
review = review_closed
else:
review_open = reviews_open.pop(0)
review = review_open
updated = review['lastUpdated']
if updated <= from_ut:
logger.debug("No more updates for %s" % (self.hostname))
break
else:
yield review
if not reviews_open and last_nreviews_open >= self.max_reviews:
last_item_open = self.client.next_retrieve_group_item(last_item_open, review_open)
reviews_open = self._get_reviews(last_item_open, filter_open)
last_nreviews_open = len(reviews_open)
if not reviews_closed and last_nreviews_closed >= self.max_reviews:
last_item_closed = self.client.next_retrieve_group_item(last_item_closed, review_closed)
reviews_closed = self._get_reviews(last_item_closed, filter_closed)
last_nreviews_closed = len(reviews_closed)
|
def _fetch_gerrit28(self, from_date=DEFAULT_DATETIME):
""" Specific fetch for gerrit 2.8 version.
Get open and closed reviews in different queries.
Take the newer review from both lists and iterate.
"""
# Convert date to Unix time
from_ut = datetime_to_utc(from_date)
from_ut = from_ut.timestamp()
filter_open = "status:open"
filter_closed = "status:closed"
last_item_open = self.client.next_retrieve_group_item()
last_item_closed = self.client.next_retrieve_group_item()
reviews_open = self._get_reviews(last_item_open, filter_open)
reviews_closed = self._get_reviews(last_item_closed, filter_closed)
last_nreviews_open = len(reviews_open)
last_nreviews_closed = len(reviews_closed)
while reviews_open or reviews_closed:
if reviews_open and reviews_closed:
if reviews_open[0]['lastUpdated'] >= reviews_closed[0]['lastUpdated']:
review_open = reviews_open.pop(0)
review = review_open
else:
review_closed = reviews_closed.pop(0)
review = review_closed
elif reviews_closed:
review_closed = reviews_closed.pop(0)
review = review_closed
else:
review_open = reviews_open.pop(0)
review = review_open
updated = review['lastUpdated']
if updated <= from_ut:
logger.debug("No more updates for %s" % (self.hostname))
break
else:
yield review
if not reviews_open and last_nreviews_open >= self.max_reviews:
last_item_open = self.client.next_retrieve_group_item(last_item_open, review_open)
reviews_open = self._get_reviews(last_item_open, filter_open)
last_nreviews_open = len(reviews_open)
if not reviews_closed and last_nreviews_closed >= self.max_reviews:
last_item_closed = self.client.next_retrieve_group_item(last_item_closed, review_closed)
reviews_closed = self._get_reviews(last_item_closed, filter_closed)
last_nreviews_closed = len(reviews_closed)
|
[
"Specific",
"fetch",
"for",
"gerrit",
"2",
".",
"8",
"version",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/gerrit.py#L186-L236
|
[
"def",
"_fetch_gerrit28",
"(",
"self",
",",
"from_date",
"=",
"DEFAULT_DATETIME",
")",
":",
"# Convert date to Unix time",
"from_ut",
"=",
"datetime_to_utc",
"(",
"from_date",
")",
"from_ut",
"=",
"from_ut",
".",
"timestamp",
"(",
")",
"filter_open",
"=",
"\"status:open\"",
"filter_closed",
"=",
"\"status:closed\"",
"last_item_open",
"=",
"self",
".",
"client",
".",
"next_retrieve_group_item",
"(",
")",
"last_item_closed",
"=",
"self",
".",
"client",
".",
"next_retrieve_group_item",
"(",
")",
"reviews_open",
"=",
"self",
".",
"_get_reviews",
"(",
"last_item_open",
",",
"filter_open",
")",
"reviews_closed",
"=",
"self",
".",
"_get_reviews",
"(",
"last_item_closed",
",",
"filter_closed",
")",
"last_nreviews_open",
"=",
"len",
"(",
"reviews_open",
")",
"last_nreviews_closed",
"=",
"len",
"(",
"reviews_closed",
")",
"while",
"reviews_open",
"or",
"reviews_closed",
":",
"if",
"reviews_open",
"and",
"reviews_closed",
":",
"if",
"reviews_open",
"[",
"0",
"]",
"[",
"'lastUpdated'",
"]",
">=",
"reviews_closed",
"[",
"0",
"]",
"[",
"'lastUpdated'",
"]",
":",
"review_open",
"=",
"reviews_open",
".",
"pop",
"(",
"0",
")",
"review",
"=",
"review_open",
"else",
":",
"review_closed",
"=",
"reviews_closed",
".",
"pop",
"(",
"0",
")",
"review",
"=",
"review_closed",
"elif",
"reviews_closed",
":",
"review_closed",
"=",
"reviews_closed",
".",
"pop",
"(",
"0",
")",
"review",
"=",
"review_closed",
"else",
":",
"review_open",
"=",
"reviews_open",
".",
"pop",
"(",
"0",
")",
"review",
"=",
"review_open",
"updated",
"=",
"review",
"[",
"'lastUpdated'",
"]",
"if",
"updated",
"<=",
"from_ut",
":",
"logger",
".",
"debug",
"(",
"\"No more updates for %s\"",
"%",
"(",
"self",
".",
"hostname",
")",
")",
"break",
"else",
":",
"yield",
"review",
"if",
"not",
"reviews_open",
"and",
"last_nreviews_open",
">=",
"self",
".",
"max_reviews",
":",
"last_item_open",
"=",
"self",
".",
"client",
".",
"next_retrieve_group_item",
"(",
"last_item_open",
",",
"review_open",
")",
"reviews_open",
"=",
"self",
".",
"_get_reviews",
"(",
"last_item_open",
",",
"filter_open",
")",
"last_nreviews_open",
"=",
"len",
"(",
"reviews_open",
")",
"if",
"not",
"reviews_closed",
"and",
"last_nreviews_closed",
">=",
"self",
".",
"max_reviews",
":",
"last_item_closed",
"=",
"self",
".",
"client",
".",
"next_retrieve_group_item",
"(",
"last_item_closed",
",",
"review_closed",
")",
"reviews_closed",
"=",
"self",
".",
"_get_reviews",
"(",
"last_item_closed",
",",
"filter_closed",
")",
"last_nreviews_closed",
"=",
"len",
"(",
"reviews_closed",
")"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
GerritClient.version
|
Return the Gerrit server version.
|
perceval/backends/core/gerrit.py
|
def version(self):
"""Return the Gerrit server version."""
if self._version:
return self._version
cmd = self.gerrit_cmd + " %s " % (GerritClient.CMD_VERSION)
logger.debug("Getting version: %s" % (cmd))
raw_data = self.__execute(cmd)
raw_data = str(raw_data, "UTF-8")
logger.debug("Gerrit version: %s" % (raw_data))
# output: gerrit version 2.10-rc1-988-g333a9dd
m = re.match(GerritClient.VERSION_REGEX, raw_data)
if not m:
cause = "Invalid gerrit version %s" % raw_data
raise BackendError(cause=cause)
try:
mayor = int(m.group(1))
minor = int(m.group(2))
except Exception:
cause = "Gerrit client could not determine the server version."
raise BackendError(cause=cause)
self._version = [mayor, minor]
return self._version
|
def version(self):
"""Return the Gerrit server version."""
if self._version:
return self._version
cmd = self.gerrit_cmd + " %s " % (GerritClient.CMD_VERSION)
logger.debug("Getting version: %s" % (cmd))
raw_data = self.__execute(cmd)
raw_data = str(raw_data, "UTF-8")
logger.debug("Gerrit version: %s" % (raw_data))
# output: gerrit version 2.10-rc1-988-g333a9dd
m = re.match(GerritClient.VERSION_REGEX, raw_data)
if not m:
cause = "Invalid gerrit version %s" % raw_data
raise BackendError(cause=cause)
try:
mayor = int(m.group(1))
minor = int(m.group(2))
except Exception:
cause = "Gerrit client could not determine the server version."
raise BackendError(cause=cause)
self._version = [mayor, minor]
return self._version
|
[
"Return",
"the",
"Gerrit",
"server",
"version",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/gerrit.py#L327-L355
|
[
"def",
"version",
"(",
"self",
")",
":",
"if",
"self",
".",
"_version",
":",
"return",
"self",
".",
"_version",
"cmd",
"=",
"self",
".",
"gerrit_cmd",
"+",
"\" %s \"",
"%",
"(",
"GerritClient",
".",
"CMD_VERSION",
")",
"logger",
".",
"debug",
"(",
"\"Getting version: %s\"",
"%",
"(",
"cmd",
")",
")",
"raw_data",
"=",
"self",
".",
"__execute",
"(",
"cmd",
")",
"raw_data",
"=",
"str",
"(",
"raw_data",
",",
"\"UTF-8\"",
")",
"logger",
".",
"debug",
"(",
"\"Gerrit version: %s\"",
"%",
"(",
"raw_data",
")",
")",
"# output: gerrit version 2.10-rc1-988-g333a9dd",
"m",
"=",
"re",
".",
"match",
"(",
"GerritClient",
".",
"VERSION_REGEX",
",",
"raw_data",
")",
"if",
"not",
"m",
":",
"cause",
"=",
"\"Invalid gerrit version %s\"",
"%",
"raw_data",
"raise",
"BackendError",
"(",
"cause",
"=",
"cause",
")",
"try",
":",
"mayor",
"=",
"int",
"(",
"m",
".",
"group",
"(",
"1",
")",
")",
"minor",
"=",
"int",
"(",
"m",
".",
"group",
"(",
"2",
")",
")",
"except",
"Exception",
":",
"cause",
"=",
"\"Gerrit client could not determine the server version.\"",
"raise",
"BackendError",
"(",
"cause",
"=",
"cause",
")",
"self",
".",
"_version",
"=",
"[",
"mayor",
",",
"minor",
"]",
"return",
"self",
".",
"_version"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
GerritClient.reviews
|
Get the reviews starting from last_item.
|
perceval/backends/core/gerrit.py
|
def reviews(self, last_item, filter_=None):
"""Get the reviews starting from last_item."""
cmd = self._get_gerrit_cmd(last_item, filter_)
logger.debug("Getting reviews with command: %s", cmd)
raw_data = self.__execute(cmd)
raw_data = str(raw_data, "UTF-8")
return raw_data
|
def reviews(self, last_item, filter_=None):
"""Get the reviews starting from last_item."""
cmd = self._get_gerrit_cmd(last_item, filter_)
logger.debug("Getting reviews with command: %s", cmd)
raw_data = self.__execute(cmd)
raw_data = str(raw_data, "UTF-8")
return raw_data
|
[
"Get",
"the",
"reviews",
"starting",
"from",
"last_item",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/gerrit.py#L357-L366
|
[
"def",
"reviews",
"(",
"self",
",",
"last_item",
",",
"filter_",
"=",
"None",
")",
":",
"cmd",
"=",
"self",
".",
"_get_gerrit_cmd",
"(",
"last_item",
",",
"filter_",
")",
"logger",
".",
"debug",
"(",
"\"Getting reviews with command: %s\"",
",",
"cmd",
")",
"raw_data",
"=",
"self",
".",
"__execute",
"(",
"cmd",
")",
"raw_data",
"=",
"str",
"(",
"raw_data",
",",
"\"UTF-8\"",
")",
"return",
"raw_data"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
GerritClient.next_retrieve_group_item
|
Return the item to start from in next reviews group.
|
perceval/backends/core/gerrit.py
|
def next_retrieve_group_item(self, last_item=None, entry=None):
"""Return the item to start from in next reviews group."""
next_item = None
gerrit_version = self.version
if gerrit_version[0] == 2 and gerrit_version[1] > 9:
if last_item is None:
next_item = 0
else:
next_item = last_item
elif gerrit_version[0] == 2 and gerrit_version[1] == 9:
# https://groups.google.com/forum/#!topic/repo-discuss/yQgRR5hlS3E
cause = "Gerrit 2.9.0 does not support pagination"
raise BackendError(cause=cause)
else:
if entry is not None:
next_item = entry['sortKey']
return next_item
|
def next_retrieve_group_item(self, last_item=None, entry=None):
"""Return the item to start from in next reviews group."""
next_item = None
gerrit_version = self.version
if gerrit_version[0] == 2 and gerrit_version[1] > 9:
if last_item is None:
next_item = 0
else:
next_item = last_item
elif gerrit_version[0] == 2 and gerrit_version[1] == 9:
# https://groups.google.com/forum/#!topic/repo-discuss/yQgRR5hlS3E
cause = "Gerrit 2.9.0 does not support pagination"
raise BackendError(cause=cause)
else:
if entry is not None:
next_item = entry['sortKey']
return next_item
|
[
"Return",
"the",
"item",
"to",
"start",
"from",
"in",
"next",
"reviews",
"group",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/gerrit.py#L368-L388
|
[
"def",
"next_retrieve_group_item",
"(",
"self",
",",
"last_item",
"=",
"None",
",",
"entry",
"=",
"None",
")",
":",
"next_item",
"=",
"None",
"gerrit_version",
"=",
"self",
".",
"version",
"if",
"gerrit_version",
"[",
"0",
"]",
"==",
"2",
"and",
"gerrit_version",
"[",
"1",
"]",
">",
"9",
":",
"if",
"last_item",
"is",
"None",
":",
"next_item",
"=",
"0",
"else",
":",
"next_item",
"=",
"last_item",
"elif",
"gerrit_version",
"[",
"0",
"]",
"==",
"2",
"and",
"gerrit_version",
"[",
"1",
"]",
"==",
"9",
":",
"# https://groups.google.com/forum/#!topic/repo-discuss/yQgRR5hlS3E",
"cause",
"=",
"\"Gerrit 2.9.0 does not support pagination\"",
"raise",
"BackendError",
"(",
"cause",
"=",
"cause",
")",
"else",
":",
"if",
"entry",
"is",
"not",
"None",
":",
"next_item",
"=",
"entry",
"[",
"'sortKey'",
"]",
"return",
"next_item"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
GerritClient.__execute
|
Execute gerrit command
|
perceval/backends/core/gerrit.py
|
def __execute(self, cmd):
"""Execute gerrit command"""
if self.from_archive:
response = self.__execute_from_archive(cmd)
else:
response = self.__execute_from_remote(cmd)
return response
|
def __execute(self, cmd):
"""Execute gerrit command"""
if self.from_archive:
response = self.__execute_from_archive(cmd)
else:
response = self.__execute_from_remote(cmd)
return response
|
[
"Execute",
"gerrit",
"command"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/gerrit.py#L403-L411
|
[
"def",
"__execute",
"(",
"self",
",",
"cmd",
")",
":",
"if",
"self",
".",
"from_archive",
":",
"response",
"=",
"self",
".",
"__execute_from_archive",
"(",
"cmd",
")",
"else",
":",
"response",
"=",
"self",
".",
"__execute_from_remote",
"(",
"cmd",
")",
"return",
"response"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
GerritClient.__execute_from_archive
|
Execute gerrit command against the archive
|
perceval/backends/core/gerrit.py
|
def __execute_from_archive(self, cmd):
"""Execute gerrit command against the archive"""
cmd = self.sanitize_for_archive(cmd)
response = self.archive.retrieve(cmd, None, None)
if isinstance(response, RuntimeError):
raise response
return response
|
def __execute_from_archive(self, cmd):
"""Execute gerrit command against the archive"""
cmd = self.sanitize_for_archive(cmd)
response = self.archive.retrieve(cmd, None, None)
if isinstance(response, RuntimeError):
raise response
return response
|
[
"Execute",
"gerrit",
"command",
"against",
"the",
"archive"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/gerrit.py#L413-L422
|
[
"def",
"__execute_from_archive",
"(",
"self",
",",
"cmd",
")",
":",
"cmd",
"=",
"self",
".",
"sanitize_for_archive",
"(",
"cmd",
")",
"response",
"=",
"self",
".",
"archive",
".",
"retrieve",
"(",
"cmd",
",",
"None",
",",
"None",
")",
"if",
"isinstance",
"(",
"response",
",",
"RuntimeError",
")",
":",
"raise",
"response",
"return",
"response"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
GerritClient.__execute_from_remote
|
Execute gerrit command with retry if it fails
|
perceval/backends/core/gerrit.py
|
def __execute_from_remote(self, cmd):
"""Execute gerrit command with retry if it fails"""
result = None # data result from the cmd execution
retries = 0
while retries < self.MAX_RETRIES:
try:
result = subprocess.check_output(cmd, shell=True)
break
except subprocess.CalledProcessError as ex:
logger.error("gerrit cmd %s failed: %s", cmd, ex)
time.sleep(self.RETRY_WAIT * retries)
retries += 1
if result is None:
result = RuntimeError(cmd + " failed " + str(self.MAX_RETRIES) + " times. Giving up!")
if self.archive:
cmd = self.sanitize_for_archive(cmd)
self.archive.store(cmd, None, None, result)
if isinstance(result, RuntimeError):
raise result
return result
|
def __execute_from_remote(self, cmd):
"""Execute gerrit command with retry if it fails"""
result = None # data result from the cmd execution
retries = 0
while retries < self.MAX_RETRIES:
try:
result = subprocess.check_output(cmd, shell=True)
break
except subprocess.CalledProcessError as ex:
logger.error("gerrit cmd %s failed: %s", cmd, ex)
time.sleep(self.RETRY_WAIT * retries)
retries += 1
if result is None:
result = RuntimeError(cmd + " failed " + str(self.MAX_RETRIES) + " times. Giving up!")
if self.archive:
cmd = self.sanitize_for_archive(cmd)
self.archive.store(cmd, None, None, result)
if isinstance(result, RuntimeError):
raise result
return result
|
[
"Execute",
"gerrit",
"command",
"with",
"retry",
"if",
"it",
"fails"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/gerrit.py#L424-L449
|
[
"def",
"__execute_from_remote",
"(",
"self",
",",
"cmd",
")",
":",
"result",
"=",
"None",
"# data result from the cmd execution",
"retries",
"=",
"0",
"while",
"retries",
"<",
"self",
".",
"MAX_RETRIES",
":",
"try",
":",
"result",
"=",
"subprocess",
".",
"check_output",
"(",
"cmd",
",",
"shell",
"=",
"True",
")",
"break",
"except",
"subprocess",
".",
"CalledProcessError",
"as",
"ex",
":",
"logger",
".",
"error",
"(",
"\"gerrit cmd %s failed: %s\"",
",",
"cmd",
",",
"ex",
")",
"time",
".",
"sleep",
"(",
"self",
".",
"RETRY_WAIT",
"*",
"retries",
")",
"retries",
"+=",
"1",
"if",
"result",
"is",
"None",
":",
"result",
"=",
"RuntimeError",
"(",
"cmd",
"+",
"\" failed \"",
"+",
"str",
"(",
"self",
".",
"MAX_RETRIES",
")",
"+",
"\" times. Giving up!\"",
")",
"if",
"self",
".",
"archive",
":",
"cmd",
"=",
"self",
".",
"sanitize_for_archive",
"(",
"cmd",
")",
"self",
".",
"archive",
".",
"store",
"(",
"cmd",
",",
"None",
",",
"None",
",",
"result",
")",
"if",
"isinstance",
"(",
"result",
",",
"RuntimeError",
")",
":",
"raise",
"result",
"return",
"result"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
GerritCommand.setup_cmd_parser
|
Returns the Gerrit argument parser.
|
perceval/backends/core/gerrit.py
|
def setup_cmd_parser(cls):
"""Returns the Gerrit argument parser."""
parser = BackendCommandArgumentParser(cls.BACKEND.CATEGORIES,
from_date=True,
archive=True)
# Gerrit options
group = parser.parser.add_argument_group('Gerrit arguments')
group.add_argument('--user', dest='user',
help="Gerrit ssh user")
group.add_argument('--max-reviews', dest='max_reviews',
type=int, default=MAX_REVIEWS,
help="Max number of reviews per ssh query.")
group.add_argument('--blacklist-reviews', dest='blacklist_reviews',
nargs='*',
help="Wrong reviews that must not be retrieved.")
group.add_argument('--disable-host-key-check', dest='disable_host_key_check', action='store_true',
help="Don't check remote host identity")
group.add_argument('--ssh-port', dest='port',
default=PORT, type=int,
help="Set SSH port of the Gerrit server")
# Required arguments
parser.parser.add_argument('hostname',
help="Hostname of the Gerrit server")
return parser
|
def setup_cmd_parser(cls):
"""Returns the Gerrit argument parser."""
parser = BackendCommandArgumentParser(cls.BACKEND.CATEGORIES,
from_date=True,
archive=True)
# Gerrit options
group = parser.parser.add_argument_group('Gerrit arguments')
group.add_argument('--user', dest='user',
help="Gerrit ssh user")
group.add_argument('--max-reviews', dest='max_reviews',
type=int, default=MAX_REVIEWS,
help="Max number of reviews per ssh query.")
group.add_argument('--blacklist-reviews', dest='blacklist_reviews',
nargs='*',
help="Wrong reviews that must not be retrieved.")
group.add_argument('--disable-host-key-check', dest='disable_host_key_check', action='store_true',
help="Don't check remote host identity")
group.add_argument('--ssh-port', dest='port',
default=PORT, type=int,
help="Set SSH port of the Gerrit server")
# Required arguments
parser.parser.add_argument('hostname',
help="Hostname of the Gerrit server")
return parser
|
[
"Returns",
"the",
"Gerrit",
"argument",
"parser",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/gerrit.py#L495-L522
|
[
"def",
"setup_cmd_parser",
"(",
"cls",
")",
":",
"parser",
"=",
"BackendCommandArgumentParser",
"(",
"cls",
".",
"BACKEND",
".",
"CATEGORIES",
",",
"from_date",
"=",
"True",
",",
"archive",
"=",
"True",
")",
"# Gerrit options",
"group",
"=",
"parser",
".",
"parser",
".",
"add_argument_group",
"(",
"'Gerrit arguments'",
")",
"group",
".",
"add_argument",
"(",
"'--user'",
",",
"dest",
"=",
"'user'",
",",
"help",
"=",
"\"Gerrit ssh user\"",
")",
"group",
".",
"add_argument",
"(",
"'--max-reviews'",
",",
"dest",
"=",
"'max_reviews'",
",",
"type",
"=",
"int",
",",
"default",
"=",
"MAX_REVIEWS",
",",
"help",
"=",
"\"Max number of reviews per ssh query.\"",
")",
"group",
".",
"add_argument",
"(",
"'--blacklist-reviews'",
",",
"dest",
"=",
"'blacklist_reviews'",
",",
"nargs",
"=",
"'*'",
",",
"help",
"=",
"\"Wrong reviews that must not be retrieved.\"",
")",
"group",
".",
"add_argument",
"(",
"'--disable-host-key-check'",
",",
"dest",
"=",
"'disable_host_key_check'",
",",
"action",
"=",
"'store_true'",
",",
"help",
"=",
"\"Don't check remote host identity\"",
")",
"group",
".",
"add_argument",
"(",
"'--ssh-port'",
",",
"dest",
"=",
"'port'",
",",
"default",
"=",
"PORT",
",",
"type",
"=",
"int",
",",
"help",
"=",
"\"Set SSH port of the Gerrit server\"",
")",
"# Required arguments",
"parser",
".",
"parser",
".",
"add_argument",
"(",
"'hostname'",
",",
"help",
"=",
"\"Hostname of the Gerrit server\"",
")",
"return",
"parser"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
Launchpad.fetch_items
|
Fetch the issues
:param category: the category of items to fetch
:param kwargs: backend arguments
:returns: a generator of items
|
perceval/backends/core/launchpad.py
|
def fetch_items(self, category, **kwargs):
"""Fetch the issues
:param category: the category of items to fetch
:param kwargs: backend arguments
:returns: a generator of items
"""
from_date = kwargs['from_date']
logger.info("Fetching issues of '%s' distribution from %s",
self.distribution, str(from_date))
nissues = 0
for issue in self._fetch_issues(from_date):
yield issue
nissues += 1
logger.info("Fetch process completed: %s issues fetched", nissues)
|
def fetch_items(self, category, **kwargs):
"""Fetch the issues
:param category: the category of items to fetch
:param kwargs: backend arguments
:returns: a generator of items
"""
from_date = kwargs['from_date']
logger.info("Fetching issues of '%s' distribution from %s",
self.distribution, str(from_date))
nissues = 0
for issue in self._fetch_issues(from_date):
yield issue
nissues += 1
logger.info("Fetch process completed: %s issues fetched", nissues)
|
[
"Fetch",
"the",
"issues"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/launchpad.py#L102-L121
|
[
"def",
"fetch_items",
"(",
"self",
",",
"category",
",",
"*",
"*",
"kwargs",
")",
":",
"from_date",
"=",
"kwargs",
"[",
"'from_date'",
"]",
"logger",
".",
"info",
"(",
"\"Fetching issues of '%s' distribution from %s\"",
",",
"self",
".",
"distribution",
",",
"str",
"(",
"from_date",
")",
")",
"nissues",
"=",
"0",
"for",
"issue",
"in",
"self",
".",
"_fetch_issues",
"(",
"from_date",
")",
":",
"yield",
"issue",
"nissues",
"+=",
"1",
"logger",
".",
"info",
"(",
"\"Fetch process completed: %s issues fetched\"",
",",
"nissues",
")"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
Launchpad._init_client
|
Init client
|
perceval/backends/core/launchpad.py
|
def _init_client(self, from_archive=False):
"""Init client"""
return LaunchpadClient(self.distribution, self.package, self.items_per_page,
self.sleep_time, self.archive, from_archive)
|
def _init_client(self, from_archive=False):
"""Init client"""
return LaunchpadClient(self.distribution, self.package, self.items_per_page,
self.sleep_time, self.archive, from_archive)
|
[
"Init",
"client"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/launchpad.py#L172-L176
|
[
"def",
"_init_client",
"(",
"self",
",",
"from_archive",
"=",
"False",
")",
":",
"return",
"LaunchpadClient",
"(",
"self",
".",
"distribution",
",",
"self",
".",
"package",
",",
"self",
".",
"items_per_page",
",",
"self",
".",
"sleep_time",
",",
"self",
".",
"archive",
",",
"from_archive",
")"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
Launchpad._fetch_issues
|
Fetch the issues from a project (distribution/package)
|
perceval/backends/core/launchpad.py
|
def _fetch_issues(self, from_date):
"""Fetch the issues from a project (distribution/package)"""
issues_groups = self.client.issues(start=from_date)
for raw_issues in issues_groups:
issues = json.loads(raw_issues)['entries']
for issue in issues:
issue = self.__init_extra_issue_fields(issue)
issue_id = self.__extract_issue_id(issue['bug_link'])
for field in TARGET_ISSUE_FIELDS:
if not issue[field]:
continue
if field == 'bug_link':
issue['bug_data'] = self.__fetch_issue_data(issue_id)
issue['activity_data'] = [activity for activity in self.__fetch_issue_activities(issue_id)]
issue['messages_data'] = [message for message in self.__fetch_issue_messages(issue_id)]
issue['attachments_data'] = [attachment for attachment in self.__fetch_issue_attachments(issue_id)]
elif field == 'assignee_link':
issue['assignee_data'] = self.__fetch_user_data('{ASSIGNEE}', issue[field])
elif field == 'owner_link':
issue['owner_data'] = self.__fetch_user_data('{OWNER}', issue[field])
yield issue
|
def _fetch_issues(self, from_date):
"""Fetch the issues from a project (distribution/package)"""
issues_groups = self.client.issues(start=from_date)
for raw_issues in issues_groups:
issues = json.loads(raw_issues)['entries']
for issue in issues:
issue = self.__init_extra_issue_fields(issue)
issue_id = self.__extract_issue_id(issue['bug_link'])
for field in TARGET_ISSUE_FIELDS:
if not issue[field]:
continue
if field == 'bug_link':
issue['bug_data'] = self.__fetch_issue_data(issue_id)
issue['activity_data'] = [activity for activity in self.__fetch_issue_activities(issue_id)]
issue['messages_data'] = [message for message in self.__fetch_issue_messages(issue_id)]
issue['attachments_data'] = [attachment for attachment in self.__fetch_issue_attachments(issue_id)]
elif field == 'assignee_link':
issue['assignee_data'] = self.__fetch_user_data('{ASSIGNEE}', issue[field])
elif field == 'owner_link':
issue['owner_data'] = self.__fetch_user_data('{OWNER}', issue[field])
yield issue
|
[
"Fetch",
"the",
"issues",
"from",
"a",
"project",
"(",
"distribution",
"/",
"package",
")"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/launchpad.py#L192-L219
|
[
"def",
"_fetch_issues",
"(",
"self",
",",
"from_date",
")",
":",
"issues_groups",
"=",
"self",
".",
"client",
".",
"issues",
"(",
"start",
"=",
"from_date",
")",
"for",
"raw_issues",
"in",
"issues_groups",
":",
"issues",
"=",
"json",
".",
"loads",
"(",
"raw_issues",
")",
"[",
"'entries'",
"]",
"for",
"issue",
"in",
"issues",
":",
"issue",
"=",
"self",
".",
"__init_extra_issue_fields",
"(",
"issue",
")",
"issue_id",
"=",
"self",
".",
"__extract_issue_id",
"(",
"issue",
"[",
"'bug_link'",
"]",
")",
"for",
"field",
"in",
"TARGET_ISSUE_FIELDS",
":",
"if",
"not",
"issue",
"[",
"field",
"]",
":",
"continue",
"if",
"field",
"==",
"'bug_link'",
":",
"issue",
"[",
"'bug_data'",
"]",
"=",
"self",
".",
"__fetch_issue_data",
"(",
"issue_id",
")",
"issue",
"[",
"'activity_data'",
"]",
"=",
"[",
"activity",
"for",
"activity",
"in",
"self",
".",
"__fetch_issue_activities",
"(",
"issue_id",
")",
"]",
"issue",
"[",
"'messages_data'",
"]",
"=",
"[",
"message",
"for",
"message",
"in",
"self",
".",
"__fetch_issue_messages",
"(",
"issue_id",
")",
"]",
"issue",
"[",
"'attachments_data'",
"]",
"=",
"[",
"attachment",
"for",
"attachment",
"in",
"self",
".",
"__fetch_issue_attachments",
"(",
"issue_id",
")",
"]",
"elif",
"field",
"==",
"'assignee_link'",
":",
"issue",
"[",
"'assignee_data'",
"]",
"=",
"self",
".",
"__fetch_user_data",
"(",
"'{ASSIGNEE}'",
",",
"issue",
"[",
"field",
"]",
")",
"elif",
"field",
"==",
"'owner_link'",
":",
"issue",
"[",
"'owner_data'",
"]",
"=",
"self",
".",
"__fetch_user_data",
"(",
"'{OWNER}'",
",",
"issue",
"[",
"field",
"]",
")",
"yield",
"issue"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
Launchpad.__fetch_issue_data
|
Get data associated to an issue
|
perceval/backends/core/launchpad.py
|
def __fetch_issue_data(self, issue_id):
"""Get data associated to an issue"""
raw_issue = self.client.issue(issue_id)
issue = json.loads(raw_issue)
return issue
|
def __fetch_issue_data(self, issue_id):
"""Get data associated to an issue"""
raw_issue = self.client.issue(issue_id)
issue = json.loads(raw_issue)
return issue
|
[
"Get",
"data",
"associated",
"to",
"an",
"issue"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/launchpad.py#L221-L227
|
[
"def",
"__fetch_issue_data",
"(",
"self",
",",
"issue_id",
")",
":",
"raw_issue",
"=",
"self",
".",
"client",
".",
"issue",
"(",
"issue_id",
")",
"issue",
"=",
"json",
".",
"loads",
"(",
"raw_issue",
")",
"return",
"issue"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
Launchpad.__fetch_issue_attachments
|
Get attachments of an issue
|
perceval/backends/core/launchpad.py
|
def __fetch_issue_attachments(self, issue_id):
"""Get attachments of an issue"""
for attachments_raw in self.client.issue_collection(issue_id, "attachments"):
attachments = json.loads(attachments_raw)
for attachment in attachments['entries']:
yield attachment
|
def __fetch_issue_attachments(self, issue_id):
"""Get attachments of an issue"""
for attachments_raw in self.client.issue_collection(issue_id, "attachments"):
attachments = json.loads(attachments_raw)
for attachment in attachments['entries']:
yield attachment
|
[
"Get",
"attachments",
"of",
"an",
"issue"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/launchpad.py#L229-L236
|
[
"def",
"__fetch_issue_attachments",
"(",
"self",
",",
"issue_id",
")",
":",
"for",
"attachments_raw",
"in",
"self",
".",
"client",
".",
"issue_collection",
"(",
"issue_id",
",",
"\"attachments\"",
")",
":",
"attachments",
"=",
"json",
".",
"loads",
"(",
"attachments_raw",
")",
"for",
"attachment",
"in",
"attachments",
"[",
"'entries'",
"]",
":",
"yield",
"attachment"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
Launchpad.__fetch_issue_messages
|
Get messages of an issue
|
perceval/backends/core/launchpad.py
|
def __fetch_issue_messages(self, issue_id):
"""Get messages of an issue"""
for messages_raw in self.client.issue_collection(issue_id, "messages"):
messages = json.loads(messages_raw)
for msg in messages['entries']:
msg['owner_data'] = self.__fetch_user_data('{OWNER}', msg['owner_link'])
yield msg
|
def __fetch_issue_messages(self, issue_id):
"""Get messages of an issue"""
for messages_raw in self.client.issue_collection(issue_id, "messages"):
messages = json.loads(messages_raw)
for msg in messages['entries']:
msg['owner_data'] = self.__fetch_user_data('{OWNER}', msg['owner_link'])
yield msg
|
[
"Get",
"messages",
"of",
"an",
"issue"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/launchpad.py#L238-L246
|
[
"def",
"__fetch_issue_messages",
"(",
"self",
",",
"issue_id",
")",
":",
"for",
"messages_raw",
"in",
"self",
".",
"client",
".",
"issue_collection",
"(",
"issue_id",
",",
"\"messages\"",
")",
":",
"messages",
"=",
"json",
".",
"loads",
"(",
"messages_raw",
")",
"for",
"msg",
"in",
"messages",
"[",
"'entries'",
"]",
":",
"msg",
"[",
"'owner_data'",
"]",
"=",
"self",
".",
"__fetch_user_data",
"(",
"'{OWNER}'",
",",
"msg",
"[",
"'owner_link'",
"]",
")",
"yield",
"msg"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
Launchpad.__fetch_issue_activities
|
Get activities on an issue
|
perceval/backends/core/launchpad.py
|
def __fetch_issue_activities(self, issue_id):
"""Get activities on an issue"""
for activities_raw in self.client.issue_collection(issue_id, "activity"):
activities = json.loads(activities_raw)
for act in activities['entries']:
act['person_data'] = self.__fetch_user_data('{PERSON}', act['person_link'])
yield act
|
def __fetch_issue_activities(self, issue_id):
"""Get activities on an issue"""
for activities_raw in self.client.issue_collection(issue_id, "activity"):
activities = json.loads(activities_raw)
for act in activities['entries']:
act['person_data'] = self.__fetch_user_data('{PERSON}', act['person_link'])
yield act
|
[
"Get",
"activities",
"on",
"an",
"issue"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/launchpad.py#L248-L256
|
[
"def",
"__fetch_issue_activities",
"(",
"self",
",",
"issue_id",
")",
":",
"for",
"activities_raw",
"in",
"self",
".",
"client",
".",
"issue_collection",
"(",
"issue_id",
",",
"\"activity\"",
")",
":",
"activities",
"=",
"json",
".",
"loads",
"(",
"activities_raw",
")",
"for",
"act",
"in",
"activities",
"[",
"'entries'",
"]",
":",
"act",
"[",
"'person_data'",
"]",
"=",
"self",
".",
"__fetch_user_data",
"(",
"'{PERSON}'",
",",
"act",
"[",
"'person_link'",
"]",
")",
"yield",
"act"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
Launchpad.__fetch_user_data
|
Get data associated to an user
|
perceval/backends/core/launchpad.py
|
def __fetch_user_data(self, tag_type, user_link):
"""Get data associated to an user"""
user_name = self.client.user_name(user_link)
user = {}
if not user_name:
return user
user_raw = self.client.user(user_name)
user = json.loads(user_raw)
return user
|
def __fetch_user_data(self, tag_type, user_link):
"""Get data associated to an user"""
user_name = self.client.user_name(user_link)
user = {}
if not user_name:
return user
user_raw = self.client.user(user_name)
user = json.loads(user_raw)
return user
|
[
"Get",
"data",
"associated",
"to",
"an",
"user"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/launchpad.py#L258-L271
|
[
"def",
"__fetch_user_data",
"(",
"self",
",",
"tag_type",
",",
"user_link",
")",
":",
"user_name",
"=",
"self",
".",
"client",
".",
"user_name",
"(",
"user_link",
")",
"user",
"=",
"{",
"}",
"if",
"not",
"user_name",
":",
"return",
"user",
"user_raw",
"=",
"self",
".",
"client",
".",
"user",
"(",
"user_name",
")",
"user",
"=",
"json",
".",
"loads",
"(",
"user_raw",
")",
"return",
"user"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
LaunchpadClient.issues
|
Get the issues from pagination
|
perceval/backends/core/launchpad.py
|
def issues(self, start=None):
"""Get the issues from pagination"""
payload = self.__build_payload(size=self.items_per_page, operation=True, startdate=start)
path = self.__get_url_project()
return self.__fetch_items(path=path, payload=payload)
|
def issues(self, start=None):
"""Get the issues from pagination"""
payload = self.__build_payload(size=self.items_per_page, operation=True, startdate=start)
path = self.__get_url_project()
return self.__fetch_items(path=path, payload=payload)
|
[
"Get",
"the",
"issues",
"from",
"pagination"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/launchpad.py#L300-L305
|
[
"def",
"issues",
"(",
"self",
",",
"start",
"=",
"None",
")",
":",
"payload",
"=",
"self",
".",
"__build_payload",
"(",
"size",
"=",
"self",
".",
"items_per_page",
",",
"operation",
"=",
"True",
",",
"startdate",
"=",
"start",
")",
"path",
"=",
"self",
".",
"__get_url_project",
"(",
")",
"return",
"self",
".",
"__fetch_items",
"(",
"path",
"=",
"path",
",",
"payload",
"=",
"payload",
")"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
LaunchpadClient.user
|
Get the user data by URL
|
perceval/backends/core/launchpad.py
|
def user(self, user_name):
"""Get the user data by URL"""
user = None
if user_name in self._users:
return self._users[user_name]
url_user = self.__get_url("~" + user_name)
logger.info("Getting info for %s" % (url_user))
try:
raw_user = self.__send_request(url_user)
user = raw_user
except requests.exceptions.HTTPError as e:
if e.response.status_code in [404, 410]:
logger.warning("Data is not available - %s", url_user)
user = '{}'
else:
raise e
self._users[user_name] = user
return user
|
def user(self, user_name):
"""Get the user data by URL"""
user = None
if user_name in self._users:
return self._users[user_name]
url_user = self.__get_url("~" + user_name)
logger.info("Getting info for %s" % (url_user))
try:
raw_user = self.__send_request(url_user)
user = raw_user
except requests.exceptions.HTTPError as e:
if e.response.status_code in [404, 410]:
logger.warning("Data is not available - %s", url_user)
user = '{}'
else:
raise e
self._users[user_name] = user
return user
|
[
"Get",
"the",
"user",
"data",
"by",
"URL"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/launchpad.py#L307-L331
|
[
"def",
"user",
"(",
"self",
",",
"user_name",
")",
":",
"user",
"=",
"None",
"if",
"user_name",
"in",
"self",
".",
"_users",
":",
"return",
"self",
".",
"_users",
"[",
"user_name",
"]",
"url_user",
"=",
"self",
".",
"__get_url",
"(",
"\"~\"",
"+",
"user_name",
")",
"logger",
".",
"info",
"(",
"\"Getting info for %s\"",
"%",
"(",
"url_user",
")",
")",
"try",
":",
"raw_user",
"=",
"self",
".",
"__send_request",
"(",
"url_user",
")",
"user",
"=",
"raw_user",
"except",
"requests",
".",
"exceptions",
".",
"HTTPError",
"as",
"e",
":",
"if",
"e",
".",
"response",
".",
"status_code",
"in",
"[",
"404",
",",
"410",
"]",
":",
"logger",
".",
"warning",
"(",
"\"Data is not available - %s\"",
",",
"url_user",
")",
"user",
"=",
"'{}'",
"else",
":",
"raise",
"e",
"self",
".",
"_users",
"[",
"user_name",
"]",
"=",
"user",
"return",
"user"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
LaunchpadClient.issue
|
Get the issue data by its ID
|
perceval/backends/core/launchpad.py
|
def issue(self, issue_id):
"""Get the issue data by its ID"""
path = urijoin("bugs", str(issue_id))
url_issue = self.__get_url(path)
raw_text = self.__send_request(url_issue)
return raw_text
|
def issue(self, issue_id):
"""Get the issue data by its ID"""
path = urijoin("bugs", str(issue_id))
url_issue = self.__get_url(path)
raw_text = self.__send_request(url_issue)
return raw_text
|
[
"Get",
"the",
"issue",
"data",
"by",
"its",
"ID"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/launchpad.py#L338-L345
|
[
"def",
"issue",
"(",
"self",
",",
"issue_id",
")",
":",
"path",
"=",
"urijoin",
"(",
"\"bugs\"",
",",
"str",
"(",
"issue_id",
")",
")",
"url_issue",
"=",
"self",
".",
"__get_url",
"(",
"path",
")",
"raw_text",
"=",
"self",
".",
"__send_request",
"(",
"url_issue",
")",
"return",
"raw_text"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
LaunchpadClient.issue_collection
|
Get a collection list of a given issue
|
perceval/backends/core/launchpad.py
|
def issue_collection(self, issue_id, collection_name):
"""Get a collection list of a given issue"""
path = urijoin("bugs", str(issue_id), collection_name)
url_collection = self.__get_url(path)
payload = {'ws.size': self.items_per_page, 'ws.start': 0, 'order_by': 'date_last_updated'}
raw_items = self.__fetch_items(path=url_collection, payload=payload)
return raw_items
|
def issue_collection(self, issue_id, collection_name):
"""Get a collection list of a given issue"""
path = urijoin("bugs", str(issue_id), collection_name)
url_collection = self.__get_url(path)
payload = {'ws.size': self.items_per_page, 'ws.start': 0, 'order_by': 'date_last_updated'}
raw_items = self.__fetch_items(path=url_collection, payload=payload)
return raw_items
|
[
"Get",
"a",
"collection",
"list",
"of",
"a",
"given",
"issue"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/launchpad.py#L347-L356
|
[
"def",
"issue_collection",
"(",
"self",
",",
"issue_id",
",",
"collection_name",
")",
":",
"path",
"=",
"urijoin",
"(",
"\"bugs\"",
",",
"str",
"(",
"issue_id",
")",
",",
"collection_name",
")",
"url_collection",
"=",
"self",
".",
"__get_url",
"(",
"path",
")",
"payload",
"=",
"{",
"'ws.size'",
":",
"self",
".",
"items_per_page",
",",
"'ws.start'",
":",
"0",
",",
"'order_by'",
":",
"'date_last_updated'",
"}",
"raw_items",
"=",
"self",
".",
"__fetch_items",
"(",
"path",
"=",
"url_collection",
",",
"payload",
"=",
"payload",
")",
"return",
"raw_items"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
LaunchpadClient.__get_url_project
|
Build URL project
|
perceval/backends/core/launchpad.py
|
def __get_url_project(self):
"""Build URL project"""
if self.package:
url = self.__get_url_distribution_package()
else:
url = self.__get_url_distribution()
return url
|
def __get_url_project(self):
"""Build URL project"""
if self.package:
url = self.__get_url_distribution_package()
else:
url = self.__get_url_distribution()
return url
|
[
"Build",
"URL",
"project"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/launchpad.py#L358-L366
|
[
"def",
"__get_url_project",
"(",
"self",
")",
":",
"if",
"self",
".",
"package",
":",
"url",
"=",
"self",
".",
"__get_url_distribution_package",
"(",
")",
"else",
":",
"url",
"=",
"self",
".",
"__get_url_distribution",
"(",
")",
"return",
"url"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
LaunchpadClient.__send_request
|
Send request
|
perceval/backends/core/launchpad.py
|
def __send_request(self, url, params=None):
"""Send request"""
r = self.fetch(url, payload=params)
return r.text
|
def __send_request(self, url, params=None):
"""Send request"""
r = self.fetch(url, payload=params)
return r.text
|
[
"Send",
"request"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/launchpad.py#L390-L394
|
[
"def",
"__send_request",
"(",
"self",
",",
"url",
",",
"params",
"=",
"None",
")",
":",
"r",
"=",
"self",
".",
"fetch",
"(",
"url",
",",
"payload",
"=",
"params",
")",
"return",
"r",
".",
"text"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
LaunchpadClient.__build_payload
|
Build payload
|
perceval/backends/core/launchpad.py
|
def __build_payload(self, size, operation=False, startdate=None):
"""Build payload"""
payload = {
'ws.size': size,
'order_by': 'date_last_updated',
'omit_duplicates': 'false',
'status': ["New", "Incomplete", "Opinion", "Invalid", "Won't Fix",
"Expired", "Confirmed", "Triaged", "In Progress",
"Fix Committed", "Fix Released",
"Incomplete (with response)",
"Incomplete (without response)"]
}
if operation:
payload['ws.op'] = 'searchTasks'
if startdate:
startdate = startdate.isoformat()
payload['modified_since'] = startdate
return payload
|
def __build_payload(self, size, operation=False, startdate=None):
"""Build payload"""
payload = {
'ws.size': size,
'order_by': 'date_last_updated',
'omit_duplicates': 'false',
'status': ["New", "Incomplete", "Opinion", "Invalid", "Won't Fix",
"Expired", "Confirmed", "Triaged", "In Progress",
"Fix Committed", "Fix Released",
"Incomplete (with response)",
"Incomplete (without response)"]
}
if operation:
payload['ws.op'] = 'searchTasks'
if startdate:
startdate = startdate.isoformat()
payload['modified_since'] = startdate
return payload
|
[
"Build",
"payload"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/launchpad.py#L396-L416
|
[
"def",
"__build_payload",
"(",
"self",
",",
"size",
",",
"operation",
"=",
"False",
",",
"startdate",
"=",
"None",
")",
":",
"payload",
"=",
"{",
"'ws.size'",
":",
"size",
",",
"'order_by'",
":",
"'date_last_updated'",
",",
"'omit_duplicates'",
":",
"'false'",
",",
"'status'",
":",
"[",
"\"New\"",
",",
"\"Incomplete\"",
",",
"\"Opinion\"",
",",
"\"Invalid\"",
",",
"\"Won't Fix\"",
",",
"\"Expired\"",
",",
"\"Confirmed\"",
",",
"\"Triaged\"",
",",
"\"In Progress\"",
",",
"\"Fix Committed\"",
",",
"\"Fix Released\"",
",",
"\"Incomplete (with response)\"",
",",
"\"Incomplete (without response)\"",
"]",
"}",
"if",
"operation",
":",
"payload",
"[",
"'ws.op'",
"]",
"=",
"'searchTasks'",
"if",
"startdate",
":",
"startdate",
"=",
"startdate",
".",
"isoformat",
"(",
")",
"payload",
"[",
"'modified_since'",
"]",
"=",
"startdate",
"return",
"payload"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
LaunchpadClient.__fetch_items
|
Return the items from Launchpad API using pagination
|
perceval/backends/core/launchpad.py
|
def __fetch_items(self, path, payload):
"""Return the items from Launchpad API using pagination"""
page = 0 # current page
url_next = path
fetch_data = True
while fetch_data:
logger.debug("Fetching page: %i", page)
try:
raw_content = self.__send_request(url_next, payload)
content = json.loads(raw_content)
except requests.exceptions.HTTPError as e:
if e.response.status_code in [410]:
logger.warning("Data is not available - %s", url_next)
raw_content = '{"total_size": 0, "start": 0, "entries": []}'
content = json.loads(raw_content)
else:
raise e
if 'next_collection_link' in content:
url_next = content['next_collection_link']
payload = None
else:
fetch_data = False
yield raw_content
page += 1
|
def __fetch_items(self, path, payload):
"""Return the items from Launchpad API using pagination"""
page = 0 # current page
url_next = path
fetch_data = True
while fetch_data:
logger.debug("Fetching page: %i", page)
try:
raw_content = self.__send_request(url_next, payload)
content = json.loads(raw_content)
except requests.exceptions.HTTPError as e:
if e.response.status_code in [410]:
logger.warning("Data is not available - %s", url_next)
raw_content = '{"total_size": 0, "start": 0, "entries": []}'
content = json.loads(raw_content)
else:
raise e
if 'next_collection_link' in content:
url_next = content['next_collection_link']
payload = None
else:
fetch_data = False
yield raw_content
page += 1
|
[
"Return",
"the",
"items",
"from",
"Launchpad",
"API",
"using",
"pagination"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/launchpad.py#L418-L446
|
[
"def",
"__fetch_items",
"(",
"self",
",",
"path",
",",
"payload",
")",
":",
"page",
"=",
"0",
"# current page",
"url_next",
"=",
"path",
"fetch_data",
"=",
"True",
"while",
"fetch_data",
":",
"logger",
".",
"debug",
"(",
"\"Fetching page: %i\"",
",",
"page",
")",
"try",
":",
"raw_content",
"=",
"self",
".",
"__send_request",
"(",
"url_next",
",",
"payload",
")",
"content",
"=",
"json",
".",
"loads",
"(",
"raw_content",
")",
"except",
"requests",
".",
"exceptions",
".",
"HTTPError",
"as",
"e",
":",
"if",
"e",
".",
"response",
".",
"status_code",
"in",
"[",
"410",
"]",
":",
"logger",
".",
"warning",
"(",
"\"Data is not available - %s\"",
",",
"url_next",
")",
"raw_content",
"=",
"'{\"total_size\": 0, \"start\": 0, \"entries\": []}'",
"content",
"=",
"json",
".",
"loads",
"(",
"raw_content",
")",
"else",
":",
"raise",
"e",
"if",
"'next_collection_link'",
"in",
"content",
":",
"url_next",
"=",
"content",
"[",
"'next_collection_link'",
"]",
"payload",
"=",
"None",
"else",
":",
"fetch_data",
"=",
"False",
"yield",
"raw_content",
"page",
"+=",
"1"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
Groupsio.fetch_items
|
Fetch the messages
:param category: the category of items to fetch
:param kwargs: backend arguments
:returns: a generator of items
|
perceval/backends/core/groupsio.py
|
def fetch_items(self, category, **kwargs):
"""Fetch the messages
:param category: the category of items to fetch
:param kwargs: backend arguments
:returns: a generator of items
"""
from_date = kwargs['from_date']
logger.info("Looking for messages from '%s' since %s",
self.uri, str(from_date))
mailing_list = GroupsioClient(self.group_name, self.dirpath,
self.api_token, self.verify)
mailing_list.fetch()
messages = self._fetch_and_parse_messages(mailing_list, from_date)
for message in messages:
yield message
logger.info("Fetch process completed")
|
def fetch_items(self, category, **kwargs):
"""Fetch the messages
:param category: the category of items to fetch
:param kwargs: backend arguments
:returns: a generator of items
"""
from_date = kwargs['from_date']
logger.info("Looking for messages from '%s' since %s",
self.uri, str(from_date))
mailing_list = GroupsioClient(self.group_name, self.dirpath,
self.api_token, self.verify)
mailing_list.fetch()
messages = self._fetch_and_parse_messages(mailing_list, from_date)
for message in messages:
yield message
logger.info("Fetch process completed")
|
[
"Fetch",
"the",
"messages"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/groupsio.py#L89-L111
|
[
"def",
"fetch_items",
"(",
"self",
",",
"category",
",",
"*",
"*",
"kwargs",
")",
":",
"from_date",
"=",
"kwargs",
"[",
"'from_date'",
"]",
"logger",
".",
"info",
"(",
"\"Looking for messages from '%s' since %s\"",
",",
"self",
".",
"uri",
",",
"str",
"(",
"from_date",
")",
")",
"mailing_list",
"=",
"GroupsioClient",
"(",
"self",
".",
"group_name",
",",
"self",
".",
"dirpath",
",",
"self",
".",
"api_token",
",",
"self",
".",
"verify",
")",
"mailing_list",
".",
"fetch",
"(",
")",
"messages",
"=",
"self",
".",
"_fetch_and_parse_messages",
"(",
"mailing_list",
",",
"from_date",
")",
"for",
"message",
"in",
"messages",
":",
"yield",
"message",
"logger",
".",
"info",
"(",
"\"Fetch process completed\"",
")"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
GroupsioClient.fetch
|
Fetch the mbox files from the remote archiver.
Stores the archives in the path given during the initialization
of this object. Those archives which a not valid extension will
be ignored.
Groups.io archives are returned as a .zip file, which contains
one file in mbox format.
:returns: a list of tuples, storing the links and paths of the
fetched archives
|
perceval/backends/core/groupsio.py
|
def fetch(self):
"""Fetch the mbox files from the remote archiver.
Stores the archives in the path given during the initialization
of this object. Those archives which a not valid extension will
be ignored.
Groups.io archives are returned as a .zip file, which contains
one file in mbox format.
:returns: a list of tuples, storing the links and paths of the
fetched archives
"""
logger.info("Downloading mboxes from '%s'", self.uri)
logger.debug("Storing mboxes in '%s'", self.dirpath)
if not os.path.exists(self.dirpath):
os.makedirs(self.dirpath)
group_id = self.__find_group_id()
url = urijoin(GROUPSIO_API_URL, self.DOWNLOAD_ARCHIVES)
payload = {'group_id': group_id}
filepath = os.path.join(self.dirpath, MBOX_FILE)
success = self._download_archive(url, payload, filepath)
return success
|
def fetch(self):
"""Fetch the mbox files from the remote archiver.
Stores the archives in the path given during the initialization
of this object. Those archives which a not valid extension will
be ignored.
Groups.io archives are returned as a .zip file, which contains
one file in mbox format.
:returns: a list of tuples, storing the links and paths of the
fetched archives
"""
logger.info("Downloading mboxes from '%s'", self.uri)
logger.debug("Storing mboxes in '%s'", self.dirpath)
if not os.path.exists(self.dirpath):
os.makedirs(self.dirpath)
group_id = self.__find_group_id()
url = urijoin(GROUPSIO_API_URL, self.DOWNLOAD_ARCHIVES)
payload = {'group_id': group_id}
filepath = os.path.join(self.dirpath, MBOX_FILE)
success = self._download_archive(url, payload, filepath)
return success
|
[
"Fetch",
"the",
"mbox",
"files",
"from",
"the",
"remote",
"archiver",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/groupsio.py#L154-L180
|
[
"def",
"fetch",
"(",
"self",
")",
":",
"logger",
".",
"info",
"(",
"\"Downloading mboxes from '%s'\"",
",",
"self",
".",
"uri",
")",
"logger",
".",
"debug",
"(",
"\"Storing mboxes in '%s'\"",
",",
"self",
".",
"dirpath",
")",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"self",
".",
"dirpath",
")",
":",
"os",
".",
"makedirs",
"(",
"self",
".",
"dirpath",
")",
"group_id",
"=",
"self",
".",
"__find_group_id",
"(",
")",
"url",
"=",
"urijoin",
"(",
"GROUPSIO_API_URL",
",",
"self",
".",
"DOWNLOAD_ARCHIVES",
")",
"payload",
"=",
"{",
"'group_id'",
":",
"group_id",
"}",
"filepath",
"=",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"dirpath",
",",
"MBOX_FILE",
")",
"success",
"=",
"self",
".",
"_download_archive",
"(",
"url",
",",
"payload",
",",
"filepath",
")",
"return",
"success"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
GroupsioClient.subscriptions
|
Fetch the groupsio paginated subscriptions for a given token
:param per_page: number of subscriptions per page
:returns: an iterator of subscriptions
|
perceval/backends/core/groupsio.py
|
def subscriptions(self, per_page=PER_PAGE):
"""Fetch the groupsio paginated subscriptions for a given token
:param per_page: number of subscriptions per page
:returns: an iterator of subscriptions
"""
url = urijoin(GROUPSIO_API_URL, self.GET_SUBSCRIPTIONS)
logger.debug("Get groupsio paginated subscriptions from " + url)
keep_fetching = True
payload = {
"limit": per_page
}
while keep_fetching:
r = self.__fetch(url, payload)
response_raw = r.json()
subscriptions = response_raw['data']
yield subscriptions
total_subscriptions = response_raw['total_count']
logger.debug("Subscriptions: %i/%i" % (response_raw['end_item'], total_subscriptions))
payload['page_token'] = response_raw['next_page_token']
keep_fetching = response_raw['has_more']
|
def subscriptions(self, per_page=PER_PAGE):
"""Fetch the groupsio paginated subscriptions for a given token
:param per_page: number of subscriptions per page
:returns: an iterator of subscriptions
"""
url = urijoin(GROUPSIO_API_URL, self.GET_SUBSCRIPTIONS)
logger.debug("Get groupsio paginated subscriptions from " + url)
keep_fetching = True
payload = {
"limit": per_page
}
while keep_fetching:
r = self.__fetch(url, payload)
response_raw = r.json()
subscriptions = response_raw['data']
yield subscriptions
total_subscriptions = response_raw['total_count']
logger.debug("Subscriptions: %i/%i" % (response_raw['end_item'], total_subscriptions))
payload['page_token'] = response_raw['next_page_token']
keep_fetching = response_raw['has_more']
|
[
"Fetch",
"the",
"groupsio",
"paginated",
"subscriptions",
"for",
"a",
"given",
"token"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/groupsio.py#L182-L207
|
[
"def",
"subscriptions",
"(",
"self",
",",
"per_page",
"=",
"PER_PAGE",
")",
":",
"url",
"=",
"urijoin",
"(",
"GROUPSIO_API_URL",
",",
"self",
".",
"GET_SUBSCRIPTIONS",
")",
"logger",
".",
"debug",
"(",
"\"Get groupsio paginated subscriptions from \"",
"+",
"url",
")",
"keep_fetching",
"=",
"True",
"payload",
"=",
"{",
"\"limit\"",
":",
"per_page",
"}",
"while",
"keep_fetching",
":",
"r",
"=",
"self",
".",
"__fetch",
"(",
"url",
",",
"payload",
")",
"response_raw",
"=",
"r",
".",
"json",
"(",
")",
"subscriptions",
"=",
"response_raw",
"[",
"'data'",
"]",
"yield",
"subscriptions",
"total_subscriptions",
"=",
"response_raw",
"[",
"'total_count'",
"]",
"logger",
".",
"debug",
"(",
"\"Subscriptions: %i/%i\"",
"%",
"(",
"response_raw",
"[",
"'end_item'",
"]",
",",
"total_subscriptions",
")",
")",
"payload",
"[",
"'page_token'",
"]",
"=",
"response_raw",
"[",
"'next_page_token'",
"]",
"keep_fetching",
"=",
"response_raw",
"[",
"'has_more'",
"]"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
GroupsioClient.__find_group_id
|
Find the id of a group given its name by iterating on the list of subscriptions
|
perceval/backends/core/groupsio.py
|
def __find_group_id(self):
"""Find the id of a group given its name by iterating on the list of subscriptions"""
group_subscriptions = self.subscriptions(self.auth)
for subscriptions in group_subscriptions:
for sub in subscriptions:
if sub['group_name'] == self.group_name:
return sub['group_id']
msg = "Group id not found for group name %s" % self.group_name
raise BackendError(cause=msg)
|
def __find_group_id(self):
"""Find the id of a group given its name by iterating on the list of subscriptions"""
group_subscriptions = self.subscriptions(self.auth)
for subscriptions in group_subscriptions:
for sub in subscriptions:
if sub['group_name'] == self.group_name:
return sub['group_id']
msg = "Group id not found for group name %s" % self.group_name
raise BackendError(cause=msg)
|
[
"Find",
"the",
"id",
"of",
"a",
"group",
"given",
"its",
"name",
"by",
"iterating",
"on",
"the",
"list",
"of",
"subscriptions"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/groupsio.py#L229-L240
|
[
"def",
"__find_group_id",
"(",
"self",
")",
":",
"group_subscriptions",
"=",
"self",
".",
"subscriptions",
"(",
"self",
".",
"auth",
")",
"for",
"subscriptions",
"in",
"group_subscriptions",
":",
"for",
"sub",
"in",
"subscriptions",
":",
"if",
"sub",
"[",
"'group_name'",
"]",
"==",
"self",
".",
"group_name",
":",
"return",
"sub",
"[",
"'group_id'",
"]",
"msg",
"=",
"\"Group id not found for group name %s\"",
"%",
"self",
".",
"group_name",
"raise",
"BackendError",
"(",
"cause",
"=",
"msg",
")"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
GroupsioClient.__fetch
|
Fetch requests from groupsio API
|
perceval/backends/core/groupsio.py
|
def __fetch(self, url, payload):
"""Fetch requests from groupsio API"""
r = requests.get(url, params=payload, auth=self.auth, verify=self.verify)
try:
r.raise_for_status()
except requests.exceptions.HTTPError as e:
raise e
return r
|
def __fetch(self, url, payload):
"""Fetch requests from groupsio API"""
r = requests.get(url, params=payload, auth=self.auth, verify=self.verify)
try:
r.raise_for_status()
except requests.exceptions.HTTPError as e:
raise e
return r
|
[
"Fetch",
"requests",
"from",
"groupsio",
"API"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/groupsio.py#L242-L251
|
[
"def",
"__fetch",
"(",
"self",
",",
"url",
",",
"payload",
")",
":",
"r",
"=",
"requests",
".",
"get",
"(",
"url",
",",
"params",
"=",
"payload",
",",
"auth",
"=",
"self",
".",
"auth",
",",
"verify",
"=",
"self",
".",
"verify",
")",
"try",
":",
"r",
".",
"raise_for_status",
"(",
")",
"except",
"requests",
".",
"exceptions",
".",
"HTTPError",
"as",
"e",
":",
"raise",
"e",
"return",
"r"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
GroupsioCommand._pre_init
|
Initialize mailing lists directory path
|
perceval/backends/core/groupsio.py
|
def _pre_init(self):
"""Initialize mailing lists directory path"""
if not self.parsed_args.mboxes_path:
base_path = os.path.expanduser('~/.perceval/mailinglists/')
dirpath = os.path.join(base_path, GROUPSIO_URL, 'g', self.parsed_args.group_name)
else:
dirpath = self.parsed_args.mboxes_path
setattr(self.parsed_args, 'dirpath', dirpath)
|
def _pre_init(self):
"""Initialize mailing lists directory path"""
if not self.parsed_args.mboxes_path:
base_path = os.path.expanduser('~/.perceval/mailinglists/')
dirpath = os.path.join(base_path, GROUPSIO_URL, 'g', self.parsed_args.group_name)
else:
dirpath = self.parsed_args.mboxes_path
setattr(self.parsed_args, 'dirpath', dirpath)
|
[
"Initialize",
"mailing",
"lists",
"directory",
"path"
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/groupsio.py#L259-L268
|
[
"def",
"_pre_init",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"parsed_args",
".",
"mboxes_path",
":",
"base_path",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"'~/.perceval/mailinglists/'",
")",
"dirpath",
"=",
"os",
".",
"path",
".",
"join",
"(",
"base_path",
",",
"GROUPSIO_URL",
",",
"'g'",
",",
"self",
".",
"parsed_args",
".",
"group_name",
")",
"else",
":",
"dirpath",
"=",
"self",
".",
"parsed_args",
".",
"mboxes_path",
"setattr",
"(",
"self",
".",
"parsed_args",
",",
"'dirpath'",
",",
"dirpath",
")"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
GroupsioCommand.setup_cmd_parser
|
Returns the Groupsio argument parser.
|
perceval/backends/core/groupsio.py
|
def setup_cmd_parser(cls):
"""Returns the Groupsio argument parser."""
parser = BackendCommandArgumentParser(cls.BACKEND.CATEGORIES,
from_date=True,
token_auth=True)
# Backend token is required
action = parser.parser._option_string_actions['--api-token']
action.required = True
# Optional arguments
group = parser.parser.add_argument_group('Groupsio arguments')
group.add_argument('--mboxes-path', dest='mboxes_path',
help="Path where mbox files will be stored")
group.add_argument('--no-verify', dest='verify',
action='store_false',
help="Value 'True' enable SSL verification")
# Required arguments
parser.parser.add_argument('group_name',
help="Name of the group on Groups.io")
return parser
|
def setup_cmd_parser(cls):
"""Returns the Groupsio argument parser."""
parser = BackendCommandArgumentParser(cls.BACKEND.CATEGORIES,
from_date=True,
token_auth=True)
# Backend token is required
action = parser.parser._option_string_actions['--api-token']
action.required = True
# Optional arguments
group = parser.parser.add_argument_group('Groupsio arguments')
group.add_argument('--mboxes-path', dest='mboxes_path',
help="Path where mbox files will be stored")
group.add_argument('--no-verify', dest='verify',
action='store_false',
help="Value 'True' enable SSL verification")
# Required arguments
parser.parser.add_argument('group_name',
help="Name of the group on Groups.io")
return parser
|
[
"Returns",
"the",
"Groupsio",
"argument",
"parser",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backends/core/groupsio.py#L271-L294
|
[
"def",
"setup_cmd_parser",
"(",
"cls",
")",
":",
"parser",
"=",
"BackendCommandArgumentParser",
"(",
"cls",
".",
"BACKEND",
".",
"CATEGORIES",
",",
"from_date",
"=",
"True",
",",
"token_auth",
"=",
"True",
")",
"# Backend token is required",
"action",
"=",
"parser",
".",
"parser",
".",
"_option_string_actions",
"[",
"'--api-token'",
"]",
"action",
".",
"required",
"=",
"True",
"# Optional arguments",
"group",
"=",
"parser",
".",
"parser",
".",
"add_argument_group",
"(",
"'Groupsio arguments'",
")",
"group",
".",
"add_argument",
"(",
"'--mboxes-path'",
",",
"dest",
"=",
"'mboxes_path'",
",",
"help",
"=",
"\"Path where mbox files will be stored\"",
")",
"group",
".",
"add_argument",
"(",
"'--no-verify'",
",",
"dest",
"=",
"'verify'",
",",
"action",
"=",
"'store_false'",
",",
"help",
"=",
"\"Value 'True' enable SSL verification\"",
")",
"# Required arguments",
"parser",
".",
"parser",
".",
"add_argument",
"(",
"'group_name'",
",",
"help",
"=",
"\"Name of the group on Groups.io\"",
")",
"return",
"parser"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
uuid
|
Generate a UUID based on the given parameters.
The UUID will be the SHA1 of the concatenation of the values
from the list. The separator bewteedn these values is ':'.
Each value must be a non-empty string, otherwise, the function
will raise an exception.
:param *args: list of arguments used to generate the UUID
:returns: a universal unique identifier
:raises ValueError: when anyone of the values is not a string,
is empty or `None`.
|
perceval/backend.py
|
def uuid(*args):
"""Generate a UUID based on the given parameters.
The UUID will be the SHA1 of the concatenation of the values
from the list. The separator bewteedn these values is ':'.
Each value must be a non-empty string, otherwise, the function
will raise an exception.
:param *args: list of arguments used to generate the UUID
:returns: a universal unique identifier
:raises ValueError: when anyone of the values is not a string,
is empty or `None`.
"""
def check_value(v):
if not isinstance(v, str):
raise ValueError("%s value is not a string instance" % str(v))
elif not v:
raise ValueError("value cannot be None or empty")
else:
return v
s = ':'.join(map(check_value, args))
sha1 = hashlib.sha1(s.encode('utf-8', errors='surrogateescape'))
uuid_sha1 = sha1.hexdigest()
return uuid_sha1
|
def uuid(*args):
"""Generate a UUID based on the given parameters.
The UUID will be the SHA1 of the concatenation of the values
from the list. The separator bewteedn these values is ':'.
Each value must be a non-empty string, otherwise, the function
will raise an exception.
:param *args: list of arguments used to generate the UUID
:returns: a universal unique identifier
:raises ValueError: when anyone of the values is not a string,
is empty or `None`.
"""
def check_value(v):
if not isinstance(v, str):
raise ValueError("%s value is not a string instance" % str(v))
elif not v:
raise ValueError("value cannot be None or empty")
else:
return v
s = ':'.join(map(check_value, args))
sha1 = hashlib.sha1(s.encode('utf-8', errors='surrogateescape'))
uuid_sha1 = sha1.hexdigest()
return uuid_sha1
|
[
"Generate",
"a",
"UUID",
"based",
"on",
"the",
"given",
"parameters",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backend.py#L514-L542
|
[
"def",
"uuid",
"(",
"*",
"args",
")",
":",
"def",
"check_value",
"(",
"v",
")",
":",
"if",
"not",
"isinstance",
"(",
"v",
",",
"str",
")",
":",
"raise",
"ValueError",
"(",
"\"%s value is not a string instance\"",
"%",
"str",
"(",
"v",
")",
")",
"elif",
"not",
"v",
":",
"raise",
"ValueError",
"(",
"\"value cannot be None or empty\"",
")",
"else",
":",
"return",
"v",
"s",
"=",
"':'",
".",
"join",
"(",
"map",
"(",
"check_value",
",",
"args",
")",
")",
"sha1",
"=",
"hashlib",
".",
"sha1",
"(",
"s",
".",
"encode",
"(",
"'utf-8'",
",",
"errors",
"=",
"'surrogateescape'",
")",
")",
"uuid_sha1",
"=",
"sha1",
".",
"hexdigest",
"(",
")",
"return",
"uuid_sha1"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
fetch
|
Fetch items using the given backend.
Generator to get items using the given backend class. When
an archive manager is given, this function will store
the fetched items in an `Archive`. If an exception is raised,
this archive will be removed to avoid corrupted archives.
The parameters needed to initialize the `backend` class and
get the items are given using `backend_args` dict parameter.
:param backend_class: backend class to fetch items
:param backend_args: dict of arguments needed to fetch the items
:param category: category of the items to retrieve.
If None, it will use the default backend category
:param filter_classified: remove classified fields from the resulting items
:param manager: archive manager needed to store the items
:returns: a generator of items
|
perceval/backend.py
|
def fetch(backend_class, backend_args, category, filter_classified=False,
manager=None):
"""Fetch items using the given backend.
Generator to get items using the given backend class. When
an archive manager is given, this function will store
the fetched items in an `Archive`. If an exception is raised,
this archive will be removed to avoid corrupted archives.
The parameters needed to initialize the `backend` class and
get the items are given using `backend_args` dict parameter.
:param backend_class: backend class to fetch items
:param backend_args: dict of arguments needed to fetch the items
:param category: category of the items to retrieve.
If None, it will use the default backend category
:param filter_classified: remove classified fields from the resulting items
:param manager: archive manager needed to store the items
:returns: a generator of items
"""
init_args = find_signature_parameters(backend_class.__init__,
backend_args)
archive = manager.create_archive() if manager else None
init_args['archive'] = archive
backend = backend_class(**init_args)
if category:
backend_args['category'] = category
if filter_classified:
backend_args['filter_classified'] = filter_classified
fetch_args = find_signature_parameters(backend.fetch,
backend_args)
items = backend.fetch(**fetch_args)
try:
for item in items:
yield item
except Exception as e:
if manager:
archive_path = archive.archive_path
manager.remove_archive(archive_path)
raise e
|
def fetch(backend_class, backend_args, category, filter_classified=False,
manager=None):
"""Fetch items using the given backend.
Generator to get items using the given backend class. When
an archive manager is given, this function will store
the fetched items in an `Archive`. If an exception is raised,
this archive will be removed to avoid corrupted archives.
The parameters needed to initialize the `backend` class and
get the items are given using `backend_args` dict parameter.
:param backend_class: backend class to fetch items
:param backend_args: dict of arguments needed to fetch the items
:param category: category of the items to retrieve.
If None, it will use the default backend category
:param filter_classified: remove classified fields from the resulting items
:param manager: archive manager needed to store the items
:returns: a generator of items
"""
init_args = find_signature_parameters(backend_class.__init__,
backend_args)
archive = manager.create_archive() if manager else None
init_args['archive'] = archive
backend = backend_class(**init_args)
if category:
backend_args['category'] = category
if filter_classified:
backend_args['filter_classified'] = filter_classified
fetch_args = find_signature_parameters(backend.fetch,
backend_args)
items = backend.fetch(**fetch_args)
try:
for item in items:
yield item
except Exception as e:
if manager:
archive_path = archive.archive_path
manager.remove_archive(archive_path)
raise e
|
[
"Fetch",
"items",
"using",
"the",
"given",
"backend",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backend.py#L545-L589
|
[
"def",
"fetch",
"(",
"backend_class",
",",
"backend_args",
",",
"category",
",",
"filter_classified",
"=",
"False",
",",
"manager",
"=",
"None",
")",
":",
"init_args",
"=",
"find_signature_parameters",
"(",
"backend_class",
".",
"__init__",
",",
"backend_args",
")",
"archive",
"=",
"manager",
".",
"create_archive",
"(",
")",
"if",
"manager",
"else",
"None",
"init_args",
"[",
"'archive'",
"]",
"=",
"archive",
"backend",
"=",
"backend_class",
"(",
"*",
"*",
"init_args",
")",
"if",
"category",
":",
"backend_args",
"[",
"'category'",
"]",
"=",
"category",
"if",
"filter_classified",
":",
"backend_args",
"[",
"'filter_classified'",
"]",
"=",
"filter_classified",
"fetch_args",
"=",
"find_signature_parameters",
"(",
"backend",
".",
"fetch",
",",
"backend_args",
")",
"items",
"=",
"backend",
".",
"fetch",
"(",
"*",
"*",
"fetch_args",
")",
"try",
":",
"for",
"item",
"in",
"items",
":",
"yield",
"item",
"except",
"Exception",
"as",
"e",
":",
"if",
"manager",
":",
"archive_path",
"=",
"archive",
".",
"archive_path",
"manager",
".",
"remove_archive",
"(",
"archive_path",
")",
"raise",
"e"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
fetch_from_archive
|
Fetch items from an archive manager.
Generator to get the items of a category (previously fetched
by the given backend class) from an archive manager. Only those
items archived after the given date will be returned.
The parameters needed to initialize `backend` and get the
items are given using `backend_args` dict parameter.
:param backend_class: backend class to retrive items
:param backend_args: dict of arguments needed to retrieve the items
:param manager: archive manager where the items will be retrieved
:param category: category of the items to retrieve
:param archived_after: return items archived after this date
:returns: a generator of archived items
|
perceval/backend.py
|
def fetch_from_archive(backend_class, backend_args, manager,
category, archived_after):
"""Fetch items from an archive manager.
Generator to get the items of a category (previously fetched
by the given backend class) from an archive manager. Only those
items archived after the given date will be returned.
The parameters needed to initialize `backend` and get the
items are given using `backend_args` dict parameter.
:param backend_class: backend class to retrive items
:param backend_args: dict of arguments needed to retrieve the items
:param manager: archive manager where the items will be retrieved
:param category: category of the items to retrieve
:param archived_after: return items archived after this date
:returns: a generator of archived items
"""
init_args = find_signature_parameters(backend_class.__init__,
backend_args)
backend = backend_class(**init_args)
filepaths = manager.search(backend.origin,
backend.__class__.__name__,
category,
archived_after)
for filepath in filepaths:
backend.archive = Archive(filepath)
items = backend.fetch_from_archive()
try:
for item in items:
yield item
except ArchiveError as e:
logger.warning("Ignoring %s archive due to: %s", filepath, str(e))
|
def fetch_from_archive(backend_class, backend_args, manager,
category, archived_after):
"""Fetch items from an archive manager.
Generator to get the items of a category (previously fetched
by the given backend class) from an archive manager. Only those
items archived after the given date will be returned.
The parameters needed to initialize `backend` and get the
items are given using `backend_args` dict parameter.
:param backend_class: backend class to retrive items
:param backend_args: dict of arguments needed to retrieve the items
:param manager: archive manager where the items will be retrieved
:param category: category of the items to retrieve
:param archived_after: return items archived after this date
:returns: a generator of archived items
"""
init_args = find_signature_parameters(backend_class.__init__,
backend_args)
backend = backend_class(**init_args)
filepaths = manager.search(backend.origin,
backend.__class__.__name__,
category,
archived_after)
for filepath in filepaths:
backend.archive = Archive(filepath)
items = backend.fetch_from_archive()
try:
for item in items:
yield item
except ArchiveError as e:
logger.warning("Ignoring %s archive due to: %s", filepath, str(e))
|
[
"Fetch",
"items",
"from",
"an",
"archive",
"manager",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backend.py#L592-L628
|
[
"def",
"fetch_from_archive",
"(",
"backend_class",
",",
"backend_args",
",",
"manager",
",",
"category",
",",
"archived_after",
")",
":",
"init_args",
"=",
"find_signature_parameters",
"(",
"backend_class",
".",
"__init__",
",",
"backend_args",
")",
"backend",
"=",
"backend_class",
"(",
"*",
"*",
"init_args",
")",
"filepaths",
"=",
"manager",
".",
"search",
"(",
"backend",
".",
"origin",
",",
"backend",
".",
"__class__",
".",
"__name__",
",",
"category",
",",
"archived_after",
")",
"for",
"filepath",
"in",
"filepaths",
":",
"backend",
".",
"archive",
"=",
"Archive",
"(",
"filepath",
")",
"items",
"=",
"backend",
".",
"fetch_from_archive",
"(",
")",
"try",
":",
"for",
"item",
"in",
"items",
":",
"yield",
"item",
"except",
"ArchiveError",
"as",
"e",
":",
"logger",
".",
"warning",
"(",
"\"Ignoring %s archive due to: %s\"",
",",
"filepath",
",",
"str",
"(",
"e",
")",
")"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
find_backends
|
Find available backends.
Look for the Perceval backends and commands under `top_package`
and its sub-packages. When `top_package` defines a namespace,
backends under that same namespace will be found too.
:param top_package: package storing backends
:returns: a tuple with two dicts: one with `Backend` classes and one
with `BackendCommand` classes
|
perceval/backend.py
|
def find_backends(top_package):
"""Find available backends.
Look for the Perceval backends and commands under `top_package`
and its sub-packages. When `top_package` defines a namespace,
backends under that same namespace will be found too.
:param top_package: package storing backends
:returns: a tuple with two dicts: one with `Backend` classes and one
with `BackendCommand` classes
"""
candidates = pkgutil.walk_packages(top_package.__path__,
prefix=top_package.__name__ + '.')
modules = [name for _, name, is_pkg in candidates if not is_pkg]
return _import_backends(modules)
|
def find_backends(top_package):
"""Find available backends.
Look for the Perceval backends and commands under `top_package`
and its sub-packages. When `top_package` defines a namespace,
backends under that same namespace will be found too.
:param top_package: package storing backends
:returns: a tuple with two dicts: one with `Backend` classes and one
with `BackendCommand` classes
"""
candidates = pkgutil.walk_packages(top_package.__path__,
prefix=top_package.__name__ + '.')
modules = [name for _, name, is_pkg in candidates if not is_pkg]
return _import_backends(modules)
|
[
"Find",
"available",
"backends",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backend.py#L631-L648
|
[
"def",
"find_backends",
"(",
"top_package",
")",
":",
"candidates",
"=",
"pkgutil",
".",
"walk_packages",
"(",
"top_package",
".",
"__path__",
",",
"prefix",
"=",
"top_package",
".",
"__name__",
"+",
"'.'",
")",
"modules",
"=",
"[",
"name",
"for",
"_",
",",
"name",
",",
"is_pkg",
"in",
"candidates",
"if",
"not",
"is_pkg",
"]",
"return",
"_import_backends",
"(",
"modules",
")"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
Backend.fetch
|
Fetch items from the repository.
The method retrieves items from a repository.
To removed classified fields from the resulting items, set
the parameter `filter_classified`. Take into account this
parameter is incompatible with archiving items. Raw client
data are archived before any other process. Therefore,
classified data are stored within the archive. To prevent
from possible data leaks or security issues when users do
not need these fields, archiving and filtering are not
compatible.
:param category: the category of the items fetched
:param filter_classified: remove classified fields from the resulting items
:param kwargs: a list of other parameters (e.g., from_date, offset, etc.
specific for each backend)
:returns: a generator of items
:raises BackendError: either when the category is not valid or
'filter_classified' and 'archive' are active at the same time.
|
perceval/backend.py
|
def fetch(self, category, filter_classified=False, **kwargs):
"""Fetch items from the repository.
The method retrieves items from a repository.
To removed classified fields from the resulting items, set
the parameter `filter_classified`. Take into account this
parameter is incompatible with archiving items. Raw client
data are archived before any other process. Therefore,
classified data are stored within the archive. To prevent
from possible data leaks or security issues when users do
not need these fields, archiving and filtering are not
compatible.
:param category: the category of the items fetched
:param filter_classified: remove classified fields from the resulting items
:param kwargs: a list of other parameters (e.g., from_date, offset, etc.
specific for each backend)
:returns: a generator of items
:raises BackendError: either when the category is not valid or
'filter_classified' and 'archive' are active at the same time.
"""
if category not in self.categories:
cause = "%s category not valid for %s" % (category, self.__class__.__name__)
raise BackendError(cause=cause)
if filter_classified and self.archive:
cause = "classified fields filtering is not compatible with archiving items"
raise BackendError(cause=cause)
if self.archive:
self.archive.init_metadata(self.origin, self.__class__.__name__, self.version, category,
kwargs)
self.client = self._init_client()
for item in self.fetch_items(category, **kwargs):
if filter_classified:
item = self.filter_classified_data(item)
yield self.metadata(item, filter_classified=filter_classified)
|
def fetch(self, category, filter_classified=False, **kwargs):
"""Fetch items from the repository.
The method retrieves items from a repository.
To removed classified fields from the resulting items, set
the parameter `filter_classified`. Take into account this
parameter is incompatible with archiving items. Raw client
data are archived before any other process. Therefore,
classified data are stored within the archive. To prevent
from possible data leaks or security issues when users do
not need these fields, archiving and filtering are not
compatible.
:param category: the category of the items fetched
:param filter_classified: remove classified fields from the resulting items
:param kwargs: a list of other parameters (e.g., from_date, offset, etc.
specific for each backend)
:returns: a generator of items
:raises BackendError: either when the category is not valid or
'filter_classified' and 'archive' are active at the same time.
"""
if category not in self.categories:
cause = "%s category not valid for %s" % (category, self.__class__.__name__)
raise BackendError(cause=cause)
if filter_classified and self.archive:
cause = "classified fields filtering is not compatible with archiving items"
raise BackendError(cause=cause)
if self.archive:
self.archive.init_metadata(self.origin, self.__class__.__name__, self.version, category,
kwargs)
self.client = self._init_client()
for item in self.fetch_items(category, **kwargs):
if filter_classified:
item = self.filter_classified_data(item)
yield self.metadata(item, filter_classified=filter_classified)
|
[
"Fetch",
"items",
"from",
"the",
"repository",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backend.py#L124-L166
|
[
"def",
"fetch",
"(",
"self",
",",
"category",
",",
"filter_classified",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"category",
"not",
"in",
"self",
".",
"categories",
":",
"cause",
"=",
"\"%s category not valid for %s\"",
"%",
"(",
"category",
",",
"self",
".",
"__class__",
".",
"__name__",
")",
"raise",
"BackendError",
"(",
"cause",
"=",
"cause",
")",
"if",
"filter_classified",
"and",
"self",
".",
"archive",
":",
"cause",
"=",
"\"classified fields filtering is not compatible with archiving items\"",
"raise",
"BackendError",
"(",
"cause",
"=",
"cause",
")",
"if",
"self",
".",
"archive",
":",
"self",
".",
"archive",
".",
"init_metadata",
"(",
"self",
".",
"origin",
",",
"self",
".",
"__class__",
".",
"__name__",
",",
"self",
".",
"version",
",",
"category",
",",
"kwargs",
")",
"self",
".",
"client",
"=",
"self",
".",
"_init_client",
"(",
")",
"for",
"item",
"in",
"self",
".",
"fetch_items",
"(",
"category",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"filter_classified",
":",
"item",
"=",
"self",
".",
"filter_classified_data",
"(",
"item",
")",
"yield",
"self",
".",
"metadata",
"(",
"item",
",",
"filter_classified",
"=",
"filter_classified",
")"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
Backend.fetch_from_archive
|
Fetch the questions from an archive.
It returns the items stored within an archive. If this method is called but
no archive was provided, the method will raise a `ArchiveError` exception.
:returns: a generator of items
:raises ArchiveError: raised when an error occurs accessing an archive
|
perceval/backend.py
|
def fetch_from_archive(self):
"""Fetch the questions from an archive.
It returns the items stored within an archive. If this method is called but
no archive was provided, the method will raise a `ArchiveError` exception.
:returns: a generator of items
:raises ArchiveError: raised when an error occurs accessing an archive
"""
if not self.archive:
raise ArchiveError(cause="archive instance was not provided")
self.client = self._init_client(from_archive=True)
for item in self.fetch_items(self.archive.category, **self.archive.backend_params):
yield self.metadata(item)
|
def fetch_from_archive(self):
"""Fetch the questions from an archive.
It returns the items stored within an archive. If this method is called but
no archive was provided, the method will raise a `ArchiveError` exception.
:returns: a generator of items
:raises ArchiveError: raised when an error occurs accessing an archive
"""
if not self.archive:
raise ArchiveError(cause="archive instance was not provided")
self.client = self._init_client(from_archive=True)
for item in self.fetch_items(self.archive.category, **self.archive.backend_params):
yield self.metadata(item)
|
[
"Fetch",
"the",
"questions",
"from",
"an",
"archive",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backend.py#L168-L184
|
[
"def",
"fetch_from_archive",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"archive",
":",
"raise",
"ArchiveError",
"(",
"cause",
"=",
"\"archive instance was not provided\"",
")",
"self",
".",
"client",
"=",
"self",
".",
"_init_client",
"(",
"from_archive",
"=",
"True",
")",
"for",
"item",
"in",
"self",
".",
"fetch_items",
"(",
"self",
".",
"archive",
".",
"category",
",",
"*",
"*",
"self",
".",
"archive",
".",
"backend_params",
")",
":",
"yield",
"self",
".",
"metadata",
"(",
"item",
")"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
test
|
Backend.filter_classified_data
|
Remove classified or confidential data from an item.
It removes those fields that contain data considered as classified.
Classified fields are defined in `CLASSIFIED_FIELDS` class attribute.
:param item: fields will be removed from this item
:returns: the same item but with confidential data filtered
|
perceval/backend.py
|
def filter_classified_data(self, item):
"""Remove classified or confidential data from an item.
It removes those fields that contain data considered as classified.
Classified fields are defined in `CLASSIFIED_FIELDS` class attribute.
:param item: fields will be removed from this item
:returns: the same item but with confidential data filtered
"""
item_uuid = uuid(self.origin, self.metadata_id(item))
logger.debug("Filtering classified data for item %s", item_uuid)
for cf in self.CLASSIFIED_FIELDS:
try:
_remove_key_from_nested_dict(item, cf)
except KeyError:
logger.debug("Classified field '%s' not found for item %s; field ignored",
'.'.join(cf), item_uuid)
logger.debug("Classified data filtered for item %s", item_uuid)
return item
|
def filter_classified_data(self, item):
"""Remove classified or confidential data from an item.
It removes those fields that contain data considered as classified.
Classified fields are defined in `CLASSIFIED_FIELDS` class attribute.
:param item: fields will be removed from this item
:returns: the same item but with confidential data filtered
"""
item_uuid = uuid(self.origin, self.metadata_id(item))
logger.debug("Filtering classified data for item %s", item_uuid)
for cf in self.CLASSIFIED_FIELDS:
try:
_remove_key_from_nested_dict(item, cf)
except KeyError:
logger.debug("Classified field '%s' not found for item %s; field ignored",
'.'.join(cf), item_uuid)
logger.debug("Classified data filtered for item %s", item_uuid)
return item
|
[
"Remove",
"classified",
"or",
"confidential",
"data",
"from",
"an",
"item",
"."
] |
chaoss/grimoirelab-perceval
|
python
|
https://github.com/chaoss/grimoirelab-perceval/blob/41c908605e88b7ebc3a536c643fa0f212eaf9e0e/perceval/backend.py#L186-L209
|
[
"def",
"filter_classified_data",
"(",
"self",
",",
"item",
")",
":",
"item_uuid",
"=",
"uuid",
"(",
"self",
".",
"origin",
",",
"self",
".",
"metadata_id",
"(",
"item",
")",
")",
"logger",
".",
"debug",
"(",
"\"Filtering classified data for item %s\"",
",",
"item_uuid",
")",
"for",
"cf",
"in",
"self",
".",
"CLASSIFIED_FIELDS",
":",
"try",
":",
"_remove_key_from_nested_dict",
"(",
"item",
",",
"cf",
")",
"except",
"KeyError",
":",
"logger",
".",
"debug",
"(",
"\"Classified field '%s' not found for item %s; field ignored\"",
",",
"'.'",
".",
"join",
"(",
"cf",
")",
",",
"item_uuid",
")",
"logger",
".",
"debug",
"(",
"\"Classified data filtered for item %s\"",
",",
"item_uuid",
")",
"return",
"item"
] |
41c908605e88b7ebc3a536c643fa0f212eaf9e0e
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.