comparison martini/config.py @ 11:c77259f467a3

hopefully OrderedDict preservation actually works now
author Jeff Hammel <k0scist@gmail.com>
date Tue, 23 Aug 2016 18:17:11 -0700
parents 66d11212175d
children 4faed08eb8d8
comparison
equal deleted inserted replaced
10:66d11212175d 11:c77259f467a3
24 # assume resource is already a file-like object 24 # assume resource is already a file-like object
25 return resource 25 return resource
26 26
27 if os.path.exists(resource): 27 if os.path.exists(resource):
28 return file(resource) 28 return file(resource)
29 if sum([resource.startswith(http) for http in 'http://', 'https://']): 29 if sum([resource.startswith(http)
30 for http in 'http://', 'https://']):
30 return urllib2.urlopen(resource) 31 return urllib2.urlopen(resource)
31 return StringIO(resource) 32 return StringIO(resource)
32 33
33 34
34 class ConfigMunger(ConfigParser): 35 class ConfigMunger(ConfigParser):
62 def move_section(self, section, newname): 63 def move_section(self, section, newname):
63 if self.has_section(section): 64 if self.has_section(section):
64 _section = self[section] 65 _section = self[section]
65 self.remove_section(section) 66 self.remove_section(section)
66 else: 67 else:
67 _section = {} 68 _section = OrderedDict()
68 self.read({newname: _section}) 69 self.read(OrderedDict(newname=_section))
69 70
70 def dict(self): 71 def dict(self):
71 """return a dictionary of dictionaries; 72 """
73 return a dictionary of dictionaries:
72 the outer with keys of section names; 74 the outer with keys of section names;
73 the inner with keys, values of the section""" 75 the inner with keys, values of the section
76 """
74 return OrderedDict([(section, self[section]) 77 return OrderedDict([(section, self[section])
75 for section in self.sections()]) 78 for section in self.sections()])
76 79
77 def read(self, *ini): 80 def read(self, *ini):
78 for _ini in ini: 81 for _ini in ini: