fix bug in save() and simplify it. Add get_doc() method

This commit is contained in:
sqlcoder 2009-11-24 19:46:57 +00:00
parent 6eba4a5544
commit c856824145

View File

@ -516,6 +516,9 @@ class Config:
file = None file = None
return file return file
def get_doc(self):
return self.doc
def get_site_node(self, site): def get_site_node(self, site):
for site_node in self.doc.getElementsByTagName("site"): for site_node in self.doc.getElementsByTagName("site"):
if site_node.getAttribute("site_name") == site: if site_node.getAttribute("site_name") == site:
@ -550,11 +553,9 @@ class Config:
return location_node return location_node
def save(self, file = None): def save(self, file = None):
if file is not None: if file is None:
with open(file, 'w') as f: file = self.file
self.doc.writexml(f) shutil.move(file, file+".backup")
else:
shutil.move(self.file, self.file+".backup")
with open(file, 'w') as f: with open(file, 'w') as f:
self.doc.writexml(f) self.doc.writexml(f)