comparison 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
comparison
equal deleted inserted replaced
364:312ca6f9d84a 365:efbfccfed623
407 self.load() 407 self.load()
408 408
409 def parseMainConf(self): 409 def parseMainConf(self):
410 """look for main .ini configuration file, and parse it""" 410 """look for main .ini configuration file, and parse it"""
411 _config = SafeConfigParser(defaults=default_config) 411 _config = SafeConfigParser(defaults=default_config)
412 _config.read(['/etc/sat.conf', os.path.expanduser('~/sat.conf'), 'sat.conf']) 412 try:
413 _config.read(map(os.path.expanduser, ['/etc/sat.conf', '~/sat.conf', '~/.sat.conf', '.sat.conf']))
414 except:
415 error (_("Can't read main config !"))
416
413 return _config 417 return _config
414 418
415 def getConfig(self, section, name, profile): 419 def getConfig(self, section, name):
416 """Get the main configuration option 420 """Get the main configuration option
417 @param section: section of the config file (None or '' for DEFAULT) 421 @param section: section of the config file (None or '' for DEFAULT)
418 @param name: name of the option 422 @param name: name of the option
419 @param profile: %(doc_profile_key)s""" 423 """
420 if not section: 424 if not section:
421 section='DEFAULT' 425 section='DEFAULT'
422 try: 426 try:
423 _value = self.config.get(section, name) 427 _value = self.config.get(section, name)
424 except NoOptionError, NoSectionError: 428 except NoOptionError, NoSectionError:
426 430
427 return os.path.expanduser(_value) if name.endswith('_path') or name.endswith('_dir') else _value 431 return os.path.expanduser(_value) if name.endswith('_path') or name.endswith('_dir') else _value
428 432
429 def load(self): 433 def load(self):
430 """Load parameters and all memory things from file/db""" 434 """Load parameters and all memory things from file/db"""
431 param_file_xml = os.path.expanduser(self.host.get_const('local_dir')+ 435 param_file_xml = os.path.expanduser(self.getConfig('','local_dir')+
432 self.host.get_const('savefile_param_xml')) 436 self.host.get_const('savefile_param_xml'))
433 param_file_data = os.path.expanduser(self.host.get_const('local_dir')+ 437 param_file_data = os.path.expanduser(self.getConfig('','local_dir')+
434 self.host.get_const('savefile_param_data')) 438 self.host.get_const('savefile_param_data'))
435 history_file = os.path.expanduser(self.host.get_const('local_dir')+ 439 history_file = os.path.expanduser(self.getConfig('','local_dir')+
436 self.host.get_const('savefile_history')) 440 self.host.get_const('savefile_history'))
437 private_file = os.path.expanduser(self.host.get_const('local_dir')+ 441 private_file = os.path.expanduser(self.getConfig('','local_dir')+
438 self.host.get_const('savefile_private')) 442 self.host.get_const('savefile_private'))
439 443
440 #parameters 444 #parameters
441 if os.path.exists(param_file_xml): 445 if os.path.exists(param_file_xml):
442 try: 446 try:
474 error (_("Can't load private values !")) 478 error (_("Can't load private values !"))
475 479
476 def save(self): 480 def save(self):
477 """Save parameters and all memory things to file/db""" 481 """Save parameters and all memory things to file/db"""
478 #TODO: need to encrypt files (at least passwords !) and set permissions 482 #TODO: need to encrypt files (at least passwords !) and set permissions
479 param_file_xml = os.path.expanduser(self.host.get_const('local_dir')+ 483 param_file_xml = os.path.expanduser(self.getConfig('','local_dir')+
480 self.host.get_const('savefile_param_xml')) 484 self.host.get_const('savefile_param_xml'))
481 param_file_data = os.path.expanduser(self.host.get_const('local_dir')+ 485 param_file_data = os.path.expanduser(self.getConfig('','local_dir')+
482 self.host.get_const('savefile_param_data')) 486 self.host.get_const('savefile_param_data'))
483 history_file = os.path.expanduser(self.host.get_const('local_dir')+ 487 history_file = os.path.expanduser(self.getConfig('','local_dir')+
484 self.host.get_const('savefile_history')) 488 self.host.get_const('savefile_history'))
485 private_file = os.path.expanduser(self.host.get_const('local_dir')+ 489 private_file = os.path.expanduser(self.getConfig('','local_dir')+
486 self.host.get_const('savefile_private')) 490 self.host.get_const('savefile_private'))
487 491
488 self.params.save_xml(param_file_xml) 492 self.params.save_xml(param_file_xml)
489 self.params.save_data(param_file_data) 493 self.params.save_data(param_file_data)
490 debug(_("params saved")) 494 debug(_("params saved"))