forked from IITC-CE/ingress-intel-total-conversion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.py
executable file
·82 lines (65 loc) · 2.56 KB
/
settings.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python3
"""Module to get settings for given iitc build name.
Defaults are taken from buildsettings.py, and extended with
values from localbuildsettings.py (if exists).
"""
import time
_build_date = None
_build_timestamp = None
def generate_timestamps():
"""Generate build date and timestamp in desired formats."""
global _build_date, _build_timestamp
utc = time.gmtime()
_build_date = time.strftime('%Y-%m-%d-%H%M%S', utc)
_build_timestamp = time.strftime('%Y%m%d.%H%M%S', utc)
def load(build_name, localfile=None):
"""Load settings for given iitc build name."""
import buildsettings as config
from pathlib import Path
from runpy import run_path
try:
localsettings = run_path(localfile or config.localfile)
except FileNotFoundError:
if localfile: # ignore for default file
raise # but raise for explicitely specified
localfile = None
else:
localfile = localfile or config.localfile
config.defaults.update(localsettings.get('defaults', {}))
config.builds.update(localsettings.get('builds', {}))
config.default_build = localsettings.get('default_build', None)
build_name = build_name or config.default_build
if not build_name:
raise ValueError('build name not specified')
if build_name not in config.builds:
raise ValueError(
'name not found in settings: {0}\n'
'(available build names: {1})'
.format(build_name, ', '.join(config.builds.keys())),
)
mod = vars(__import__(__name__))
mod.pop('load')
mod['build_name'] = build_name
mod['build_date'] = lambda: _build_date
mod['build_timestamp'] = lambda: _build_timestamp
base = Path(localfile or __file__).parent
mod['build_source_dir'] = base
mod['build_target_dir'] = base / 'build' / build_name
mod.update(config.defaults)
mod.update(config.builds[build_name])
mod['localfile'] = Path(localfile) if localfile else None
if __name__ == '__main__':
import argparse
from pprint import pprint
import settings
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('build', type=str, nargs='?',
help='Specify build name')
args = parser.parse_args()
try:
settings.load(args.build)
except ValueError as err:
parser.error(err)
print('settings for build: {.build_name}'.format(settings))
pprint({key: value for key, value in vars(settings).items()
if not key.startswith('__')}) # skip private attributes