def output_support_mismatch(self, ref_name: str, prof_name: str): """Output algorithm support differences section""" tags.h4("Differences in algorithm support:", style="color:var(--red-color);display:inline-block") header = ["Algorithm", ref_name + " (reference)", prof_name + " (profiled)"] data = [] for key in self.support_mismatch: ref = self.support_mismatch[key][0] prof = self.support_mismatch[key][1] reftext = "Supported" if ref.support else "Unsupported" if ref.error: reftext = ref.error proftext = "Supported" if prof.support else "Unsupported" if prof.error: proftext = prof.error data.append([key, reftext, proftext]) sm_div = show_hide_div("support_mismatch_div") with sm_div: tags.p( "If an algorithm is supported by the reference card, but not " "the profiled card and vice versa, the cards almost certainly " "do not match.") table(data, header, green_value="Supported", red_value="Unsupported")
def get_html(self, pretty=True): """Generates html code for displaying data for this metadata element""" root_div = div(cls="content-block") def get_th(heading_name): return th(heading_name, cls="text-muted") with root_div: legend('Spatial Reference') div('Coordinate Reference System', cls='text-muted space-top') div(self.value.get('projection', '')) div('Coordinate Reference System Unit', cls='text-muted space-top') div(self.value['units']) div('Datum', cls='text-muted space-top') div(self.value.get('datum', '')) div('Coordinate String', cls='text-muted space-top') div(self.value.get('projection_string', ''), style="word-break: break-all;") h4('Extent', cls='space-top') with table(cls='custom-table'): with tbody(): with tr(): get_th('North') td(self.value['northlimit']) with tr(): get_th('West') td(self.value['westlimit']) with tr(): get_th('South') td(self.value['southlimit']) with tr(): get_th('East') td(self.value['eastlimit']) return root_div.render(pretty=pretty)
def output_mismatch(self, ref_name, prof_name): """Output mismatch section""" tags.h4("List of algorithms with different results:", style="color:var(--red-color);display:inline-block") header = ["Algorithm", ref_name + " (reference)", prof_name + " (profiled)"] data = [] for key in self.mismatch: ref = self.mismatch[key][0] prof = self.mismatch[key][1] reftext = "{:.2f}".format(ref.operation_avg()) + " ms" proftext = "{:.2f}".format(prof.operation_avg()) + " ms" data.append([key, reftext, proftext]) sm_div = show_hide_div("performance_mismatch_div", hide=False) with sm_div: tags.p( "These are the algorithms in which the cards performed " "with different results." ) table(data, header, red_value="ms")
def output_intro(self): """Output introductory section""" tags.h3("Algorithm Performance comparison results") tags.p("This module compares Java Card " "algorithm performance between the cards.") tags.p("To learn more about testing methodology, visit") tags.a( "https://www.fi.muni.cz/~xsvenda/jcalgtest/knowledgebase.html", href="https://www.fi.muni.cz/~xsvenda/jcalgtest/knowledgebase.html" ) tags.h4("Overview:") tags.p( "The cards' performance match in " + str(len(self.matching)) + " algorithms." ) tags.p( "There are " + str(len(self.missing)) + " algorithms with missing results for either card." ) tags.p( "There are " + str(len(self.mismatch)) + " algorithms with different results." ) tags.p( "There are " + str(len(self.erroneous)) + " algorithms that failed with different error message." ) tags.p( str(len(self.skipped)) + " algorithms were omitted due to being too fast in general." )
def make_modals(section, info): if not 'button' in info: button = 'Info' else: button = info['button'] for k in ['title', 'content']: if not k in info: raise NotValidTag( 'Make sure to use both title and content keys') modal_title = info['title'].replace(' ', '') modal_content = info['content'] tag.button(button, type="button", _class="btn btn-primary btn-md reportng-button-class", data_toggle="modal", data_target="#%s" % modal_title) with tag.div(_class="modal fade", id="%s" % modal_title, tabindex="-1", role="dialog", aria_labelledby="model%s" % modal_title, aria_hidden="true"): with tag.div(_class="modal-dialog", role="document"): with tag.div(_class="modal-content reportng-modal-content-class"): with tag.div(_class="modal-header reportng-modal-header-class"): tag.h4(modal_title, _class="modal-title reportng-modal-title-class", id="model%s" % modal_title) with tag.div(_class="modal-body reportng-modal-body-class"): tag.div(modal_content, _class="container-fluid", style="word-wrap: break-word;") with tag.div(_class="modal-footer reportng-modal-footer-class"): tag.button( 'Close', type="button", _class="btn btn-sm btn-secondary", data_dismiss="modal")
def output_intro(self): """Output introductory section""" tags.h3("Algorithm Support comparison results") tags.p("This module compares Java Card " "algorithm support between the cards.") tags.p("To learn more about testing methodology, visit:") tags.a("https://www.fi.muni.cz/~xsvenda/jcalgtest/table.html", href="https://www.fi.muni.cz/~xsvenda/jcalgtest/table.html") tags.h4("Overview:") tags.p( "The cards match in " + str(len(self.matching)) + " algorithms." ) tags.p( "There are " + str(len(self.missing)) + " algorithms with missing results for either card." ) tags.p( "There are " + str(len(self.support_mismatch)) + " algorithms with different results." ) mem_mismatch = len(self.memory_mismatch) + len(self.reset_mismatch) \ + len(self.deselect_mismatch) tags.p( "There are " + str(mem_mismatch) + " algorithms with suspicious differences in memory allocation." )
def output_single_memory_mismatch(self, ref_name: str, prof_name: str, dataset: Dict[str, List[SupportResult]]): """Output part of memory mismatch section""" mismatch = "" if dataset is self.memory_mismatch: mismatch = "persistent memory allocation" elif dataset is self.reset_mismatch: mismatch = "memory allocation during reset call" elif dataset is self.deselect_mismatch: mismatch = "memory allocation during deselect call" tags.h4("Differences in " + mismatch + ":", style="color:var(--orange-color)") header = ["Algorithm", ref_name + " (reference)", prof_name + " (profiled)"] data = [] for key in dataset.keys(): if dataset is self.memory_mismatch: ref = str(dataset[key][0].persistent_memory) prof = str(dataset[key][1].persistent_memory) elif dataset is self.reset_mismatch: ref = str(dataset[key][0].ram_reset) prof = str(dataset[key][1].ram_reset) elif dataset is self.deselect_mismatch: ref = str(dataset[key][0].ram_deselect) prof = str(dataset[key][1].ram_deselect) else: raise Exception("Wrong parameter in output_memory_mismatch") data.append([key, ref, prof]) table(data, header)
def get_contest_details(contest) -> div: """Return 'div' element with info about 'contest' instance and it's options. :param contest: Contest instance from which 'div' tag should be build. """ contest_attributes = [ ('name from OCR', contest.name), ('name from fuzzy matching', contest.fuzzy_name), ('name from alias', contest.alias_name), ('referendum header', contest.additional_text), ('question', contest.question), ('Yes/No contest', contest.bipolar), ('on page', contest.page + 1), ('vote for', contest.vote_for), ] title = contest.alias_name or contest.fuzzy_name or contest.name contest_container = div(id=title, cls='py-1') contest_container.add(h4(title, cls='mt-2')) contest_div = div(cls='col pl-4') for contest_key, contest_value in contest_attributes: contest_div.add( StyleSummary.get_details_row(contest_key, str(contest_value))) options_div = div() contest_div.add(h5('Options', cls='mt-2')) for option in reversed(contest.options): options_div.add(StyleSummary.get_option_details(option)) contest_div.add(options_div) contest_container.add(contest_div) return contest_container
def get_html(self): """overrides the base class function""" html_string = super(RefTimeseriesFileMetaData, self).get_html() if not self.has_metadata: root_div = div(cls="alert alert-warning alert-dismissible", role="alert") with root_div: h4("No file level metadata exists for the selected file.") html_string = root_div.render() else: if self.abstract: abstract_div = div(cls="col-xs-12 content-block") with abstract_div: legend("Abstract") p(self.abstract) html_string += abstract_div.render() if self.file_version: file_ver_div = div(cls="col-xs-12 content-block") with file_ver_div: legend("File Version") p(self.file_version) html_string += file_ver_div.render() if self.symbol: symbol_div = div(cls="col-xs-12 content-block") with symbol_div: legend("Symbol") if self.symbol.startswith('http'): with p(): a(self.symbol, href=self.symbol, target="_blank") else: p(self.symbol) html_string += symbol_div.render() if self.temporal_coverage: html_string += self.temporal_coverage.get_html() if self.spatial_coverage: html_string += self.spatial_coverage.get_html() html_string += self.get_ts_series_html().render() html_string += self.get_json_file_data_html().render() template = Template(html_string) context = Context({}) return template.render(context)
def project_html(self, ref_name, prof_name): tags.h3("ATR comparison results") tags.p("This module compares ATR of the smart cards " "and searches database of known smart cards " "for additional information.") tags.h4("ATR:") table([[ref_name + " (reference)", self.ref_atr], [prof_name + " (profiled)", self.prof_atr]], header=["Card", "ATR"]) if self.ref_atr == self.prof_atr: tags.p("The ATR of tested card matches the reference. " "This would suggest the same smart card model.") else: tags.p("The ATR of tested card does not match the reference. " "This would suggest different smart card models.") tags.h4("Additional info from smart card database") tags.p("This information was taken from database of known " "smart cards, distributed under GNU GPLv2.") tags.p("For complete list, check:") tags.a(config.URL.SMARTCARD_LIST, href=config.URL.SMARTCARD_LIST) if self.ref_info: tags.p("The reference card (" + ref_name + ") was found in the database:") with tags.div(): for i in self.ref_info: tags.p(i) else: tags.p("The reference card (" + ref_name + ") was not found in the database.") if self.prof_info: tags.p("The profiled card (" + prof_name + ") was found in the database:") with tags.div(): for i in self.prof_info: tags.p(i) else: tags.p("The profiled card (" + prof_name + ") was not found in the database.")
def get_html(self, pretty=True): """Generates html code for displaying data for this metadata element""" root_div = div(cls="col-xs-6 col-sm-6", style="margin-bottom:40px;") def get_th(heading_name): return th(heading_name, cls="text-muted") with root_div: legend('Spatial Reference') with table(cls='custom-table'): with tbody(): with tr(): get_th('Coordinate Reference System') td(self.value.get('projection', '')) with tr(): get_th('Datum') td(self.datum) with tr(): get_th('Coordinate String Type') td(self.projection_string_type) with tr(): get_th('Coordinate String Text') td(self.projection_string_text) h4('Extent') with table(cls='custom-table'): with tbody(): with tr(): get_th('North') td(self.value['northlimit']) with tr(): get_th('West') td(self.value['westlimit']) with tr(): get_th('South') td(self.value['southlimit']) with tr(): get_th('East') td(self.value['eastlimit']) with tr(): get_th('Unit') td(self.value['units']) return root_div.render(pretty=pretty)
def get_html(self, pretty=True): """Generates html code for displaying data for this metadata element""" root_div = div(cls='content-block') def get_th(heading_name): return th(heading_name, cls="text-muted") with root_div: legend('Spatial Reference') if self.value.get('projection', ''): div('Coordinate Reference System', cls='text-muted') div(self.value.get('projection', '')) if self.datum: div('Datum', cls='text-muted space-top') div(self.datum) if self.projection_string_type: div('Coordinate String Type', cls='text-muted space-top') div(self.projection_string_type) if self.projection_string_text: div('Coordinate String Text', cls='text-muted space-top') div(self.projection_string_text) h4('Extent', cls='space-top') with table(cls='custom-table'): with tbody(): with tr(): get_th('North') td(self.value['northlimit']) with tr(): get_th('West') td(self.value['westlimit']) with tr(): get_th('South') td(self.value['southlimit']) with tr(): get_th('East') td(self.value['eastlimit']) with tr(): get_th('Unit') td(self.value['units']) return root_div.render(pretty=pretty)
def get_html(self): """overrides the base class function""" html_string = super(GenericFileMetaData, self).get_html() if not self.has_metadata: root_div = div(cls="alert alert-warning alert-dismissible", role="alert") with root_div: h4("No file level metadata exists for the selected file.") html_string = root_div.render() else: if self.temporal_coverage: html_string += self.temporal_coverage.get_html() if self.spatial_coverage: html_string += self.spatial_coverage.get_html() template = Template(html_string) context = Context({}) return template.render(context)
def project_html(self, ref_name: str, prof_name: str) -> None: tags.h3("CPLC comparison results") tags.p("This module compares CPLC of smart cards. " "Bear in mind that the CPLC data is static and could be faked. " "Therefore, matching result does not guarantee match. " "However, mismatch in CPLC data is highly suspicious.") tags.h4("CPLC:") if self.get_state() == ContrastState.MATCH: tags.p("CPLC data seems to match between cards.") elif self.get_state() == ContrastState.WARN: tags.p("There are missing CPLC fields in results for one of the " "cards. This could be due to error in measurement, but " "it could suggest suspicious difference.") else: tags.p("There are differences in CPLC fields. The cards probably " "don't match, or differ in hardware or software revision.") self.output_table(ref_name, prof_name)
def output_memory_mismatch(self, ref_name: str, prof_name: str): """Output memory mismatch section""" tags.h4("Differences in memory allocation during tests:", style="color:var(--orange-color);display:inline-block") sm_div = show_hide_div("support_memory_mismatch_div", hide=False) with sm_div: tags.p("Differences in bytes of allocated memory above " "certain threshold might be suspicious, as the memory " "allocated during the test of the same algorithm should " "remain similar.") for dataset in [self.memory_mismatch, self.reset_mismatch, self.deselect_mismatch]: if dataset: self.output_single_memory_mismatch(ref_name, prof_name, dataset)
def render_summary(repo: Path, digest: Changes[Any], rendered: Path) -> Path: rtype = get_result_type(repo) # TODO ?? # ODO just get trait for type?? Cumulative = CumulativeBase.for_(rtype) NOW = datetime.now() name = repo.stem everything = flatten([ch for ch in digest.changes.values()]) before = len(everything) grouped = group_by_key(everything, key=Cumulative.cumkey) print(f'before: {before}, after: {len(grouped)}') cumulatives = list(map(Cumulative, grouped.values())) cumulatives = list(sorted(cumulatives, key=Cumulative.sortkey)) doc = dominate.document( title=f'axol results for {name}, rendered at {fdate(NOW)}') with doc.head: T.style(STYLE) raw_script(JS) with doc: T.h3("This is axol search summary") T.div( "You can use 'hide' function in JS (chrome debugger) to hide certain tags/subreddits/users" ) T.h4("Sources summary") # TODO wrap in div? with T.div(): Cumulative.sources_summary(everything) for cc in cumulatives: T.div(cc.format(), cls='item') rendered.mkdir(exist_ok=True, parents=True) sf = rendered.joinpath(name + '.html') with sf.open('w') as fo: fo.write(str(doc)) return sf
def output_missing(self, ref_name, prof_name): """Output missing measurements section""" tags.h4("Missing measurements in algorithm performance:", style="color:var(--yellow-color);display:inline-block") header = ["Algorithm", ref_name + " (reference)", prof_name + " (profiled)"] data = [] for key in self.missing: ref = self.missing[key][0] prof = self.missing[key][1] reftext = "Failed: " + str(ref.error) proftext = "Failed: " + str(prof.error) if not ref: reftext = "Result missing" elif not ref.error: reftext = "{:.2f}".format(ref.operation_avg()) + " ms" if not prof: proftext = "Result missing" elif not prof.error: proftext = "{:.2f}".format(prof.operation_avg()) + " ms" data.append([key, reftext, proftext]) sm_div = show_hide_div("performance_missing_div", hide=True) with sm_div: tags.p( "These are the algorithms which had their results missing on " "one of the cards. These should be checked manually." ) table(data, header, green_value="ms", red_value="Failed")
def output_erroneous(self, ref_name, prof_name): """Output erroneous section""" tags.h4("List of algorithms with mismatch in error:", style="color:var(--orange-color);display:inline-block") header = ["Algorithm", ref_name + " (reference)", prof_name + " (profiled)"] data = [] for key in self.erroneous: ref = self.erroneous[key][0] prof = self.erroneous[key][1] reftext = "Failed: " + str(ref.error) proftext = "Failed: " + str(prof.error) if not ref.error: reftext = "{:.2f}".format(ref.operation_avg()) + " ms" if not prof.error: proftext = "{:.2f}".format(prof.operation_avg()) + " ms" data.append([key, reftext, proftext]) sm_div = show_hide_div("performance_erroneous_div", hide=False) with sm_div: tags.p( "These are the algorithms in which the cards failed with " "different error. You should manually check this table." "The errors were probably caused by random exceptions during " "performance testing. It is recommended to rerun these " "algorithms manually to ascertain that the card is not broken." ) table(data, header, green_value="ms", red_value="Failed")
def output_skipped(self, ref_name, prof_name): """Output skipped section""" tags.h4("List of algorithms not used for verification:", style="display:inline-block") header = ["Algorithm", ref_name + " (reference)", prof_name + " (profiled)"] data = [] for key in self.skipped: ref = self.skipped[key][0] prof = self.skipped[key][1] reftext = "Failed: " + str(ref.error) proftext = "Failed: " + str(prof.error) if not ref.error: reftext = "{:.2f}".format(ref.operation_avg()) + " ms" if not prof.error: proftext = "{:.2f}".format(prof.operation_avg()) + " ms" data.append([key, reftext, proftext]) sm_div = show_hide_div("performance_skipped_div", hide=True) with sm_div: tags.p( "These are the algorithms that run fast overall. Differences " "of few milliseconds can happen due to measurement errors. " "These measurements have information value, but are omitted " "in automated mismatch detection." ) table(data, header, green_value="ms", red_value="Failed")
def product(file_in): file, remote = file_in prod = Product(file) with div() as di: h4(f"{type(prod).__name__}") with ul(): with li(): b("Description: ") span(mydescription(prod)) with li(): b("Descriptor: ") span(mydescriptor(prod)) with li(): b("Free field: ") span(myfreefield(prod)) with li(): b("Level: ") span(prod.level) with li(): b("File cadence: ") span(myfilecadence(prod)) with li(): b("Download example: ") a(remote, href=remote) h5("PRIMARY Header") hdul = fits.open(file) header2table(hdul["PRIMARY"].header) for extname in ["DATA", "CONTROL", "ENERGIES", "IDB_VERSIONS"]: try: data = read_qtable(file, hdu=extname, hdul=hdul) h5(f"Extension: '{extname}'") # header2table(hdu[extname].header) data2table(data, prod.level) except KeyError: pass return ((prod.level, prod.type, di))
def output_matching(self, ref_name, prof_name): """Output matching section""" tags.h4("List of algorithms with matching results:", style="color:var(--green-color);display:inline-block") header = ["Algorithm", ref_name + " (reference)", prof_name + " (profiled)"] data = [] for key in self.matching: ref = self.matching[key][0] prof = self.matching[key][1] reftext = "Failed: " + str(ref.error) proftext = "Failed: " + str(prof.error) if not ref.error: reftext = "{:.2f}".format(ref.operation_avg()) + " ms" if not prof.error: proftext = "{:.2f}".format(prof.operation_avg()) + " ms" data.append([key, reftext, proftext]) sm_div = show_hide_div("performance_matching_div", hide=True) with sm_div: tags.p( "These are the algorithms in which the cards performed " "similarly, or on which they failed with the same error." ) table(data, header, green_value="ms", red_value="Failed")
def output_matching(self, ref_name, prof_name): """Output matching section""" tags.h4("List of algorithms with matching results:", style="color:var(--green-color);display:inline-block") header = ["Algorithm", ref_name + " (reference)", prof_name + " (profiled)"] data = [] for key in self.matching: ref = self.matching[key][0] prof = self.matching[key][1] reftext = "Supported" if ref.support else "Unsupported" if ref.error: reftext = ref.error proftext = "Supported" if prof.support else "Unsupported" if prof.error: proftext = prof.error data.append([key, reftext, proftext]) sm_div = show_hide_div("support_matching_div", hide=True) with sm_div: tags.p( "These are the algorithms which had their results matching " "between cards with no significant differences in the memory " "allocation." ) table(data, header, green_value="Supported", red_value="Unsupported")
def output_missing(self, ref_name, prof_name): """Output missing measurements section""" tags.h4("Missing measurements in algorithm support:", style="color:var(--yellow-color);display:inline-block") header = ["Algorithm", ref_name + " (reference)", prof_name + " (profiled)"] data = [] for key in self.missing: ref = self.missing[key][0] prof = self.missing[key][1] if ref: ref = "Supported" if ref.support else "Unsupported" else: ref = "Result missing" if prof: prof = "Supported" if prof.support else "Unsupported" else: prof = "Result missing" data.append([key, ref, prof]) sm_div = show_hide_div("support_missing_div", hide=True) with sm_div: tags.p( "These are the algorithms which had their results missing on " "one of the cards. These should be checked manually." ) table(data, header, green_value="Supported", red_value="Unsupported")
def get_html(self, pretty=True): """Generates html code for displaying data for this metadata element""" root_div = div(cls="content-block") def get_th(heading_name): return th(heading_name, cls="text-muted") with root_div: legend('Spatial Reference') div('Coordinate Reference System', cls='text-muted') div(self.projection_name) div('Datum', cls='text-muted space-top') div(self.datum) div('Coordinate String Text', cls='text-muted space-top') div(self.projection_string) h4('Extent', cls='space-top') with table(cls='custom-table'): with tbody(): with tr(): get_th('North') td(self.northlimit) with tr(): get_th('West') td(self.westlimit) with tr(): get_th('South') td(self.southlimit) with tr(): get_th('East') td(self.eastlimit) with tr(): get_th('Unit') td(self.unit) return root_div.render(pretty=pretty)
def test_file_structure(self): c = Converter('Man', file='structured_file.man') c.translate() text = c.html.render() text = c.change_special_symbols(text) doc = tags.html(lang='en') doc = add_head(doc) doc_body = tags.body() row = tags.div(cls='row') row = add_row(row, 'BASH(1)', '', 'BASH(1)') doc_body.add(row) with doc_body: tags.h2('NAME') content = tags.div(cls='content') paragraph = tags.p() paragraph += '\ngrep, egrep, fgrep, rgrep' content.add(paragraph) content.add(tags.h4('Simple Commands')) content2 = tags.div(cls='content') content2.add(tags.br()) paragraph = tags.p() paragraph += '\nA \\fIsimple command\\fP' content2.add(paragraph) def_list = tags.dl() def_termin = tags.dt() def_termin.add('\nInterpret') def_list.add(def_termin) def_list.add(tags.dd(cls='indent')) content2.add(def_list) def_list = tags.dl() def_termin = tags.dt(cls='short') def_termin.add((tags.b('%%'))) def_list.add(def_termin) def_def = tags.dd(cls='indent') def_def.add('\nA literal') def_list.add(def_def) content2.add(def_list) content.add(content2) row = tags.div(cls='row') row = add_row(row, 'GNU Bash 4.4', '2016-08-26', 'BASH(1)') doc_body.add(row) doc.add(doc_body) doc = c.change_special_symbols(doc.render()) self.assertEqual(doc, text)
def get_html(self, site_number): """generates html code for viewing site related data""" root_div = div(cls="content-block") def get_th(heading_name): return th(heading_name, cls="text-muted") with root_div: with div(cls="panel panel-default"): with div(cls="panel-heading"): with h4(cls="panel-title"): site_name = "Site-{}".format(site_number) if self.site_name: site_name = self.site_name a(site_name, data_toggle="collapse", data_parent="#accordion", href="#collapse{}".format(site_number)) with div(id="collapse{}".format(site_number), cls="panel-collapse collapse"): with div(cls="panel-body"): with table(cls='custom-table'): with tbody(): with tr(): get_th('Network Name') td(self.network_name) with tr(): get_th('Service Type') td(self.service_type) with tr(): get_th('Return Type') td(self.return_type) with tr(): get_th('Reference Type') td(self.reference_type) with tr(): get_th('URL') with td(): a(self.url, href=self.url, target="_blank") with tr(): get_th('Site Name') if self.site_name: td(self.site_name) else: td("") with tr(): get_th('Site Code') td(self.site_code) with tr(): get_th('Latitude') td(self.latitude) with tr(): get_th('Longitude') td(self.longitude) with tr(): get_th('Variable Name') if self.variable_name: td(self.variable_name) else: td("") with tr(): get_th('Variable Code') td(self.variable_code) with tr(): get_th('Method Description') if self.method_description: td(self.method_description) else: td("") with tr(): get_th('Method Link') if self.method_link \ and self.method_link.lower() != 'unknown': with td(): a(self.method_link, href=self.method_link, target="_blank") elif self.method_link: td(self.method_link) else: td("") with tr(): get_th('Sample Medium') if self.sample_medium: td(self.sample_medium) else: td("") with tr(): get_th('Value Count') if self.value_count is not None: td(self.value_count) else: td("") with tr(): get_th('Begin Date') td(self.start_date) with tr(): get_th('End Date') td(self.end_date) return root_div
def get_html(self, site_number): """generates html code for viewing site related data""" root_div = div(cls="col-xs-12 pull-left", style="margin-top:10px;") def get_th(heading_name): return th(heading_name, cls="text-muted") with root_div: with div(cls="custom-well panel panel-default"): with div(cls="panel-heading"): with h4(cls="panel-title"): a(self.site_name, data_toggle="collapse", data_parent="#accordion", href="#collapse{}".format(site_number)) with div(id="collapse{}".format(site_number), cls="panel-collapse collapse"): with div(cls="panel-body"): with table(cls='custom-table'): with tbody(): with tr(): get_th('Network Name') td(self.network_name) with tr(): get_th('Service Type') td(self.service_type) with tr(): get_th('Return Type') td(self.return_type) with tr(): get_th('Reference Type') td(self.reference_type) with tr(): get_th('URL') with td(): a(self.url, href=self.url, target="_blank") with tr(): get_th('Site Name') td(self.site_name) with tr(): get_th('Site Code') td(self.site_code) with tr(): get_th('Latitude') td(self.latitude) with tr(): get_th('Longitude') td(self.longitude) with tr(): get_th('Variable Name') td(self.variable_name) with tr(): get_th('Variable Code') td(self.variable_code) with tr(): get_th('Method Description') td(self.method_description) with tr(): get_th('Method Link') with td(): a(self.method_link, href=self.method_link, target="_blank") with tr(): get_th('Sample Medium') td(self.sample_medium) with tr(): get_th('Value Count') td(self.value_count) with tr(): get_th('Begin Date') td(self.start_date) with tr(): get_th('End Date') td(self.end_date) return root_div
def __researchDIRACGroup(self, extSession, chooseScope, state): """Research DIRAC groups for authorized user :param dict extSession: ended authorized external IdP session :return: -- will return (None, response) to provide error or group selector will return (grant_user, request) to contionue authorization with choosed group """ # Base DIRAC client auth session firstRequest = createOAuth2Request(extSession["firstRequest"]) # Read requested groups by DIRAC client or user firstRequest.addScopes(chooseScope) # Read already authed user username = extSession["authed"]["username"] # Requested arguments in first request provider = firstRequest.provider self.log.debug("Next groups has been found for %s:" % username, ", ".join(firstRequest.groups)) # Researche Group result = getGroupsForUser(username) if not result["OK"]: return None, self.server.handle_response( payload=getHTML("server error", theme="error", info=result["Message"]), delSession=True ) groups = result["Value"] validGroups = [ group for group in groups if (getIdPForGroup(group) == provider) or ("proxy" in firstRequest.scope) ] if not validGroups: return None, self.server.handle_response( payload=getHTML( "groups not found.", theme="error", info=f"No groups found for {username} and for {provider} Identity Provider.", ), delSession=True, ) self.log.debug("The state of %s user groups has been checked:" % username, pprint.pformat(validGroups)) # If group already defined in first request, just return it if firstRequest.groups: return extSession["authed"], firstRequest # If not and we found only one valid group, apply this group if len(validGroups) == 1: firstRequest.addScopes(["g:%s" % validGroups[0]]) return extSession["authed"], firstRequest # Else give user chanse to choose group in browser with dom.div(cls="row mt-5 justify-content-md-center align-items-center") as tag: for group in sorted(validGroups): vo, gr = group.split("_") with dom.div(cls="col-auto p-2").add(dom.div(cls="card shadow-lg border-0 text-center p-2")): dom.h4(vo.upper() + " " + gr, cls="p-2") dom.a(href="%s?state=%s&chooseScope=g:%s" % (self.currentPath, state, group), cls="stretched-link") html = getHTML( "group selection..", body=tag, icon="users", info="Dirac use groups to describe permissions. " "You will need to select one of the groups to continue.", ) return None, self.server.handle_response(payload=html, newSession=extSession)
def add_subheader(self, line): self.div_subheader = None self.paragraph = None self.div_header.add(tags.h4(line[4:].strip('"\n'))) self.div_subheader = self.div_header.add(tags.div(cls='content'))
print('Content-Type: text/html; charset=utf-8\n') # XXX: Maybe call cgitb.enable() # XXX: Maybe error out if that doesn't return anything, or if # dists/<item>/Release is missing dists = sorted(os.listdir('dists')) apt_pkg.init_system() doc = dominate.document(title=TITLE) with doc.head: style(CSS) with doc.body: h1(TITLE) with h4(): text('Available distributions: ') # XXX: "manual join" for i, dist in enumerate(dists): if i != 0: text(' | ') a(dist, href='#%s' % dist, _class='mono') text(' — ') text('direct access: ') a('dists', href='dists/', _class='mono') text(' | ') a('pool', href='pool/', _class='mono') text(' — ') text('freshness scale: ')
with doc: tags.button("Back to Top", onclick="backToTop()", id="topButton", cls="floatingbutton") intro_div = tags.div(id="intro") with intro_div: tags.h1("Verification of " + contrast.prof_name + " against " + contrast.ref_name) tags.p("Generated on: " + datetime.now().strftime("%d/%m/%Y %H:%M:%S")) tags.p("Generated from: " + args.verification_profile) tags.h2("Verification results") tags.h4("Ordered results from tested modules:") worst_contrast_state = ContrastState.MATCH suspicions = 0 with tags.div(id="modules"): module_count: int = 0 for m in contrast.contrasts: divname = m.module_name + str(module_count) contrast_class = m.get_state() if contrast_class.value > worst_contrast_state.value: worst_contrast_state = contrast_class if contrast_class.value >= ContrastState.WARN.value:
def process(): # doc = dominate.document(DOCNAME) h = html(name=DOCNAME) with h: # _head = head() _head = head() with _head: s = style() s.add("\nh3, h4 {text-align:center;}") s.add("\nth {background-color:yellow;}") s.add("\ntr, td, th {text-align:center;}") s.add("\ntd.left {text-align:left;}") s.add("\n") b = body() b.add(h3(DOCNAME)) b.add(h4(asctime())) b.add(hr()) t = table(border="1", cellpadding="3", cellspacing="3") b.add(t) r = tr() t.add(r) r.add(th("Code")) r.add(th("Waypoint")) r.add(th("Image")) r.add(th("Note")) f = open(FILENAME, "r") for index, line in enumerate(f.readlines()): if index == 0: continue code, waypoint_name, url = line.split('\t') r = tr() t.add(r) r.add(td(code)) r.add(td(a(waypoint_name, href=url))) if code in IMAGES: link = IMAGES[code] if isinstance(link, type([])): images = table() for link in link: r2 = tr() r2.add(td(a(link, href=link))) images.add(r2) else: images = a(link, href=link) else: images = "" r.add(td(images)) if code in NOTES: note = NOTES[code] else: note = "TBD" r.add(td(note, cls="left")) outfile = open(OUTFILE, "wb") print >> outfile, h outfile.close() print "Output is in %s" % OUTFILE