def render_html(results: Dict[str, Any]) -> str: heading = E.H2( E.A("Locust", href="https://github.com/simiotics/locust"), " summary") body_elements = [heading] refs = results.get("refs") if refs is not None: body_elements.extend([E.H3("Git references")]) body_elements.extend( [E.B("Initial: "), E.SPAN(refs["initial"]), E.BR()]) if refs["terminal"] is not None: body_elements.extend( [E.B("Terminal: "), E.SPAN(refs["terminal"]), E.BR()]) body_elements.append(E.HR()) changes_by_file = results["locust"] for item in changes_by_file: item_element = file_section_handler(item) body_elements.append(item_element) html = E.HTML(E.BODY(*body_elements)) results_string = lxml.html.tostring(html).decode() return results_string
def span(self): """Assemble the HTML cell object for the match""" section = B.B(self.section) section.tail = ' - "' + self.prefix.lstrip() term = B.B(self.text, B.CLASS("error")) term.tail = self.suffix.rstrip() + '"' return B.SPAN(section, term)
def change_representation_compressed(change: Dict[str, Any], link: str, filepath: str, current_depth: int, max_depth: int) -> Optional[Any]: """ Generator of compressed html markdown. """ change_elements: List[Any] = [ E.B(change["type"]), E.SPAN(" "), E.A(change["name"], href=link), E.B(" changed lines: "), E.SPAN(str(change["changed_lines"])), ] if change["total_lines"]: change_elements.extend( [E.SPAN("/"), E.SPAN(str(change["total_lines"]))]) if change["children"]: change_elements.extend([E.BR()]) child_elements = [] for child in change["children"]: child_element = render_change_as_html(child, filepath, current_depth + 1, max_depth, True) if child_element is not None: child_elements.append(child_element) change_elements.append(E.UL(*child_elements)) return change_elements
def _update_commands(toolshed, doc_ul, doc): from lxml.html import builder as E missing = {} for bi in toolshed.bundle_info(None): for cmd in bi.commands: words = cmd.name.split(maxsplit=2) name = words[0] if name in doc or name in missing: continue synopsis = cmd.synopsis if len(words) > 1: # synopsis not appropriate for multiword commands synopsis = bi.synopsis href = bi.get_path(os.path.join("docs", "user", "commands", "%s.html" % name)) if href: missing[name] = ("commands/%s.html" % name, synopsis) names = list(doc) missing_names = list(missing) missing_names.sort(key=str.casefold) all_names = names + missing_names all_names.sort(key=str.casefold) for name in missing_names: i = all_names.index(name) href, synopsis = missing[name] if synopsis: synopsis = " \N{En dash} " + synopsis doc_ul.insert( i, E.LI(E.A(E.B(name), href=href), synopsis))
def compare_tables(body, old, new): body.append(builder.H2("Table Comparisons")) for name in sorted(old.tables): body.append(builder.H3(name)) if name in new.tables: compare_table(body, name, old, new) else: body.append(builder.UL(builder.LI(builder.B("TABLE LOST"))))
def html_file_section_handler_vanilla(item: Dict[str, Any]) -> Any: filepath = item["file"] file_url = item.get("file_url", filepath) change_elements = [ render_change_as_html(change, filepath, 0, 2) for change in item["changes"] ] file_elements = [ E.H4(E.A(filepath, href=file_url)), E.B("Changes:"), E.UL(*change_elements), ] return E.DIV(*file_elements)
def compare_docs(body, old, new, verbose): body.append(builder.H2("Document Comparisons")) for name in sorted(old.docs): body.append(builder.H3(f"{name} Docs")) new_docs = new.docs[name] if not new_docs.docs: body.append(builder.UL(builder.LI(builder.B(LOST)))) else: old_docs = old.docs[name] items = [] for key in old_docs.docs: old_id, old_title, old_xml = old_docs.docs[key] if key not in new_docs.docs: items.append(builder.I(builder.LI(old_title))) else: diffs = diff_xml(old_xml, new_docs.docs[key][2], verbose) if diffs is not None: title = builder.B(old_title) items.append(builder.LI(title, diffs)) if not items: body.append(builder.P(CHECK, OK)) else: body.append(builder.UL(*items))
def render_change_as_html(change: Dict[str, Any], filepath: str, current_depth: int, max_depth: int) -> Optional[Any]: if current_depth >= max_depth: return None link = change.get("link") if link is None: link = filepath change_elements: List[Any] = [ E.B("Name: "), E.A(change["name"], href=link), E.BR(), E.B("Type: "), E.SPAN(change["type"]), E.BR(), E.B("Changed lines: "), E.SPAN(str(change["changed_lines"])), ] if change["total_lines"]: change_elements.extend( [E.BR(), E.B("Total lines: "), E.SPAN(str(change["total_lines"]))]) if change["children"]: change_elements.extend([E.BR(), E.B("Changes:")]) child_elements = [] for child in change["children"]: child_element = render_change_as_html(child, filepath, current_depth + 1, max_depth) if child_element is not None: child_elements.append(child_element) change_elements.append(E.UL(*child_elements)) return E.LI(*change_elements)
def _update_tools(toolshed, doc_ul, doc): from lxml.html import builder as E missing = {} for bi in toolshed.bundle_info(None): for t in bi.tools: name = t.name if name in doc: continue href = None tools_dir = bi.get_path(os.path.join("docs", "user", "tools")) if tools_dir is not None: n1 = name.replace(' ', '_') n2 = name.replace(' ', '') names = [n1, n2, n1.casefold(), n2.casefold()] for n in names: html = "%s.html" % n if os.path.exists(os.path.join(tools_dir, html)): href = "tools/%s" % html break missing[name] = (href, t.synopsis) names = list(doc) missing_names = list(missing) missing_names.sort(key=str.casefold) all_names = names + missing_names all_names.sort(key=str.casefold) for name in missing_names: i = all_names.index(name) href, synopsis = missing[name] if synopsis: synopsis = " \N{En dash} " + synopsis if href is None: e = E.LI(E.B(name), synopsis) else: e = E.LI(E.A(E.B(name), href=href), synopsis) e.tail = '\n' doc_ul.insert(i, e)
def html_file_section_handler_github(item: Dict[str, Any]) -> Any: filepath = item["file"] file_url = item.get("file_url", filepath) change_elements = [ render_change_as_html(change, filepath, 0, 2) for change in item["changes"] ] file_summary_element = E.A(filepath, href=file_url) file_elements = [ E.B("Changes:"), E.UL(*change_elements), ] file_elements_div = E.DIV(*file_elements) file_details_element = E.DIV( lxml.html.fromstring( f"<details><summary>{lxml.html.tostring(file_summary_element).decode()}</summary>" f"{lxml.html.tostring(file_elements_div).decode()}</details>")) return file_details_element
def make_menu(index=False): if index: contact = builder.A(builder.B("Contact"), builder.CLASS("hashtag"), href="#contact") else: contact = builder.A(builder.B("Contact"), href=base_url + "#contact") menu = builder.UL( builder.LI( builder.A(builder.I("", builder.CLASS("fas fa-bars")), href=""), builder.CLASS("menu-button")), builder.LI(builder.A(builder.B("Dmitry Kovalev"), href=base_url), builder.CLASS("menu-title")), builder.LI(builder.A(builder.B("Posts"), href=base_url + "posts.html"), builder.CLASS("menu-item")), builder.LI( builder.A(builder.B("Papers"), href=base_url + "papers.html"), builder.CLASS("menu-item")), builder.LI(contact, builder.CLASS("menu-item")), builder.LI(builder.A(builder.B("CV"), href=base_url + "CV/cv.pdf"), builder.CLASS("menu-item")), builder.CLASS("menu")) return builder.DIV(menu, builder.CLASS("menu-container"))
def write_reference_list(self, list): tbody = E.TBODY() refkeys = [] refdict = {} for i, reference in enumerate(list.findall('reference')): tr = E.TR() # Use anchor or num depending on PI anchor = reference.attrib.get('anchor', str(i + self.ref_start)) if self.pis['symrefs'] == 'yes': bullet = anchor else: bullet = str(i + self.ref_start) bullet_td = E.TD(E.B('[' + bullet + ']', id=anchor)) bullet_td.attrib['class'] = 'reference' ref_td = E.TD() ref_td.attrib['class'] = 'top' last = None authors = reference.findall('front/author') for j, author in enumerate(authors): organization = author.find('organization') email = author.find('address/email') initials, surname = short_author_name_parts(author) initials = self.get_initials(author) or initials or '' a = None if j == len(authors) - 1 and len(authors) > 1: last.tail = ' and ' if surname is not None: if j == len(authors) - 1 and len(authors) > 1: # Last author, render in reverse if len(initials) > 0: name_string = initials + ' ' + surname else: name_string = surname else: if len(initials) > 0: name_string = surname + ', ' + initials else: name_string = surname a = E.A(name_string) if email is not None and email.text: if self.pis['linkmailto'] == 'yes': a.attrib['href'] = 'mailto:' + email.text if organization is not None and organization.text: a.attrib['title'] = organization.text.strip() elif organization is not None and organization.text: # Use organization instead of name a = E.A(organization.text.strip()) else: continue ref_td.append(a) last = a a.tail = ', ' title = reference.find('front/title') if title is not None and title.text: title_string = title.text.strip() else: xml2rfc.log.warn('No title specified in reference', \ reference.attrib.get('anchor', '')) title_string = '' if title_string: if reference.attrib.get("quote-title", "true") == "true": # attribute default value: yes if last is not None: last.tail = ', "' else: ref_td.text = '"' title_a = E.A(title_string) title_a.tail = '"' else: if last is not None: last.tail = ', ' title_a = E.A(title_string) title_a.tail = '' ref_td.append(title_a) for seriesInfo in reference.findall('seriesInfo'): # Create title's link to document from seriesInfo if seriesInfo.attrib.get('name', '') == 'RFC': title_a.attrib['href'] = \ self.html_defaults['references_url'] + \ 'rfc' + seriesInfo.attrib.get('value', '') elif seriesInfo.attrib.get('name', '') == 'Internet-Draft': title_a.attrib['href'] = \ self.html_defaults['references_url'] + \ seriesInfo.attrib.get('value', '') title_a.tail += ', '+seriesInfo.attrib.get('name', '') + ' ' + \ seriesInfo.attrib.get('value', '') if not title_a.attrib.has_key("href"): href = reference.attrib.get("target", None) if href: title_a.attrib['href'] = href date = reference.find('front/date') if date is not None: month = date.attrib.get('month', '') if month.isdigit(): month = calendar.month_name[int(month)] year = date.attrib.get('year', '') if month or year: title_a.tail += ', ' if month: month += ' ' title_a.tail += month + year + '.' tr.append(bullet_td) tr.append(ref_td) refdict[bullet] = tr refkeys.append(bullet) # Render annotation as a separate paragraph annotation = reference.find('annotation') if annotation is not None and annotation.text: p = E.P() self.write_t_rec(annotation, parent=p) ref_td.append(p) if self.pis['sortrefs'] == 'yes' and self.pis['symrefs'] == 'yes': refkeys.sort(key=str.lower) for key in refkeys: tbody.append(refdict[key]) self.ref_start += i + 1 # Add to body buffer self.buf.append(self._serialize(E.TABLE(tbody)))
for studiengang in studiengaenge: print(studiengang) document.append(E.H2(studiengang, name=studiengang)) container = E.DIV(E.CLASS("plancontainer")) # E.DIV(E.CLASS("plancontainer")) for stunde in range(59): style = "top: " + str(2 + (100 / 60) * stunde) + "%; " mnt = str(int((stunde + 2) % 4 * 15)) if mnt == "0": mnt = "00" container.append( E.DIV(E.CLASS("stunde"), E.B(str(int(stunde / 4 + 7.5)) + ":" + mnt), style=style)) plan = {} wochentagcounter = 0 for wochentag in [ "montags", "dienstags", "mittwochs", "donnerstags", "freitags" ]: plan[wochentag] = [] print(" " + wochentag) for veranstaltung in tabelle: if veranstaltung["studiengang"] == studiengang and veranstaltung[ "s_termin_zeit"] == wochentag: platziert = False for spalte in plan[wochentag]:
def compare_table(body, name, old, new): items = [] ot = old.tables[name] nt = new.tables[name] if set(ot.cols) != set(nt.cols): ul = builder.UL() item = builder.LI("TABLE STRUCTURE MISMATCH", ul) ul.append(builder.LI(f"old: {ot.cols:!r}")) ul.append(builder.LI(f"new: {nt.cols:!r}")) items.append(item) if ot.names: for key in sorted(ot.names): if key not in nt.names: items.append(builder.LI("row for ", builder.B(key), " lost")) continue old_row = ot.names[key].copy() new_row = nt.names[key].copy() if "id" in old_row: old_row.pop("id") new_row.pop("id") if old_row != new_row: cols = builder.UL() item = builder.LI("row for ", builder.B(key), " changed", cols) items.append(item) for col in old_row: ov = old_row[col] nv = new_row[col] if ov != nv: if name == "query" and col == "value": ov = builder.PRE(ov.replace("\r", "")) nv = builder.PRE(nv.replace("\r", "")) else: ov = repr(ov) nv = repr(nv) changes = builder.LI(f"{col!r} column changed") cols.append(changes) if col not in ("hashedpw", "password"): changes.append( builder.UL(builder.LI(f"old: {ov}"), builder.LI(f"new: {nv}"))) elif name in ("grp_action", "grp_usr"): old_rows = [getattr(old, name)(row) for row in ot.rows] new_rows = [getattr(new, name)(row) for row in nt.rows] for row in sorted(set(old_rows) - set(new_rows)): items.append(builder.LI(f"row for {row} lost")) else: if name in dir(old): old_rows = set([getattr(old, name)(row) for row in ot.rows]) new_rows = set([getattr(new, name)(row) for row in nt.rows]) else: old_rows = set(ot.rows) new_rows = set(nt.rows) old_only = [(row, "lost") for row in (old_rows - new_rows)] new_only = [(row, "added") for row in (new_rows - old_rows)] deltas = old_only + new_only try: for row, which_set in sorted(deltas, key=lambda v: str(v)): items.append(builder.LI(f"{which_set}: {row}")) except: print(deltas) raise if items: body.append(builder.UL(*items)) else: body.append(builder.P(CHECK, OK))