This repository was archived by the owner on Feb 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathfind-bindist
More file actions
executable file
·69 lines (57 loc) · 1.41 KB
/
find-bindist
File metadata and controls
executable file
·69 lines (57 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python
#
# Return the url for a GHC bindist.
#
# Examples:
# find-bindist apple
# find-bindist deb8 64
# find-bindist i3 ming
# find-bindist apple 7.10.2
# find-bindist -- shows all bin dists
import requests
import re
import os
import sys
BASE_URL = "http://downloads.haskell.org/~ghc"
DEFAULT_GHC_VERSION = "8.0.1"
def list_bin_dists(url):
r = requests.get(url)
contents = r.text
return re.findall('a href="(ghc-.*?.tar.xz)"', contents)
def has_words(words, m):
for w in words:
if not (w in m):
return False
return True
def is_ghc_vers(arg):
return re.match("(\d+)\.(\d+)\.(\d+)\Z", arg)
def process_args(args):
versions = []
others = []
for arg in args:
if is_ghc_vers(arg):
versions.append(arg)
else:
others.append(arg)
return versions, others
def main():
args = sys.argv[1:]
versions, words = process_args(sys.argv[1:])
if not versions:
versions.append(DEFAULT_GHC_VERSION)
ghc_vers = versions[0]
url = BASE_URL + "/" + ghc_vers + "/"
matches = [ m for m in list_bin_dists(url) if has_words(words, m) ]
if not matches:
if words:
msg = " contain the words: " + ", ".join(words)
else:
msg = ""
print "no bindists for version " + ghc_vers + msg
elif len(matches) == 1:
print url + matches[0]
else:
print "Multiple matching bindists:"
for m in matches:
print " ", url + m
main()