8000 Add a download archive feature to Release · pythonthings/github3.py@b7ca5a9 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b7ca5a9

Browse files
committed
Add a download archive feature to Release
1 parent 47487d0 commit b7ca5a9

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

github3/repos/release.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,46 @@ def _update_attributes(self, release):
4646
self.published_at = self._strptime(release.get('published_at'))
4747
#: Name of the tag
4848
self.tag_name = release.get('tag_name')
49+
#: URL to download a tarball of the release
50+
self.tarball_url = release.get('tarball_url')
4951
#: "Commit" that this release targets
5052
self.target_commitish = release.get('target_commitish')
5153
upload_url = release.get('upload_url')
5254
#: URITemplate to upload an asset with
5355
self.upload_urlt = URITemplate(upload_url) if upload_url else None
56+
#: URL to download a zipball of the release
57+
self.zipball_url = release.get('zipball_url')
5458

5559
def _repr(self):
5660
return '<Release [{0}]>'.format(self.name)
5761

62+
def archive(self, format, path=''):
63+
"""Get the tarball or zipball archive for this release.
64+
65+
:param str format: (required), accepted values: ('tarball',
66+
'zipball')
67+
:param path: (optional), path where the file should be saved
68+
to, default is the filename provided in the headers and will be
69+
written in the current directory.
70+
it can take a file-like object as well
71+
:type path: str, file
72+
:returns: bool -- True if successful, False otherwise
73+
74+
"""
75+
resp = None
76+
if format == 'tarball':
77+
resp = self._get(self.tarball_url, allow_redirects=True,
78+
stream=True)
79+
80+
elif format == 'zipball':
81+
resp = self._get(self.zipball_url, allow_redirects=True,
82+
stream=True)
83+
84+
if resp and self._boolean(resp, 200, 404):
85+
utils.stream_response_to_file(resp, path)
86+
return True
87+
return False
88+
5889
def asset(self, asset_id):
5990
"""Retrieve the asset from this release with ``asset_id``.
6091

0 commit comments

Comments
 (0)
0