Debian Codegraph @

uranium

raw
1 #!/usr/bin/env python
2 # warmup should be added into everyone's root level repository. warmup will:
3 # * download and set up a virtualenv
4 # * install uranium
5 # * run uranium
6 import os
7
8 ROOT = os.path.dirname(__file__)
9 URANIUM_PATH = os.getenv('URANIUM_PATH', None)
10 URANIUM_GITHUB_ACCOUNT = os.getenv('URANIUM_GITHUB_ACCOUNT', 'toumorokoshi')
11 URANIUM_GITHUB_BRANCH = os.getenv('URANIUM_GITHUB_BRANCH', 'master')
12 URANIUM_STANDALONE_URL = "https://raw.githubusercontent.com/{account}/uranium/{branch}/uranium/scripts/uranium_standalone".format(account=URANIUM_GITHUB_ACCOUNT, branch=URANIUM_GITHUB_BRANCH)
13 CACHE_DIRECTORY = os.path.join(ROOT, ".uranium")
14 CACHED_URANIUM_STANDALONE = os.path.join(CACHE_DIRECTORY, "uranium_standalone")
15
16
17 def get_cached_standalone():
18 if not os.path.isfile(CACHED_URANIUM_STANDALONE):
19 return None
20 with open(CACHED_URANIUM_STANDALONE) as fh:
21 return fh.read()
22
23
24 def store_cached_standalone(body):
25 if not os.path.exists(CACHE_DIRECTORY):
26 os.makedirs(CACHE_DIRECTORY)
27 with open(CACHED_URANIUM_STANDALONE, "wb+") as fh:
28 fh.write(body)
29
30 cached_standalone = get_cached_standalone()
31
32 if URANIUM_PATH is not None:
33 print("Executing uranium from " + URANIUM_PATH)
34 execfile(os.path.realpath(URANIUM_PATH))
35 elif cached_standalone is not None:
36 exec(cached_standalone)
37 else:
38 print("Downloading uranium from " + URANIUM_STANDALONE_URL)
39 try:
40 from urllib2 import urlopen as urlopen
41 except:
42 from urllib.request import urlopen as urlopen
43
44 print("loading uranium bootstrapper...")
45 body = urlopen(URANIUM_STANDALONE_URL).read()
46 print("caching standalone uranium script...")
47 store_cached_standalone(body)
48 exec(body)