diff src/tools/memory.py @ 365:efbfccfed623

core: local_dir moved to config file - ~/.sat.conf added to potential config file location - removed useless profile param from getConfig
author Goffi <goffi@goffi.org>
date Sat, 18 Jun 2011 17:56:59 +0200
parents 312ca6f9d84a
children e83d0c21d64d
line wrap: on
line diff
--- a/src/tools/memory.py	Sat Jun 18 16:22:50 2011 +0200
+++ b/src/tools/memory.py	Sat Jun 18 17:56:59 2011 +0200
@@ -409,14 +409,18 @@
     def parseMainConf(self):
         """look for main .ini configuration file, and parse it"""
         _config = SafeConfigParser(defaults=default_config)
-        _config.read(['/etc/sat.conf', os.path.expanduser('~/sat.conf'), 'sat.conf'])
+        try:
+            _config.read(map(os.path.expanduser, ['/etc/sat.conf', '~/sat.conf', '~/.sat.conf', '.sat.conf']))
+        except:
+            error (_("Can't read main config !"))
+
         return _config
 
-    def getConfig(self, section, name, profile):
+    def getConfig(self, section, name):
         """Get the main configuration option
         @param section: section of the config file (None or '' for DEFAULT)
         @param name: name of the option
-        @param profile: %(doc_profile_key)s"""
+        """
         if not section:
             section='DEFAULT'
         try:
@@ -428,13 +432,13 @@
 
     def load(self):
         """Load parameters and all memory things from file/db"""
-        param_file_xml = os.path.expanduser(self.host.get_const('local_dir')+
+        param_file_xml = os.path.expanduser(self.getConfig('','local_dir')+
                                         self.host.get_const('savefile_param_xml'))
-        param_file_data = os.path.expanduser(self.host.get_const('local_dir')+
+        param_file_data = os.path.expanduser(self.getConfig('','local_dir')+
                                         self.host.get_const('savefile_param_data'))
-        history_file = os.path.expanduser(self.host.get_const('local_dir')+
+        history_file = os.path.expanduser(self.getConfig('','local_dir')+
                                         self.host.get_const('savefile_history'))
-        private_file = os.path.expanduser(self.host.get_const('local_dir')+
+        private_file = os.path.expanduser(self.getConfig('','local_dir')+
                                         self.host.get_const('savefile_private'))
 
         #parameters
@@ -476,13 +480,13 @@
     def save(self):
         """Save parameters and all memory things to file/db"""
         #TODO: need to encrypt files (at least passwords !) and set permissions
-        param_file_xml = os.path.expanduser(self.host.get_const('local_dir')+
+        param_file_xml = os.path.expanduser(self.getConfig('','local_dir')+
                                         self.host.get_const('savefile_param_xml'))
-        param_file_data = os.path.expanduser(self.host.get_const('local_dir')+
+        param_file_data = os.path.expanduser(self.getConfig('','local_dir')+
                                         self.host.get_const('savefile_param_data'))
-        history_file = os.path.expanduser(self.host.get_const('local_dir')+
+        history_file = os.path.expanduser(self.getConfig('','local_dir')+
                                         self.host.get_const('savefile_history'))
-        private_file = os.path.expanduser(self.host.get_const('local_dir')+
+        private_file = os.path.expanduser(self.getConfig('','local_dir')+
                                         self.host.get_const('savefile_private'))
         
         self.params.save_xml(param_file_xml)