From 2d318c3c0e7a615552e8c5ca103614be0b40eab7 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Thu, 20 Sep 2007 16:22:42 -0400 Subject: Basic config file. Intentionally short. Slowly removing VF code. --- server/config_data.py | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) (limited to 'server/config_data.py') diff --git a/server/config_data.py b/server/config_data.py index 9ccca75..bda7635 100755 --- a/server/config_data.py +++ b/server/config_data.py @@ -16,19 +16,10 @@ from codes import * - import os -import yaml - -CONFIG_FILE = "/etc/virt-factory/settings" - -# from the comments in http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66531 -#class Singleton(object): -# def __new__(type): -# if not '_the_instance' in type.__dict__: -# type._the_instance = object.__new__(type) -# return type._the_instance +import ConfigParser +CONFIG_FILE = "/etc/func/settings" class Config: @@ -40,16 +31,18 @@ class Config: self.__dict__ = self.__shared_state if not self.has_read: self.read() - print "***** CONFIG RELOAD *****" Config.has_read = True def read(self): + if not os.path.exists(CONFIG_FILE): - raise MisconfiguredException(comment="Missing %s" % CONFIG_FILE) - config_file = open(CONFIG_FILE) - data = config_file.read() - self.ds = yaml.load(data).next() - + raise FuncException(comment="Missing %s" % CONFIG_FILE) + + cp = ConfigParser.ConfigParser() + + self.ds["is_master"] = int(cp.get("general","is_master")) + self.ds["is_minion"] = int(cp.get("general","is_minion")) + self.ds["master_server"] = cp.get("general","master") def get(self): return self.ds -- cgit From 7d7c0f4dc299dc342c53341f61ae4643eb134213 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Thu, 20 Sep 2007 16:44:02 -0400 Subject: Remove yaml libraries (configparser is good enough) plus remove references to virt-factory. --- server/config_data.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'server/config_data.py') diff --git a/server/config_data.py b/server/config_data.py index bda7635..46d98ec 100755 --- a/server/config_data.py +++ b/server/config_data.py @@ -1,11 +1,9 @@ #!/usr/bin/python -# Virt-factory backend code. +# func # # Copyright 2006, Red Hat, Inc -# Michael DeHaan -# Scott Seago -# Adrian Likins +# see AUTHORS # # This software may be freely redistributed under the terms of the GNU # general public license. -- cgit From 5b0f3d1e802f4dbdee9b36fa5a526b63dd20f364 Mon Sep 17 00:00:00 2001 From: Adrian Likins Date: Thu, 20 Sep 2007 17:34:30 -0400 Subject: fix up config_data to use ConfigParser correctly --- server/config_data.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'server/config_data.py') diff --git a/server/config_data.py b/server/config_data.py index 46d98ec..b9a4bc8 100755 --- a/server/config_data.py +++ b/server/config_data.py @@ -27,6 +27,7 @@ class Config: def __init__(self): self.__dict__ = self.__shared_state + self.ds = {} if not self.has_read: self.read() Config.has_read = True @@ -38,9 +39,11 @@ class Config: cp = ConfigParser.ConfigParser() + cp.read([CONFIG_FILE]) + self.ds["is_master"] = int(cp.get("general","is_master")) self.ds["is_minion"] = int(cp.get("general","is_minion")) - self.ds["master_server"] = cp.get("general","master") + self.ds["master_server"] = cp.get("general","master_server") def get(self): return self.ds -- cgit From 425f61b97305e9a44d9f31c8a82c633c95f61edc Mon Sep 17 00:00:00 2001 From: James Bowes Date: Thu, 20 Sep 2007 18:27:11 -0400 Subject: Catch FuncException when the config file is missing and exit gracefully --- server/config_data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'server/config_data.py') diff --git a/server/config_data.py b/server/config_data.py index b9a4bc8..7ace8ca 100755 --- a/server/config_data.py +++ b/server/config_data.py @@ -35,7 +35,7 @@ class Config: def read(self): if not os.path.exists(CONFIG_FILE): - raise FuncException(comment="Missing %s" % CONFIG_FILE) + raise FuncException("Missing %s" % CONFIG_FILE) cp = ConfigParser.ConfigParser() -- cgit