##// END OF EJS Templates
config: split source data out into separate map
Matt Mackall -
r8185:dc10a7a3 default
parent child Browse files
Show More
@@ -30,9 +30,11 b' class sortdict(dict):'
30 class config:
30 class config:
31 def __init__(self, data=None):
31 def __init__(self, data=None):
32 self._data = {}
32 self._data = {}
33 self._source = {}
33 if data:
34 if data:
34 for k in data._data:
35 for k in data._data:
35 self._data[k] = data[k].copy()
36 self._data[k] = data[k].copy()
37 self._source = data._source.copy()
36 def copy(self):
38 def copy(self):
37 return config(self)
39 return config(self)
38 def __contains__(self, section):
40 def __contains__(self, section):
@@ -47,18 +49,20 b' class config:'
47 self._data[s] = sortdict()
49 self._data[s] = sortdict()
48 for k in src._data[s]:
50 for k in src._data[s]:
49 self._data[s][k] = src._data[s][k]
51 self._data[s][k] = src._data[s][k]
52 self._source[(s, k)] = src._source[(s, k)]
50 def get(self, section, item, default=None):
53 def get(self, section, item, default=None):
51 return self._data.get(section, {}).get(item, (default, ""))[0]
54 return self._data.get(section, {}).get(item, default)
52 def getsource(self, section, item):
55 def getsource(self, section, item):
53 return self._data.get(section, {}).get(item, (None, ""))[1]
56 return self._source.get((section, item), "")
54 def sections(self):
57 def sections(self):
55 return sorted(self._data.keys())
58 return sorted(self._data.keys())
56 def items(self, section):
59 def items(self, section):
57 return [(k, v[0]) for k,v in self._data.get(section, {}).items()]
60 return self._data.get(section, {}).items()
58 def set(self, section, item, value, source=""):
61 def set(self, section, item, value, source=""):
59 if section not in self:
62 if section not in self:
60 self._data[section] = sortdict()
63 self._data[section] = sortdict()
61 self._data[section][item] = (value, source)
64 self._data[section][item] = value
65 self._source[(section, item)] = source
62
66
63 def read(self, path, fp=None):
67 def read(self, path, fp=None):
64 sectionre = re.compile(r'\[([^\[]+)\]')
68 sectionre = re.compile(r'\[([^\[]+)\]')
General Comments 0
You need to be logged in to leave comments. Login now