def add_mime_url(grph, fil_node, entity_type, mime_type, entity_id_arr): mime_node = lib_uris.gUriGen.node_from_script_args('/entity_mime.py', entity_type, *entity_id_arr) # So that the MIME type is known without loading the URLs. # Also, it allows to force a specific MIME type. # The MIME type is not coded in the property because it is an attribute of the object. mime_node_with_mode = mime_node + "&" + "mode=" + _mime_mode_prefix + mime_type grph.add((fil_node, pc.property_rdf_data_nolist2, lib_util.NodeUrl(mime_node_with_mode)))
def QueryToGraph(grph, sparql_query): logging.critical("THIS IS DEPRECATED") iter_entities_dicts = QueryEntities(grph, sparql_query) # FIXME: Survol scripts are not able to return objects, # FIXME: but they natively create triples which can be fed into the graph: # FIXME: Survol scripts just return the minimum set of data allowing to join with other clauses. # # FIXME: On the other hand, WMI returns objects but cannot natively create RDF triples. # FIXME: Therefore, it makes sense to create triples from the objects. for one_dict_entity in iter_entities_dicts: for variable_name, sparql_object in one_dict_entity.items(): # Dictionary of variable names to PathPredicateObject subject_path_node = lib_util.NodeUrl(sparql_object.m_subject_path) for key, val in sparql_object.m_predicate_object_dict.items(): grph.add((subject_path_node, key, val))
def AddMimeUrl(grph, filNode, entity_type, mime_type, entity_id_arr): entity_host = None if entity_host: genObj = lib_uris.RemoteBox(entity_host) else: genObj = lib_uris.gUriGen mimeNode = genObj.UriMakeFromScript('/entity_mime.py', entity_type, *entity_id_arr) # So that the MIME type is known without loading the URLs. # Also, it allows to force a specific MIME type. # The MIME type is not coded in the property because it is an attribute of the object. # mimeNodeWithMode = lib_util.AnyUriModed(mimeNode, "mime/" + mime_type) # sys.stderr.write("lib_mime.AddMimeUrl BEFORE mimeNode=%s\n"%(mimeNode)) mimeNodeWithMode = mimeNode + "&" + "mode=" + mimeModePrefix + mime_type grph.add((filNode, pc.property_rdf_data_nolist2, lib_util.NodeUrl(mimeNodeWithMode)))
def _add_wmi_links(callback_grph_add, parent_node, entity_type, entity_id, gen_obj): """ wmi_associators_list(entity_type, entity_id) = ["ASSOC1", "ASSOC2"] This applies only if this class is defined in WMI or WBEM respectively, as Survol classes have no associators. # This creates a menu like: # "WMI associators" => :param callback_grph_add: :param parent_node: :param entity_type: :param entity_id: :return: """ # Get the list of associators names and field names, from the ontology, in WMI or WBEM. # It is possible to have both types of accessors, or none. # From survol_ontology_attributes.wmi.202104.json # CIM_ProcessExecutable.Antecedent # predicate_type "ref:CIM_DataFile" # predicate_domai ["CIM_Process"] # CIM_ProcessExecutable.Dependent # predicate_type "ref:CIM_Process" # predicate_domain ["CIM_DataFile"] # Get the list of attributes, like "accessor name.field name" which have a predicate type of the given class. # See terminology: https://docs.microsoft.com/en-us/windows/win32/wmisdk/associators-of-statement # ASSOCIATORS OF {ObjectPath} WHERE # AssocClass = AssocClassName # ClassDefsOnly # RequiredAssocQualifier = QualifierName # RequiredQualifier = QualifierName # ResultClass = ClassName # ResultRole = PropertyName # Role = PropertyName # For each of these attributes, create a URL like: # associators_wmi.py?xid=<the-xid>&__result_class__=<class name>&__result_role__=<xyz> logging.debug("entity_type=%s entity_id=%s", entity_type, entity_id) depth_call = 1 wmi_associators_node = None attributes_list = lib_ontology_tools.class_associators("wmi", lib_wmi.extract_specific_ontology_wmi, entity_type) for attribute_name in attributes_list: logging.debug("attribute_name=%s", attribute_name) # It must have the syntax "associator.role" assert attribute_name.find(".") > 0 if wmi_associators_node is None: # Add the parent node only if there is at least one associator. wmi_associators_node = lib_util.NodeLiteral("WMI associators") callback_grph_add((parent_node, pc.property_script, wmi_associators_node), depth_call) # The CGI parameter "xid" is normally the only CGI parameter related to data. # Extra CGI parameters are used for display mode (RDF, SVG etc...) or for parameters edition, # that is, for "technical" things. # Here, this is the only place where an extra CGI parameters related to data is used. # This is why no function is created in lib_urls for this purpose. # This might change if, in the future, all parameters of the instances are passed # as plain CGI parameters, like the technical parameters which will be prefixed and suffixed with "__". # url_path = gen_obj.create_entity_path("/entity.py", entity_type, entity_id.replace("/", "")) url_path = gen_obj.create_entity_path("/entity.py", entity_type, entity_id) url_path += "&__associator_attribute__=" + attribute_name script_node = lib_util.NodeUrl(url_path) associator_name, _, _ = attribute_name.partition(".") callback_grph_add((wmi_associators_node, pc.property_script, script_node), depth_call + 1) script_label, _, _ = lib_naming.ParseEntityUri(url_path) callback_grph_add((script_node, pc.property_information, lib_util.NodeLiteral(script_label)), depth_call + 1)
def node_from_script_path(self, script_path, entity_type, entity_id): url_path = self.create_entity_path(script_path, entity_type, entity_id) # Depending on the code path, NodeUrl might be called on the result of NodeUrl, # and this is not detected because it does not harm, just a waste of CPU. return lib_util.NodeUrl(url_path)
def MakeTheNodeFromScript(self, path, entity_type, entity_id): url = self.RootUrl() + path + lib_util.xidCgiDelimiter + self.TypeMake( ) + entity_type + "." + entity_id # Depending on the code path, NodeUrl is sometimes called recursively, which is not detected # because its conversion to a string returns the same URL. return lib_util.NodeUrl(url)