|
1 | 1 | # -*- coding: utf-8 -*- |
2 | | - |
| 2 | +import json |
3 | 3 | import logging |
4 | 4 | import os |
5 | 5 | import os.path |
@@ -42,36 +42,29 @@ def _get_pandoc_urls(version="latest"): |
42 | 42 | :return: str version: actual pandoc version. (e.g. "latest" will be resolved to the actual one) |
43 | 43 | """ |
44 | 44 | # url to pandoc download page |
45 | | - url = "https://github.com/jgm/pandoc/releases/" + \ |
46 | | - ("tag/" if version != "latest" else "") + version |
| 45 | + url = "https://api.github.com/repos/jgm/pandoc/releases/" + \ |
| 46 | + ("tags/" if version != "latest" else "") + version |
47 | 47 | # try to open the url |
48 | 48 | try: |
49 | 49 | response = urlopen(url) |
50 | | - version_url_frags = response.url.split("/") |
51 | | - version = version_url_frags[-1] |
52 | 50 | except urllib.error.HTTPError as e: |
53 | 51 | raise RuntimeError("Invalid pandoc version {}.".format(version)) |
54 | | - return |
55 | | - # read the HTML content |
56 | | - response = urlopen(f"https://github.com/jgm/pandoc/releases/expanded_assets/{version}") |
57 | | - content = response.read() |
58 | | - # regex for the binaries |
59 | | - uname = platform.uname()[4] |
60 | | - processor_architecture = "arm" if uname.startswith("arm") or uname.startswith("aarch") else "amd" |
61 | | - regex = re.compile(fr"/jgm/pandoc/releases/download/.*(?:{processor_architecture}|x86|mac).*\.(?:msi|deb|pkg)") |
62 | | - # a list of urls to the binaries |
63 | | - pandoc_urls_list = regex.findall(content.decode("utf-8")) |
| 52 | + # read the json response |
| 53 | + data = json.loads(response.read()) |
64 | 54 | # actual pandoc version |
65 | | - version = pandoc_urls_list[0].split('/')[5] |
| 55 | + version = data["tag_name"] |
66 | 56 | # dict that lookup the platform from binary extension |
67 | 57 | ext2platform = { |
68 | 58 | 'msi': 'win32', |
69 | 59 | 'deb': 'linux', |
70 | 60 | 'pkg': 'darwin' |
71 | | - } |
72 | | - # parse pandoc_urls from list to dict |
73 | | - # py26 don't like dict comprehension. Use this one instead when py26 support is dropped |
74 | | - pandoc_urls = {ext2platform[url_frag[-3:]]: (f"https://github.com{url_frag}") for url_frag in pandoc_urls_list} |
| 61 | + } |
| 62 | + # collect pandoc urls from json content |
| 63 | + pandoc_urls = dict() |
| 64 | + for asset in data["assets"]: |
| 65 | + pf = ext2platform.get(asset["name"][-3:]) |
| 66 | + if pf: |
| 67 | + pandoc_urls[pf] = asset["browser_download_url"] |
75 | 68 | return pandoc_urls, version |
76 | 69 |
|
77 | 70 |
|
|
0 commit comments