-
Notifications
You must be signed in to change notification settings - Fork 40
/
flags.py
35 lines (23 loc) · 680 Bytes
/
flags.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
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import os
import yaml
import collections
def dict_to_namedtuple(d):
FLAGSTuple = collections.namedtuple('FLAGS', sorted(d.keys()))
for k, v in d.items():
if type(v) is dict:
d[k] = dict_to_namedtuple(v)
elif type(v) is str:
d[k] = v
nt = FLAGSTuple(**d)
return nt
class Flags():
def __init__(self, config_file):
with open(config_file, 'r') as f:
d = yaml.safe_load(f)
self.flags = dict_to_namedtuple(d)
def get(self):
return self.flags