-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathuranium
executable file
·48 lines (40 loc) · 1.69 KB
/
uranium
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
#!/usr/bin/env python3
# warmup should be added into everyone's root level repository. warmup will:
# * download and set up a virtualenv
# * install uranium
# * run uranium
import os
ROOT = os.path.dirname(__file__)
URANIUM_PATH = os.getenv('URANIUM_PATH', None)
URANIUM_GITHUB_ACCOUNT = os.getenv('URANIUM_GITHUB_ACCOUNT', 'toumorokoshi')
URANIUM_GITHUB_BRANCH = os.getenv('URANIUM_GITHUB_BRANCH', 'master')
URANIUM_STANDALONE_URL = "https://raw.githubusercontent.com/{account}/uranium/{branch}/uranium/scripts/uranium_standalone".format(account=URANIUM_GITHUB_ACCOUNT, branch=URANIUM_GITHUB_BRANCH)
CACHE_DIRECTORY = os.path.join(ROOT, ".uranium")
CACHED_URANIUM_STANDALONE = os.path.join(CACHE_DIRECTORY, "uranium_standalone")
def get_cached_standalone():
if not os.path.isfile(CACHED_URANIUM_STANDALONE):
return None
with open(CACHED_URANIUM_STANDALONE) as fh:
return fh.read()
def store_cached_standalone(body):
if not os.path.exists(CACHE_DIRECTORY):
os.makedirs(CACHE_DIRECTORY)
with open(CACHED_URANIUM_STANDALONE, "wb+") as fh:
fh.write(body)
cached_standalone = get_cached_standalone()
if URANIUM_PATH is not None:
print("Executing uranium from " + URANIUM_PATH)
execfile(os.path.realpath(URANIUM_PATH))
elif cached_standalone is not None:
exec(cached_standalone)
else:
print("Downloading uranium from " + URANIUM_STANDALONE_URL)
try:
from urllib2 import urlopen as urlopen
except:
from urllib.request import urlopen as urlopen
print("loading uranium bootstrapper...")
body = urlopen(URANIUM_STANDALONE_URL).read()
print("caching standalone uranium script...")
store_cached_standalone(body)
exec(body)