Commit 7dbb48a6 authored by Jelte Jansen's avatar Jelte Jansen
Browse files

data path correction


git-svn-id: svn://bind10.isc.org/svn/bind10/branches/parkinglot@694 e5f2f494-b856-4b98-b285-d166d9295462
parent 3e366ab1
......@@ -6,6 +6,15 @@ from cfgmgr import ConfigManager
import signal
import os
# If B10_FROM_SOURCE is set in the environment, we use data files
# from a directory relative to that, otherwise we use the ones
# installed on the system
if "B10_FROM_SOURCE" in os.environ:
DATA_PATH = os.environ["B10_FROM_SOURCE"]
else:
PREFIX = "@prefix@"
DATA_PATH = "@localstatedir@/@PACKAGE@".replace("${prefix}", PREFIX)
cm = None
def signal_handler(signal, frame):
......@@ -15,7 +24,7 @@ def signal_handler(signal, frame):
if __name__ == "__main__":
try:
cm = ConfigManager()
cm = ConfigManager(DATA_PATH)
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
cm.read_config()
......
......@@ -5,31 +5,23 @@ import pprint
import os
from ISC.CC import data
# If B10_FROM_SOURCE is set in the environment, we use data files
# from a directory relative to that, otherwise we use the ones
# installed on the system
if "B10_FROM_SOURCE" in os.environ:
DATA_PATH = os.environ["B10_FROM_SOURCE"]
else:
PREFIX = "@prefix@"
DATA_PATH = "@localstatedir@/@PACKAGE@".replace("${prefix}", PREFIX)
class ConfigManagerData:
CONFIG_VERSION = 1
DB_FILENAME = DATA_PATH + "/b10-config.db"
def __init__(self):
def __init__(self, data_path):
self.data = {}
self.data['version'] = ConfigManagerData.CONFIG_VERSION
self.data_path = data_path
self.db_filename = data_path + "/b10-config.db"
def set_data_definition(self, module_name, module_data_definition):
self.zones[module_name] = module_data_definition
self.data_definitions[module_name] = module_data_definition
def read_from_file():
config = ConfigManagerData()
def read_from_file(data_path):
config = ConfigManagerData(data_path)
try:
file = open(self.DB_FILENAME, 'r')
file = open(self.db_filename, 'r')
file_config = ast.literal_eval(file.read())
if 'version' in file_config and \
file_config['version'] == ConfigManagerData.CONFIG_VERSION:
......@@ -49,22 +41,23 @@ class ConfigManagerData:
def write_to_file(self):
try:
tmp_filename = self.DB_FILENAME + ".tmp"
tmp_filename = self.db_filename + ".tmp"
file = open(tmp_filename, 'w');
pp = pprint.PrettyPrinter(indent=4)
s = pp.pformat(self.data)
file.write(s)
file.write("\n")
file.close()
os.rename(tmp_filename, self.DB_FILENAME)
os.rename(tmp_filename, self.db_filename)
except IOError as ioe:
print("Unable to write config file; configuration not stored")
class ConfigManager:
def __init__(self):
def __init__(self, data_path):
self.commands = {}
self.data_definitions = {}
self.config = ConfigManagerData()
self.data_path = data_path
self.config = ConfigManagerData(data_path)
self.cc = ISC.CC.Session()
self.cc.group_subscribe("ConfigManager")
self.cc.group_subscribe("Boss", "ConfigManager")
......@@ -87,7 +80,7 @@ class ConfigManager:
def read_config(self):
print("Reading config")
self.config = ConfigManagerData.read_from_file()
self.config = ConfigManagerData.read_from_file(self.data_path)
def write_config(self):
print("Writing config")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment