8000 add support for private github repos · cclauss/python-for-android@1068a81 · GitHub
[go: up one dir, main page]

< 8000 a href="#start-of-content" data-skip-target-assigned="false" class="px-2 py-4 color-bg-accent-emphasis color-fg-on-emphasis show-on-focus js-skip-to-content">Skip to content

Commit 1068a81

Browse files
committed
add support for private github repos
1 parent 9bfa3eb commit 1068a81

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

pythonforandroid/recipe.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ class Recipe(metaclass=RecipeMeta):
5959
if you want.
6060
'''
6161

62+
_github_access_token = None
63+
'''Used to access a private git repository. Specify the github-supplied
64+
access token in order to download the private repository files.
65+
'''
66+
6267
_version = None
6368
'''A string giving the version of the software the recipe describes,
6469
e.g. ``2.0.3`` or ``master``.'''
@@ -170,6 +175,11 @@ def versioned_url(self):
170175
return None
171176
return self.url.format(version=self.version)
172177

178+
@property
179+
def github_access_token(self):
180+
key = "GITHUB_ACCESS_TOKEN_" + self.name
181+
return environ.get(key, self._github_access_token)
182+
173183
def download_file(self, url, target, cwd=None):
174184
"""
175185
(internal) Download an ``url`` to a ``target``.
@@ -205,6 +215,9 @@ def report_hook(index, blksize, size):
205215
# jqueryui.com returns a 403 w/ the default user agent
206216
# Mozilla/5.0 doesnt handle redirection for liblzma
207217
url_opener.addheaders = [('User-agent', 'Wget/1.0')]
218+
if self.github_access_token:
219+
url_opener.addheaders += [('Authorization', f'token {self.github_access_token}'),
220+
('Accept', 'application/vnd.github.v3.raw')]
208221
urlretrieve(url, target, report_hook)
209222
except OSError as e:
210223
attempts += 1

0 commit comments

Comments
 (0)
0