Spotter-VM/basic/srv/vm/mgr/config.py

25 lines
535 B
Python
Raw Normal View History

2018-10-21 10:09:02 +02:00
# -*- coding: utf-8 -*-
import json
from threading import Lock
2018-10-21 10:09:02 +02:00
CONF_FILE = '/srv/vm/config.json'
class Config:
def __init__(self):
self.lock = Lock()
self.load()
def load(self):
with self.lock:
2018-10-28 18:19:45 +01:00
with open(CONF_FILE, 'r') as f:
self.data = json.load(f)
2018-10-21 10:09:02 +02:00
def save(self):
with self.lock:
2018-10-28 18:19:45 +01:00
with open(CONF_FILE, 'w') as f:
json.dump(self.data, f, sort_keys=True, indent=4)
2018-10-21 10:09:02 +02:00
def __getitem__(self, attr):
return self.data[attr]