Browse Source

corrections

prieto 9 years ago
parent
commit
c887008dc3
1 changed files with 30 additions and 24 deletions
  1. 30
    24
      lodel/settings/settings_loader.py

+ 30
- 24
lodel/settings/settings_loader.py View File

@@ -6,6 +6,7 @@ import copy
6 6
 
7 7
 from lodel.settings.utils import *
8 8
 
9
+   
9 10
 ## @brief Merges and loads configuration files
10 11
 class SettingsLoader(object):
11 12
     ## @brief Constructor
@@ -26,21 +27,24 @@ class SettingsLoader(object):
26 27
         dir_conf = os.open(self.__conf_path, os.O_RDONLY)
27 28
  
28 29
         l = glob.glob(self.__conf_path+'/*.ini')  
30
+
29 31
         for f in l:  
30 32
             config.read(f)
31
-            for s in config:
32
-                if s in conf:
33
-                    for vs in config[s]:
34
-                        if vs not in conf[s]: 
35
-                            conf[s].update({vs:config[s][vs]})
36
-                        else:
37
-                             print(vs) #raise SettingsError("Key attribute already define : %s" % s + ' '+vs + ' ' + str(conf[s]))                        
38
-                else:
39
-                    opts={}
40
-                    for key in config[s]:
41
-                        opts[key] = config[s].get(key)
42
-                    conf.update({s: opts})
43
-                self.__conf_sv.add(str({s: opts}))
33
+        for s in config:
34
+            if s in conf:
35
+                for vs in config[s]:
36
+                    if vs not in conf[s]: 
37
+                        conf[s][vs] = config[s][vs]
38
+                        if s != 'DEFAULT': self.__conf_sv.add(s + ':' + vs)
39
+                    else:
40
+                        raise SettingsError("Key attribute already define : %s" % s + ' '+vs + ' ' + str(conf[s]))                        
41
+            else:
42
+                opts={}
43
+                for key in config[s]:
44
+                    opts[key] = config[s].get(key)
45
+                    if s != 'DEFAULT': self.__conf_sv.add(s + ':' + key)
46
+                conf.update({s: opts})
47
+        print(self.__conf_sv)
44 48
         os.close(dir_conf)
45 49
         return conf
46 50
         
@@ -54,15 +58,17 @@ class SettingsLoader(object):
54 58
     # @param mandatory bool
55 59
     # @return the option
56 60
     def getoption(self,section,keyname,validator,default_value=None,mandatory=False):
57
-        if keyname in section:
58
-            option=validator(section[keyname].split(','))
59
-            self.conf_save.remove(section[keyname])
60
-            return section[keyname]
61
-        elif default_value is not None:
62
-            return section[default_value]
63
-        elif mandatory is True:
64
-            raise SettingsError("Default value mandatory for option %s" % keyname)
65
-        return None
61
+        conf=copy.copy(self.__conf)
62
+        sec=conf[section]
63
+        if keyname in sec:
64
+            optionstr=sec[keyname]
65
+            option=validator(sec[keyname])
66
+            self.__conf_sv.remove(section + ':' + keyname)
67
+            return option
68
+        elif mandatory:
69
+             raise SettingsError("Default value mandatory for option %s" % keyname)
70
+        else:
71
+             return default_value
66 72
                               
67 73
     
68 74
     ## @brief Returns the section to be configured
@@ -75,10 +81,10 @@ class SettingsLoader(object):
75 81
             return conf[section_prefix]
76 82
         elif default_section in conf: 
77 83
             return conf[default_section]
78
-        return None;
84
+        return [];
79 85
     
80 86
     ## @brief Returns the sections which have not been configured
81 87
     # @return list of missing options
82 88
     def getremains(self):
83
-        return list(self.conf_save)
89
+        return list(self.__conf_sv)
84 90
         

Loading…
Cancel
Save