summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2015-11-23 21:33:22 +0100
committerDaniel Schadt <kingdread@gmx.de>2015-12-20 19:24:41 +0100
commitef85d1af4ce740341c0689bdfe902ed1169a198f (patch)
treea24040499e47fbf51758a01c8e20a30674580ead /scripts
parentccb8e31e78ade1e5bb4d803be421a1dc6a8ac9ef (diff)
downloadqutebrowser-ef85d1af4ce740341c0689bdfe902ed1169a198f.tar.gz
qutebrowser-ef85d1af4ce740341c0689bdfe902ed1169a198f.zip
Move pdfjs and use original files
* No modified pdfjs installation needed -> Groundwork for using a system-wide installation * Script update_3rdparty.py to download and upack the latest pdfjs release
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/dev/update_3rdparty.py65
1 files changed, 65 insertions, 0 deletions
diff --git a/scripts/dev/update_3rdparty.py b/scripts/dev/update_3rdparty.py
new file mode 100755
index 000000000..bb9d70013
--- /dev/null
+++ b/scripts/dev/update_3rdparty.py
@@ -0,0 +1,65 @@
+#!/usr/bin/env python3
+# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
+
+# Copyright 2015 Daniel Schadt
+#
+# This file is part of qutebrowser.
+#
+# qutebrowser is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# qutebrowser is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
+
+"""Update all third-party-modules."""
+
+import urllib.request
+import tempfile
+import shutil
+import json
+import os
+
+
+def get_latest_pdfjs_url():
+ """Get the URL of the latest pdf.js prebuilt package.
+
+ Returns a (version, url)-tuple."""
+ github_api = 'https://api.github.com'
+ endpoint = 'repos/mozilla/pdf.js/releases/latest'
+ request_url = '{}/{}'.format(github_api, endpoint)
+ with urllib.request.urlopen(request_url) as fp:
+ data = json.loads(fp.read().decode('utf-8'))
+
+ download_url = data['assets'][0]['browser_download_url']
+ version_name = data['name']
+ return (version_name, download_url)
+
+
+def update_pdfjs():
+ version, url = get_latest_pdfjs_url()
+ target_path = os.path.join('qutebrowser', '3rdparty', 'pdfjs')
+ print("=> Downloading pdf.js {}".format(version))
+ with tempfile.NamedTemporaryFile(prefix='qute-pdfjs-') as archive:
+ urllib.request.urlretrieve(url, archive.name)
+ if os.path.isdir(target_path):
+ print("Removing old version in {}".format(target_path))
+ shutil.rmtree(target_path)
+ os.makedirs(target_path)
+ print("Extracting new version")
+ shutil.unpack_archive(archive, target_path, 'zip')
+
+
+
+
+def main():
+ update_pdfjs()
+
+if __name__ == '__main__':
+ main()