astyle/config.py

65 lines
1.5 KiB
Python
Raw Normal View History

2016-09-16 23:07:49 +02:00
#!/usr/bin/env python
# encoding: utf-8
import traceback
import sys
2017-04-01 00:17:31 +02:00
try:
input = raw_input
except NameError:
pass
2016-09-16 23:07:49 +02:00
project_name = 'astyle'
project_dependencies = \
[
'waf-tools',
]
def importCode(code, name, add_to_sys_modules=0):
"""
2017-04-01 00:17:31 +02:00
Import dynamically generated code as a module.
Python recipe from http://code.activestate.com/recipes/82234
2016-09-16 23:07:49 +02:00
"""
import imp
module = imp.new_module(name)
2017-04-01 00:17:31 +02:00
exec(code, module.__dict__)
2016-09-16 23:07:49 +02:00
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"
2017-04-01 00:17:31 +02:00
try:
from urllib.request import urlopen, Request
except ImportError:
from urllib2 import urlopen, Request
2016-09-16 23:07:49 +02:00
try:
# Fetch the code file from the given url
2017-04-01 00:17:31 +02:00
req = Request(url)
response = urlopen(req)
2016-09-16 23:07:49 +02:00
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
2017-04-01 00:17:31 +02:00
mod.config_tool(project_dependencies, project_name)
2016-09-16 23:07:49 +02:00
except:
print("Unexpected error:")
2017-04-01 00:17:31 +02:00
print(traceback.format_exc())
2016-09-16 23:07:49 +02:00
except Exception as e:
print("Could not fetch code file from:\n\t{}".format(url))
print(e)
2017-04-01 00:17:31 +02:00
input('Press ENTER to exit...')