def build_oval_document_for_definition(defid): """For a definition, build a complete oval_definitions document for it""" if defid is None: return None elements_index = lib_search.ElementsIndex(False) if verbose: print( " ---- Resolving all elements needed to build comprehensive document..." ) oval_ids = elements_index.find_downstream_ids(defid) file_paths = elements_index.get_paths_from_ids(oval_ids) if verbose: print( " ---- Importing separate elements into comprehensive document...." ) oval = OvalDocument(None) for path in file_paths: element = OvalElement.fromStandaloneFile(path) if element is None: print(":::: None from path: ", path) return None oval.addElement(element, True) return etree.fromstring(oval.to_string())
def build_comprehensive_oval_document(changes): """ Builds an XML tree which contains all elements affected by the changes """ global debug global verbose if changes is None or len(changes) < 1: return None if verbose: print(" ---- Getting OVAL ID's for all changed files...") oval_ids_changed = { lib_repo.path_to_oval_id(filepath) for filepath in changes } # find all upstream ids if verbose: print( " ---- Locating parent definitions for all changed elements...") elements_index = lib_search.ElementsIndex(False) upstream_ids = elements_index.find_upstream_ids(oval_ids_changed, set()) # filter affected to definition ids affected_def_ids = { oval_id for oval_id in upstream_ids if lib_repo.get_element_type_from_oval_id(oval_id) == 'definition' } # get all downstream elements if verbose: print( " ---- Resolving all elements needed to build comprehensive document..." ) oval_ids = elements_index.find_downstream_ids(affected_def_ids, affected_def_ids) file_paths = elements_index.get_paths_from_ids(oval_ids) if verbose: print( " ---- Importing separate elements into comprehensive document...." ) oval = OvalDocument(None) for path in file_paths: element = OvalElement.fromStandaloneFile(path) if element is None: print(":::: None from path: ", path) return None oval.addElement(element, True) return etree.fromstring(oval.to_string())
def build_comprehensive_oval_document(changes): """ Builds an XML tree which contains all elements affected by the changes """ global debug global verbose if changes is None or len(changes) < 1: return None if verbose: print(" ---- Getting OVAL ID's for all changed files...") oval_ids_changed = {lib_repo.path_to_oval_id(filepath) for filepath in changes} # find all upstream ids if verbose: print(" ---- Locating parent definitions for all changed elements...") elements_index = lib_search.ElementsIndex(False) upstream_ids = elements_index.find_upstream_ids(oval_ids_changed, set()) # filter affected to definition ids affected_def_ids = { oval_id for oval_id in upstream_ids if lib_repo.get_element_type_from_oval_id(oval_id) == "definition" } # get all downstream elements if verbose: print(" ---- Resolving all elements needed to build comprehensive document...") oval_ids = elements_index.find_downstream_ids(affected_def_ids, affected_def_ids) file_paths = elements_index.get_paths_from_ids(oval_ids) if verbose: print(" ---- Importing separate elements into comprehensive document....") oval = OvalDocument(None) for path in file_paths: element = OvalElement.fromStandaloneFile(path) if element is None: print(":::: None from path: ", path) return None oval.addElement(element, True) return etree.fromstring(oval.to_string())
def build_oval_document_for_definition(defid): """For a definition, build a complete oval_definitions document for it""" if defid is None: return None elements_index = lib_search.ElementsIndex(False) if verbose: print(" ---- Resolving all elements needed to build comprehensive document...") oval_ids = elements_index.find_downstream_ids(defid) file_paths = elements_index.get_paths_from_ids(oval_ids) if verbose: print(" ---- Importing separate elements into comprehensive document....") oval = OvalDocument(None) for path in file_paths: element = OvalElement.fromStandaloneFile(path) if element is None: print (":::: None from path: ", path) return None oval.addElement(element, True) return etree.fromstring(oval.to_string())