summaryrefslogtreecommitdiff
path: root/scripts/dev/update_3rdparty.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/dev/update_3rdparty.py')
-rwxr-xr-xscripts/dev/update_3rdparty.py23
1 files changed, 13 insertions, 10 deletions
diff --git a/scripts/dev/update_3rdparty.py b/scripts/dev/update_3rdparty.py
index 76f77303c..88f56b7f3 100755
--- a/scripts/dev/update_3rdparty.py
+++ b/scripts/dev/update_3rdparty.py
@@ -64,7 +64,7 @@ def download_nsis_plugins():
urllib.request.urlcleanup()
-def get_latest_pdfjs_url():
+def get_latest_pdfjs_url(gh_token):
"""Get the URL of the latest pdf.js prebuilt package.
Returns a (version, url)-tuple.
@@ -73,12 +73,12 @@ def get_latest_pdfjs_url():
endpoint = 'repos/mozilla/pdf.js/releases/latest'
request = urllib.request.Request(f'{github_api}/{endpoint}')
- token = os.environ.get('GITHUB_TOKEN')
- if token is not None:
+ if gh_token is not None:
# Without token will work as well, but has a strict rate limit, so we need to
# use the token on CI.
- request.add_header('Authorization', f'token {token}')
- print("Using GITHUB_TOKEN to authorize to GitHub.")
+ request.add_header('Authorization', f'token {gh_token}')
+ elif 'CI' in os.environ:
+ raise Exception("No GitHub token given on CI")
with urllib.request.urlopen(request) as fp:
data = json.loads(fp.read().decode('utf-8'))
@@ -88,16 +88,17 @@ def get_latest_pdfjs_url():
return (version_name, download_url)
-def update_pdfjs(target_version=None):
+def update_pdfjs(target_version=None, gh_token=None):
"""Download and extract the latest pdf.js version.
If target_version is not None, download the given version instead.
Args:
target_version: None or version string ('x.y.z')
+ gh_token: GitHub token to use for the API. Optional except on CI.
"""
if target_version is None:
- version, url = get_latest_pdfjs_url()
+ version, url = get_latest_pdfjs_url(gh_token)
else:
# We need target_version as x.y.z, without the 'v' prefix, though the
# user might give it on the command line
@@ -167,12 +168,12 @@ def test_dicts():
def run(nsis=False, ace=False, pdfjs=True, fancy_dmg=False, pdfjs_version=None,
- dicts=False):
+ dicts=False, gh_token=None):
"""Update components based on the given arguments."""
if nsis:
download_nsis_plugins()
if pdfjs:
- update_pdfjs(pdfjs_version)
+ update_pdfjs(pdfjs_version, gh_token=gh_token)
if ace:
update_ace()
if fancy_dmg:
@@ -197,9 +198,11 @@ def main():
help='Test whether all available dictionaries '
'can be reached at the remote repository.',
required=False, action='store_true')
+ parser.add_argument(
+ '--gh-token', help="GitHub token to use.", nargs='?')
args = parser.parse_args()
run(nsis=False, ace=True, pdfjs=True, fancy_dmg=args.fancy_dmg,
- pdfjs_version=args.pdfjs, dicts=args.dicts)
+ pdfjs_version=args.pdfjs, dicts=args.dicts, gh_token=args.gh_token)
if __name__ == '__main__':