2018-10-21 10:09:02 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import json
|
2018-10-30 23:59:59 +01:00
|
|
|
from threading import Lock
|
2018-10-21 10:09:02 +02:00
|
|
|
|
|
|
|
CONF_FILE = '/srv/vm/config.json'
|
|
|
|
|
|
|
|
class Config:
|
|
|
|
def __init__(self):
|
2018-10-30 23:59:59 +01:00
|
|
|
self.lock = Lock()
|
2018-10-21 11:04:48 +02:00
|
|
|
self.load()
|
|
|
|
|
|
|
|
def load(self):
|
2018-10-30 23:59:59 +01:00
|
|
|
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):
|
2018-10-30 23:59:59 +01:00
|
|
|
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]
|