configfile.py

changeset 118
dbf49689af0d
parent 76
a2fe9ba3041a
child 124
7b2cd8b1ba86
equal deleted inserted replaced
117:6c0609395889 118:dbf49689af0d
24 return self.obj[key] 24 return self.obj[key]
25 25
26 def set_value (self, key, value): 26 def set_value (self, key, value):
27 self.obj[key] = value 27 self.obj[key] = value
28 self.save() 28 self.save()
29
30 def append_value (self, key, value):
31 if key not in self.obj:
32 self.obj[key] = []
33
34 self.obj[key].append (value)
35 self.save()
29 36
30 def get_node (self, key): 37 def get_node (self, key):
31 return ConfigNode (obj=self.get_value (key, {}), name=self.keyname (key), parent=self) 38 return ConfigNode (obj=self.get_value (key, {}), name=self.keyname (key), parent=self)
32 39
33 def get_nodelist (self, key): 40 def get_nodelist (self, key, default=None):
34 data = self.get_value (key) 41 data = self.get_value (key, default)
35 result = [] 42 result = []
36 43
37 for entry in data: 44 for entry in data:
38 node = ConfigNode (obj=entry, name=self.keyname (key), parent=self) 45 node = ConfigNode (obj=entry, name=self.keyname (key), parent=self)
39 result.append (node) 46 result.append (node)
40 47
41 return result 48 return result
49
50 def has_node (self, key):
51 return key in self.obj
42 52
43 def append_nodelist (self, key): 53 def append_nodelist (self, key):
44 data = self.get_value (key) 54 data = self.get_value (key, [])
45 obj = {} 55 obj = {}
46 data.append (obj) 56 data.append (obj)
47 return ConfigNode (obj=obj, name=self.keyname (key), parent=self) 57 return ConfigNode (obj=obj, name=self.keyname (key), parent=self)
48 58
49 def save (self): 59 def save (self):

mercurial