Newer
Older
from collections import OrderedDict
from pathlib import Path
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
def load_conf() -> dict:
conf = {}
base_dir = str(Path(__file__).expanduser().resolve().parent)
files = (
(str(Path(base_dir, "global-conf.sh")), True),
(str(Path(base_dir, "auto-generated-conf.sh")), False),
(str(Path(base_dir, "conf.sh")), False),
)
only_default = True
override = OrderedDict()
for path, is_default in files:
if not Path(path).exists():
if is_default:
return dict()
continue
# Load conf
with open(path, "r") as fo:
content = fo.read()
# Parse conf
for line in content.split("\n"):
line = line.strip()
if line and not line.startswith("#") and "=" in line:
name, *val = line.split("=")
name = name.strip(" \t'\"")
val = ("=".join(val)).strip(" \t'\"")
conf[name] = val
if is_default:
override[name] = False
else:
only_default = False
override[name] = True
conf["_override"] = override
return conf
def get_conf(name: str, default: str = None) -> str:
conf = load_conf()
return conf.get(name, default)
branch = get_conf('ENVSETUP_BRANCH') or 'stable'
os.chdir(os.path.dirname(os.path.abspath(os.path.expanduser(__file__))))
sys.stdout.write('Updating envsetup: ')
sys.stdout.flush()
subprocess.call('find . -name *.pyc -type f -delete', shell=True)
subprocess.call('find . -name __pycache__ -type d -delete', shell=True)
subprocess.check_call(['git', 'fetch', '--recurse-submodules', '--all'])
subprocess.check_call(['git', 'reset', '--hard', 'origin/{}'.format(branch)])
if branch:
subprocess.check_call(['git', 'checkout', branch])
subprocess.check_call(['git', 'pull', '--recurse-submodules'])
subprocess.check_call(['git', 'submodule', 'update', '--init', '--recursive'])
subprocess.call('find . -type d -empty -delete', shell=True)