-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigurations.py
More file actions
33 lines (24 loc) · 799 Bytes
/
configurations.py
File metadata and controls
33 lines (24 loc) · 799 Bytes
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
class DynamicConfiguration:
def __init__(self, cls, args, _):
pass
@classmethod
def load_configuration(cls):
with open("configuration.json", "r") as conf:
cls.__configuration = json.loads(conf.read())
@classmethod
def save_configuration(cls):
with open("configuration.json", "w") as conf:
conf.write(json.dumps(cls.__configuration))
@classmethod
def __getattr__(cls, key):
if key not in cls.__configuration:
return None
return cls.__configuration[key]
@classmethod
def __setattr__(cls, key, value):
cls.__configuration[key] = value
class Configuration(metaclass=DynamicConfiguration):
__configuration = None