# vim: sw=4 ts=4 expandtab ai
import gtk
+from configobj import ConfigObj
+from validate import Validator
class Config_Control(object):
def __init__(self):
- self.config = Config_Abstraction('findit.cfg')
+ self.config = Config_Abstraction('findit.ini', 'config_spec.ini')
#conf_ui = Config_Presentation()
def get(self, param):
class Config_Abstraction(object):
- def __init__(self, config_file):
- self.load_config(config_file)
+ def __init__(self, config_file, config_spec_file):
+ self.load_config(config_file, config_spec_file)
def get_val(self, param):
return self.conf[param]
def set_val(self, param, value):
self.conf[param] = value
- def load_config(self, config_file):
- # Здесь планируется загрузка конфига из файла - пока так присваивается
- self.conf = {}
- self.conf['default_start_dir'] = '/home/alex/Desktop/python/test/'
- self.conf['default_count'] = 10
- self.conf['ignore_dir_list'] = ['/dev', '/proc', '/sys', '/mnt']
- self.conf['window_width'] = 575
- self.conf['window_height'] = 345
-
- def save_config(self, config_file):
- pass
+ def load_config(self, config_file, config_spec_file):
+ self.conf = ConfigObj(config_file, configspec=config_spec_file)
+ val = Validator()
+ test = self.conf.validate(val)
+ if not test:
+ print 'Failed Load Config File'
+ def save_config(self, config_file=None):
+ if config_file:
+ self.conf.filename = config_file
+ self.conf.write()
class Config_Presentation(gtk.Window):
def __init__(self):
def run(self):
self.show_all()
gtk.main()
+
+
+if __name__ == '__main__':
+ cfg = Config_Control()
+ #cfg.config.set_val('default_pkg_count',15)
+ print cfg.config.conf
+ print cfg.get('window_width'), type(cfg.get('window_width'))
+ cfg.config.save_config()