def main(): if len(sys.argv) > 1: print >> sys.stderr, 'No arguments expected!' sys.stderr.write(__doc__) sys.exit(1) Log('Reading histogram enum definition from "%s".' % EDITOR_COMMAND_CPP) histogram_values = ReadHistogramValues(EDITOR_COMMAND_CPP) Log('Reading existing histograms from "%s".' % (ENUMS_PATH)) with open(ENUMS_PATH, 'rb') as f: histograms_doc = minidom.parse(f) f.seek(0) xml = f.read() Log('Comparing histograms enum with new enum definition.') UpdateHistogramDefinitions(histogram_values, histograms_doc) Log('Writing out new histograms file.') new_xml = histograms_print_style.GetPrintStyle().PrettyPrintNode( histograms_doc) if PromptUserToAcceptDiff(xml, new_xml, 'Is the updated version acceptable?'): with open(ENUMS_PATH, 'wb') as f: f.write(new_xml) Log('Done.')
def PrettyPrintEnums(raw_xml): """Pretty print the enums.xml file.""" tree = xml.dom.minidom.parseString(raw_xml) # Prevent accidentally adding histograms to enums.xml DropNodesByTagName(tree, 'histograms') DropNodesByTagName(tree, 'histogram_suffixes_list') return histograms_print_style.GetPrintStyle().PrettyPrintXml(tree)
def PrettyPrintEnums(raw_xml): """Pretty print the given enums XML.""" root = etree_util.ParseXMLString(raw_xml) # Prevent accidentally adding histograms to enums.xml DropNodesByTagName(root, 'histograms') DropNodesByTagName(root, 'histogram_suffixes_list') top_level_content = etree_util.GetTopLevelContent(raw_xml) formatted_xml = ( histograms_print_style.GetPrintStyle().PrettyPrintXml(root)) return top_level_content + formatted_xml
def PrettyPrintHistogramsTree(tree): """Pretty-print the given ElementTree element. Args: tree: The ElementTree element. Returns: The pretty-printed version as an XML string. """ # Prevent accidentally adding enums to histograms.xml DropNodesByTagName(tree, 'enums') canonicalizeUnits(tree) fixObsoleteOrder(tree) return histograms_print_style.GetPrintStyle().PrettyPrintXml(tree)
def PrettyPrintHistogramsTree(tree): """Pretty-print the given xml.dom.minidom.Document object. Args: tree: The xml.dom.minidom.Document object. Returns: The pretty-printed version as an XML string. """ assert isinstance(tree, xml.dom.minidom.Document) # Prevent accidentally adding enums to histograms.xml DropNodesByTagName(tree, 'enums') canonicalizeUnits(tree) fixObsoleteOrder(tree) return histograms_print_style.GetPrintStyle().PrettyPrintXml(tree)
def _GetOldAndUpdatedXml(histogram_enum_name, source_enum_values, source_enum_path, caller_script_name): """Reads old histogram from |histogram_enum_name| from |ENUMS_PATH|, and calculates new histogram from |source_enum_values| from |source_enum_path|, and returns both in XML format. """ Log('Reading existing histograms from "{0}".'.format(ENUMS_PATH)) with open(ENUMS_PATH, 'rb') as f: histograms_doc = minidom.parse(f) f.seek(0) xml = f.read() Log('Comparing histograms enum with new enum definition.') UpdateHistogramDefinitions(histogram_enum_name, source_enum_values, source_enum_path, caller_script_name, histograms_doc) new_xml = histograms_print_style.GetPrintStyle().PrettyPrintXml( histograms_doc) return (xml, new_xml)
def main(): if len(sys.argv) > 1: print >> sys.stderr, 'No arguments expected!' sys.stderr.write(__doc__) sys.exit(1) with open(path_util.GetInputFile(POLICY_TEMPLATES_PATH), 'rb') as f: policy_templates = literal_eval(f.read()) with open(ENUMS_PATH, 'rb') as f: histograms_doc = minidom.parse(f) f.seek(0) xml = f.read() UpdateHistogramDefinitions(policy_templates, histograms_doc) new_xml = histograms_print_style.GetPrintStyle().PrettyPrintNode( histograms_doc) if PromptUserToAcceptDiff(xml, new_xml, 'Is the updated version acceptable?'): with open(ENUMS_PATH, 'wb') as f: f.write(new_xml)
def PrettyPrintMergedFiles(filenames=[], files=[]): return histograms_print_style.GetPrintStyle().PrettyPrintXml( MergeFiles(filenames=filenames, files=files))