Author: tmckay Date: 2011-03-22 19:09:02 +0000 (Tue, 22 Mar 2011) New Revision: 4656
Modified: trunk/cumin/bin/cumin trunk/cumin/python/cumin/config.py Log: Add master section for specifying data/web instances
Modified: trunk/cumin/bin/cumin =================================================================== --- trunk/cumin/bin/cumin 2011-03-22 18:21:20 UTC (rev 4655) +++ trunk/cumin/bin/cumin 2011-03-22 19:09:02 UTC (rev 4656) @@ -5,6 +5,7 @@ import os import sys import signal +from cumin.config import *
home = os.environ.get("CUMIN_HOME", os.path.normpath("/usr/share/cumin")) sys.path.append(os.path.join(home, "python")) @@ -33,7 +34,7 @@ return True
def get_args(app, section, init_only, console, extra_options=""): - args = [app, "--section="+section] + args = [app, "--section="+section.strip()] if init_only: args.append("--init-only") if not console: @@ -50,16 +51,19 @@ ARGS = 1 PROG_STRING = 2
+ config = CuminMasterConfig() + values = config.parse().master + parser = OptionParser()
parser.add_option("--init-only", dest="init_only", action="store_true", default=False, help="Check options and initialization, then return.")
- parser.add_option("--webs", dest="webs", default="web", + parser.add_option("--webs", dest="webs", default=values.webs, help="Configuration section names for cumin-web instances."\ "\nEach value implies a separate cumin-web instance.")
- parser.add_option("--datas", dest="datas", default="data", + parser.add_option("--datas", dest="datas", default=values.datas, help="Configuration section names for cumin-data instances."\ "\nEach value implies a separate cumin-data instance.")
Modified: trunk/cumin/python/cumin/config.py =================================================================== --- trunk/cumin/python/cumin/config.py 2011-03-22 18:21:20 UTC (rev 4655) +++ trunk/cumin/python/cumin/config.py 2011-03-22 19:09:02 UTC (rev 4656) @@ -20,39 +20,7 @@ test = CuminConfigSection(self, "test") test.log_file.default = os.path.join(self.home, "log", "test.log")
- def get_home(self): - return self.home - - def parse(self): - paths = list() - - paths.append(os.path.join(os.sep, "etc", "cumin", "cumin.conf")) - paths.append(os.path.join(self.home, "etc", "cumin.conf")) - paths.append(os.path.join(os.path.expanduser("~"), ".cumin.conf")) - - return self.parse_files(paths) - -class CuminCommonConfig(CuminConfig): - ''' - Provide a simple class which just gives access - to the values in the common section of the config - file for apps which do not need any more - ''' - def __init__(self): - super(CuminCommonConfig, self).__init__() - - self.section = CuminConfigSection(self, "common") - - def set_log(self, log): - self.section.log_file.default = log - -class CuminWebConfig(CuminConfig): - def __init__(self, section_name="web", strict_section="False"): - super(CuminWebConfig, self).__init__() - - self.create_section(section_name, strict_section) - - def create_section(self, name, strict_section): + def create_web_section(self, name, strict_section): web = CuminConfigSection(self, name, strict_section) web.log_file.default = os.path.join(self.home, "log", name + ".log")
@@ -84,13 +52,7 @@ param = ConfigParameter(web, "persona", str) param.default = "default"
-class CuminDataConfig(CuminConfig): - def __init__(self, section_name="data", strict_section=False): - super(CuminDataConfig, self).__init__() - - self.create_section(section_name, strict_section) - - def create_section(self, name, strict_section): + def create_data_section(self, name, strict_section): data = CuminConfigSection(self, name, strict_section) data.log_file.default = os.path.join(self.home, "log", name + ".log")
@@ -106,6 +68,63 @@ param = ConfigParameter(data, "vacuum-interval", int) param.default = 60 * 60 # 1 hour
+ def create_master_section(self, name, strict_section): + ''' + Creates a blank master section. + CuminConfigSection values are not interesting to the master + ''' + + master = ConfigSection(self, name, strict_section) + param = ConfigParameter(master, "datas", str) + param.default = "data" + + param = ConfigParameter(master, "webs", str) + param.default = "web" + + def get_home(self): + return self.home + + def parse(self): + paths = list() + + paths.append(os.path.join(os.sep, "etc", "cumin", "cumin.conf")) + paths.append(os.path.join(self.home, "etc", "cumin.conf")) + paths.append(os.path.join(os.path.expanduser("~"), ".cumin.conf")) + + return self.parse_files(paths) + +class CuminCommonConfig(CuminConfig): + ''' + Provide a simple class which just gives access + to the values in the common section of the config + file for apps which do not need any more + ''' + def __init__(self): + super(CuminCommonConfig, self).__init__() + + self.section = CuminConfigSection(self, "common") + + def set_log(self, log): + self.section.log_file.default = log + +class CuminWebConfig(CuminConfig): + def __init__(self, section_name="web", strict_section="False"): + super(CuminWebConfig, self).__init__() + + self.create_web_section(section_name, strict_section) + +class CuminDataConfig(CuminConfig): + def __init__(self, section_name="data", strict_section=False): + super(CuminDataConfig, self).__init__() + + self.create_data_section(section_name, strict_section) + +class CuminMasterConfig(CuminConfig): + def __init__(self, section_name="master", strict_section=False): + super(CuminMasterConfig, self).__init__() + + self.create_master_section(section_name, strict_section) + class CuminConfigSection(ConfigSection): def __init__(self, config, name, strict_section=False): super(CuminConfigSection, self).__init__(config, name, strict_section)