##// END OF EJS Templates
config: add %unset name support
Matt Mackall -
r8184:9189afe1 default
parent child Browse files
Show More
@@ -2,7 +2,7 b' from i18n import _'
2 import re, error, os
2 import re, error, os
3
3
4 class sortdict(dict):
4 class sortdict(dict):
5 'a simple append-only sorted dictionary'
5 'a simple sorted dictionary'
6 def __init__(self, data=None):
6 def __init__(self, data=None):
7 self._list = []
7 self._list = []
8 if data:
8 if data:
@@ -23,6 +23,9 b' class sortdict(dict):'
23 self[k] = src[k]
23 self[k] = src[k]
24 def items(self):
24 def items(self):
25 return [(k,self[k]) for k in self._list]
25 return [(k,self[k]) for k in self._list]
26 def __delitem__(self, key):
27 dict.__delitem__(self, key)
28 self._list.remove(key)
26
29
27 class config:
30 class config:
28 def __init__(self, data=None):
31 def __init__(self, data=None):
@@ -62,6 +65,7 b' class config:'
62 itemre = re.compile(r'([^=\s]+)\s*=\s*(.*)')
65 itemre = re.compile(r'([^=\s]+)\s*=\s*(.*)')
63 contre = re.compile(r'\s+(\S.*)')
66 contre = re.compile(r'\s+(\S.*)')
64 emptyre = re.compile(r'(;|#|\s*$)')
67 emptyre = re.compile(r'(;|#|\s*$)')
68 unsetre = re.compile(r'%unset\s+(\S.*)')
65 includere = re.compile(r'%include\s+(\S.*)')
69 includere = re.compile(r'%include\s+(\S.*)')
66 section = ""
70 section = ""
67 item = None
71 item = None
@@ -102,5 +106,12 b' class config:'
102 self.set(section, item, m.group(2), "%s:%d" % (path, line))
106 self.set(section, item, m.group(2), "%s:%d" % (path, line))
103 cont = 1
107 cont = 1
104 continue
108 continue
109 m = unsetre.match(l)
110 if m:
111 name = m.group(1)
112 if self.get(section, name) != None:
113 del self._data[section][name]
114 continue
115
105 raise error.ConfigError(_('config error at %s:%d: \'%s\'')
116 raise error.ConfigError(_('config error at %s:%d: \'%s\'')
106 % (path, line, l.rstrip()))
117 % (path, line, l.rstrip()))
General Comments 0
You need to be logged in to leave comments. Login now