forked from steinwurf/cpuid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
67 lines (53 loc) · 1.6 KB
/
config.py
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
#!/usr/bin/env python
# encoding: utf-8
import traceback
import sys
try:
input = raw_input
except NameError:
pass
project_name = 'cpuid'
project_dependencies = \
[
'waf-tools',
'gtest',
'boost',
'platform',
]
def importCode(code, name, add_to_sys_modules=0):
"""
Import dynamically generated code as a module.
Python recipe from http://code.activestate.com/recipes/82234
"""
import imp
module = imp.new_module(name)
exec(code, module.__dict__)
if add_to_sys_modules:
sys.modules[name] = module
return module
if __name__ == '__main__':
print('Updating Smart Project Config Tool...')
url = "https://raw.github.com/steinwurf/steinwurf-labs/" \
"master/config_helper/config-impl.py"
try:
from urllib.request import urlopen, Request
except ImportError:
from urllib2 import urlopen, Request
try:
# Fetch the code file from the given url
req = Request(url)
response = urlopen(req)
code = response.read()
print("Update complete. Code size: {}\n".format(len(code)))
try:
# Import the code string as a module
mod = importCode(code, "config_helper")
# Run the actual config tool from the dynamic module
mod.config_tool(project_dependencies, project_name)
except:
print("Unexpected error:")
print(traceback.format_exc())
except Exception as e:
print("Could not fetch code file from:\n\t{}".format(url))
print(e)
input('Press ENTER to exit...')