comparison src/memory/memory.py @ 729:8f50a0079769

core: management of _list and _dict in sat.conf
author Goffi <goffi@goffi.org>
date Thu, 12 Dec 2013 01:06:19 +0100
parents e07afabc4a25
children 03744d9ebc13
comparison
equal deleted inserted replaced
728:e07afabc4a25 729:8f50a0079769
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 from __future__ import with_statement 20 from __future__ import with_statement
21 21
22 import os.path 22 import os.path
23 import csv
23 from ConfigParser import SafeConfigParser, NoOptionError, NoSectionError 24 from ConfigParser import SafeConfigParser, NoOptionError, NoSectionError
24 from xml.dom import minidom 25 from xml.dom import minidom
25 from logging import debug, info, warning, error 26 from logging import debug, info, warning, error
26 from twisted.internet import defer 27 from twisted.internet import defer
27 from twisted.words.protocols.jabber import jid 28 from twisted.words.protocols.jabber import jid
649 @param name: name of the option 650 @param name: name of the option
650 """ 651 """
651 if not section: 652 if not section:
652 section = 'DEFAULT' 653 section = 'DEFAULT'
653 try: 654 try:
654 _value = self.config.get(section, name) 655 value = self.config.get(section, name)
655 except (NoOptionError, NoSectionError): 656 except (NoOptionError, NoSectionError):
656 _value = '' 657 value = ''
657 658
658 return os.path.expanduser(_value) if name.endswith('_path') or name.endswith('_dir') else _value 659 if name.endswith('_path') or name.endswith('_dir'):
660 value = os.path.expanduser(value)
661 # thx to Brian (http://stackoverflow.com/questions/186857/splitting-a-semicolon-separated-string-to-a-dictionary-in-python/186873#186873)
662 elif name.endswith('_list'):
663 value = csv.reader([value], delimiter=',', quotechar='"').next()
664 elif name.endswith('_dict'):
665 value = dict(csv.reader([item], delimiter=':', quotechar='"').next()
666 for item in csv.reader([value], delimiter=',', quotechar='"').next())
667 return value
659 668
660 def load_xml(self, filename): 669 def load_xml(self, filename):
661 """Load parameters template from xml file""" 670 """Load parameters template from xml file"""
662 if filename is None: 671 if filename is None:
663 return False 672 return False