moved AttrDict cast into static method
This commit is contained in:
parent
a62e7bc6de
commit
0ae5fd12d7
@ -23,17 +23,17 @@ class AttrDict(dict):
|
||||
def __getattr__(self, item):
|
||||
return self.setdefault(item, AttrDict())
|
||||
|
||||
|
||||
def cast_to_ad(d):
|
||||
if not isinstance(d, AttrDict):
|
||||
d = AttrDict(d)
|
||||
for k, v in dict(d.items()).items():
|
||||
if " " in k:
|
||||
del d[k]
|
||||
d[k.replace(" ", "_")] = v
|
||||
if isinstance(v, dict):
|
||||
d[k] = cast_to_ad(v)
|
||||
return d
|
||||
@staticmethod
|
||||
def from_dict_recur(d):
|
||||
if not isinstance(d, AttrDict):
|
||||
d = AttrDict(d)
|
||||
for k, v in dict(d.items()).items():
|
||||
if " " in k:
|
||||
del d[k]
|
||||
d[k.replace(" ", "_")] = v
|
||||
if isinstance(v, dict):
|
||||
d[k] = AttrDict.from_dict_recur(v)
|
||||
return d
|
||||
|
||||
|
||||
def sizeof_fmt(num, suffix='B'):
|
||||
@ -155,7 +155,7 @@ if __name__ == '__main__':
|
||||
file_db = defaultdict(dict)
|
||||
confname = sys.argv[1] if sys.argv[1:] and os.path.isfile(sys.argv[1]) else 'config.yaml'
|
||||
with open(confname) as cf:
|
||||
conf = cast_to_ad(yaml.load(cf))
|
||||
conf = AttrDict.from_dict_recur(yaml.load(cf))
|
||||
if conf.url_hash_len > 31:
|
||||
raise ValueError('url_hash_len can\'t be bigger than 31')
|
||||
if not set(conf.max_filesize.replace(' ', ''))\
|
||||
|
Loading…
Reference in New Issue
Block a user