Change configuration file format
[archipelago] / xseg / tools / archipelago / archipelago / common.py
index 0823bd2..57c28f4 100755 (executable)
@@ -53,6 +53,7 @@ from collections import namedtuple
 import socket
 import random
 from select import select
+import ConfigParser
 
 random.seed()
 hostname = socket.gethostname()
@@ -656,15 +657,65 @@ def exclusive(get_port=False):
         return lock
     return wrap
 
+def createBDict(cfg, section):
+       sec_dic = {}
+       sec_dic['portno_start'] = cfg.getint(section, 'portno_start')
+       sec_dic['portno_end'] = cfg.getint(section, 'portno_end')
+       sec_dic['log_level'] = cfg.getint(section, 'log_level')
+       sec_dic['nr_ops'] = cfg.getint(section, 'nr_ops')
+       try:
+               sec_dic['nr_threads'] = cfg.getint(section, 'nr_threads')
+               sec_dic['archip_dir'] = cfg.get(section, 'archip_dir')
+               sec_dic['fdcache'] = cfg.getint(section, 'fdcache')
+       except:
+               sec_dic['pool'] = cfg.get(section, 'pool')
+       return sec_dic
+
+def createMDict(cfg, section):
+       sec_dic = {}
+       sec_dic['portno_start'] = cfg.getint(section, 'portno_start')
+       sec_dic['portno_end'] = cfg.getint(section, 'portno_end')
+       sec_dic['log_level'] = cfg.getint(section, 'log_level')
+       sec_dic['nr_ops'] = cfg.getint(section, 'nr_ops')
+       sec_dic['blockerb_port'] = cfg.getint(section, 'blockerb_port')
+       sec_dic['blockerm_port'] = cfg.getint(section, 'blockerm_port')
+       return sec_dic
+
+def createVDict(cfg, section):
+       sec_dic = {}
+       sec_dic['portno_start'] = cfg.getint(section, 'portno_start')
+       sec_dic['portno_end'] = cfg.getint(section, 'portno_end')
+       sec_dic['log_level'] = cfg.getint(section, 'log_level')
+       sec_dic['nr_ops'] = cfg.getint(section, 'nr_ops')
+       sec_dic['blocker_port'] = cfg.getint(section, 'blocker_port')
+       sec_dic['mapper_port'] = cfg.getint(section, 'mapper_port')
+       return sec_dic
+
+
 def loadrc(rc):
     try:
         if rc is None:
-            execfile(os.path.expanduser(DEFAULTS), config)
+           cfg_dir = os.path.expanduser(DEFAULTS)
         else:
-            execfile(rc, config)
+           cfg_dir = rc
+       cfg_fd = open(cfg_dir)
     except:
         raise Error("Cannot read config file")
 
+    cfg = ConfigParser.ConfigParser()
+    cfg.readfp(cfg_fd)
+    config['SEGMENT_PORTS'] = cfg.getint('XSEG','SEGMENT_PORTS')
+    config['SEGMENT_SIZE'] = cfg.getint('XSEG','SEGMENT_SIZE')
+    config['XSEGBD_START'] = cfg.getint('XSEG','XSEGBD_START')
+    config['XSEGBD_END'] = cfg.getint('XSEG','XSEGBD_END')
+    config['VTOOL_START'] = cfg.getint('XSEG','VTOOL_START')
+    config['VTOOL_END'] = cfg.getint('XSEG','VTOOL_END')
+    config['roles'] = eval(cfg.get('ROLES','order'))
+    config['blockerb'] = createBDict(cfg, 'BLOCKERB')
+    config['blockerm'] = createBDict(cfg, 'BLOCKERM')
+    config['mapperd'] = createMDict(cfg, 'MAPPERD')
+    config['vlmcd'] = createVDict(cfg, 'VLMCD')
+
     if not check_conf():
         raise Error("Invalid conf file")