def _save(self, root, filename): umask(0077) try: return xml_save(root, filename) except IOError, err: raise ConfigError(CONFIG_ERR_XML_WRITE, tr('Unable to write into %s XML file: %s'), filename, exceptionAsUnicode(err))
def write(self, filename, save_as=None): if save_as: name = save_as else: name = self.name # Create the XML tree root = self.exportXML(name) umask(0077) xml_save(root, filename) if save_as: self.name = save_as self.filename = filename self.generic_links.write() if filename == self.filename: self.actions.setSavedState()
def apply(self): root = etree.Element("periods", version="3.0", name="timerange") timeranges = set() for acl in self.acls: for timerange in acl.durations | acl.periodicities: timeranges.add(timerange) for timerange in timeranges: period_node = etree.SubElement(root, "period", name=timerange.id, desc="Generated by Ruleset") perioditem_node = etree.SubElement(period_node, "perioditem") timerange.exportTimeRangeXML(perioditem_node) umask(FILE_UMASK) xml_save(root, self.filename) # umask() should be enough, but old version of ufwi_ruleset used umask(0033) # and an existing periods.xml keeps it old mode. So force the mode the # 0644. chmod(self.filename, 0644)