def legend_add_alternate_display_links(stream): # So we can change parameters of this CGI script. url_html = lib_exports.ModedUrl("html") url_json = lib_exports.ModedUrl("json") url_rdf = lib_exports.ModedUrl("rdf") urlD3 = lib_exports.UrlToMergeD3() # Stupid replacement of dot: "\\" transformed into "\" # Fix for : "http://mymachine:8000/survol/class_wmi.py?xid=\\machine\root\CIMV2%3ACIM_Directory.&mode=html" def url_for_dot(md_url): md_url = md_url.replace("\\\\", "\\\\\\") return _url_to_svg(md_url) stream.write("<tr><td colspan='4'><table border='0'>") stream.write( "<tr>" "<td>(</td>" "<td align='left' href='" + url_for_dot(url_html) + "'>" + _dot_ul("HTML") + "</td>" "<td>,</td>" "<td align='left' href='" + url_for_dot(url_json) + "'>" + _dot_ul("JSON") + "</td>" "<td>,</td>" "<td align='left' href='" + url_for_dot(url_rdf) + "'>" + _dot_ul("RDF") + "</td>" "<td>,</td>" "<td align='left' href='" + url_for_dot(urlD3) + "'>" + _dot_ul("D3") + "</td>" "<td>)</td></tr>" ) stream.write("</table></td></tr>")
def _other_urls(topUrl): if topUrl: topUrl_with_mode = _url_in_html_mode(topUrl) yield (topUrl_with_mode, "Home") yield (lib_exports.ModedUrl("svg"), "SVG format", "Graphviz™ generated") yield (lib_exports.ModedUrl("rdf"), "RDF format", "Semantic Web, RDF-Schema / Protégé™ / Jena...") yield (lib_exports.UrlToMergeD3(), "D3", "Javascript D3 library")
def legend_add_parameters_links(stream, parameters, parameterized_links): """This displays the parameters of the URL and a link allowing to edit them. It assumes that it writes in the middle of a table with two columns.""" if parameters : url_edit = lib_exports.ModedUrl("edit") url_edit_replaced = _url_to_svg(url_edit) stream.write("<tr><td colspan='4' href='%s' align='left'>%s</td></tr>" % (url_edit_replaced, _dot_bold_ul("Edit script parameters"))) arguments = cgi.FieldStorage() for key_param, val_param in parameters.items(): try: actual_param = arguments[key_param].value except KeyError: actual_param = val_param stream.write('<tr><td colspan="2">%s:</td><td colspan="2">%s</td></tr>' % (key_param, _dot_it(actual_param))) # We want to display links associated to the parameters. # The use case is "Prev/Next" when paging between many values. # This could be nicely modelled by just specifying special set of values, # and the links would be calculated here. # For example: { "next" : { "index": curr + 80 }, "prev" : { "index": curr - 80 } } # This simplifies the edition in Json. # It might also simplify formatting. # There will be a similar piece of code in Javascript and plain HTML: # (1) The calling script provides the values to ScriptEnvironment. # (2) A method in ScriptEnvironment calculates the URLS and returns a map # of { "label":"urls" } for url_label in parameterized_links: param_url = parameterized_links[url_label] stream.write("<tr><td colspan='4' href='%s' align='left'>%s</td></tr>" % (param_url, _dot_bold_ul(url_label)))
def _write_errors_no_jinja(error_msg, is_sub_server): if error_msg or is_sub_server: yield ('<table border="0">') if error_msg: yield ( '<tr><td bgcolor="#DDDDDD" align="center" color="#FF0000"><b></b></td></tr>' ) yield ( '<tr><td bgcolor="#DDDDDD"><b>ERROR MESSAGE:%s</b></td></tr>' % error_msg) if is_sub_server: yield ('<tr><td><a href="' + lib_exports.ModedUrl("stop") + '">Stop subserver</a></td></tr>') yield (" </table><br>")
def WriteErrors(error_msg, isSubServer): if error_msg or isSubServer: # TODO: Use style-sheets. WrtAsUtf('<table border="0">') if error_msg: WrtAsUtf( '<tr><td bgcolor="#DDDDDD" align="center" color="#FF0000"><b></b></td></tr>' ) WrtAsUtf( '<tr><td bgcolor="#DDDDDD"><b>ERROR MESSAGE:%s</b></td></tr>' % error_msg) if isSubServer: WrtAsUtf('<tr><td><a href="' + lib_exports.ModedUrl("stop") + '">Stop subserver</a></td></tr>') WrtAsUtf(" </table><br>")
def WriteOtherUrls(topUrl): """ This displays the URL to view the same document, in other ouput formats. """ WrtAsUtf('<table class="other_urls">') if topUrl: topUrl_with_mode = UrlInHtmlMode(topUrl) WrtAsUtf(""" <tr><td align="left" colspan="2"><a href="%s"><b>Home</b></a></td></tr> """ % topUrl_with_mode) # Because Graphviz is not available on OVH platform. if not lib_util.modeOVH: WrtAsUtf(""" <tr> <td class="other_urls"><a href="%s">SVG format</a></td> <td>Graphviz™ generated</td> </tr> """ % lib_exports.ModedUrl("svg")) WrtAsUtf(""" <tr> <td class="other_urls"><a href="%s">RDF format</a></td> <td>Semantic Web, OWL standard / Protégé™...</td> </tr> """ % lib_exports.ModedUrl("rdf")) urlD3 = lib_exports.UrlToMergeD3() WrtAsUtf(""" <tr> <td class="other_urls"><a href="%s">D3</a></td> <td>Javascript D3 library</td> </tr> """ % urlD3) host_wbem_wmi = lib_util.currentHostname # This callback receives a RDF property (WBEM or WMI) and a map # which represents the CIM links associated to the current object. def WMapToHtml(theMap, propData): sys.stderr.write("WMapToHtml len=%d\n" % len(theMap)) for urlSubj in theMap: (subjText, subjEntityGraphClass, subjEntityId) = lib_naming.ParseEntityUri( lib_util.urllib_unquote(urlSubj)) WrtAsUtf("<tr>") WrtAsUtf("<td valign='top'><a href='%s'>%s</a></td>" % (str(urlSubj), subjText)) WrtAsUtf("<td>") WrtAsUtf("<table>") for theProp, urlObj in theMap[urlSubj]: WrtAsUtf("<tr>") propNam = lib_exports.PropToShortPropNam(theProp) WrtAsUtf("<td><i>%s</i></td>" % propNam) if lib_kbase.IsLiteral(urlObj): WrtAsUtf("<td>%s</td>" % (str(urlObj))) else: (objText, objEntityGraphClass, objEntityId) = lib_naming.ParseEntityUri( lib_util.urllib_unquote(urlObj)) WrtAsUtf("<td><a href='%s'>%s</a></td>" % (str(urlObj), objText)) WrtAsUtf("</tr>") WrtAsUtf("</table>") WrtAsUtf("</td>") WrtAsUtf("</tr>") callingUrl = lib_util.RequestUri() (entity_label, entity_type, entity_id) = lib_naming.ParseEntityUri(callingUrl, longDisplay=True) nameSpace = "" mapWbem = CIM_ComputerSystem.AddWbemServers(host_wbem_wmi, nameSpace, entity_type, entity_id) WMapToHtml(mapWbem, pc.property_wbem_data) mapWmi = CIM_ComputerSystem.AddWmiServers(host_wbem_wmi, nameSpace, entity_type, entity_id) WMapToHtml(mapWmi, pc.property_wmi_data) mapSurvol = CIM_ComputerSystem.AddSurvolServers(host_wbem_wmi, nameSpace, entity_type, entity_id) WMapToHtml(mapSurvol, pc.property_survol_agent) WrtAsUtf('</table>')