vmmgr/mgr/config.py

25 lines
535 B
Python
Raw Normal View History

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