def visit_Instance(self, node): """ Create a table row for this Instance and a new file giving it a memory map of its own. """ # If we're writing files, write another one for the instance and # create an HTML link. Otherwise just give it a name. try: relativefile = htmlpathjoin(self.subdir, node.name + self.extension) filename = os.path.join(self.path, relativefile) except TypeError: linkelement = node.name else: obj = type(self)(output=filename) try: obj.offset = node.offset + self.base except TypeError: obj.offset = node.offset obj.inst = node.name obj.breadcrumbs = E.A(self.title, href=htmlpathjoin('..', self.filename)) obj.styledir = htmlpathjoin(self.styledir, '..') obj.execute(node.binding) linkelement = E.A(node.name, href=relativefile) # And provide a table row for the MemoryMap desc = node.description or node.binding.description if isinstance(self.base, int): offset = '0x{:0{}X}'.format(node.offset + self.base, self.address_nibbles) else: offset = '{}+0x{:0{}X}'.format(self.base, node.offset, self.address_nibbles) return E.TR( E.TD(linkelement, CLASS('peripheral')), E.TD(offset, CLASS('paddress')), E.TD('0x{:0{}X}'.format(node.size, self.address_nibbles), CLASS('psize')), E.TD(CLASS('pdesc'), *[E.P(d) for d in desc]))
def write_top(self, left_header, right_header): """ Buffers the header table """ for i in range(max(len(left_header), len(right_header))): if i < len(left_header): left = left_header[i] else: left = '' if i < len(right_header): right = right_header[i] else: right = '' # Add row to header_rows buffer left_td = E.TD(left) left_td.attrib['class'] = 'left' right_td = E.TD(right) right_td.attrib['class'] = 'right' tr = E.TR(left_td, right_td) self.buffers['header_rows'].append(self._serialize(tr))
def visit_MemoryMap(self, node): """Create an HTML file for a MemoryMap.""" self.title = title = node.name + ' Peripheral Map' an = ((node.size - 1).bit_length() + 3) // 4 # Sweep the document tree to build up the main content with self.tempvars(wordwidth=1, address_nibbles=an, base=node.base, subdir=node.name + '_instances', hlev=2): children = list(self.visitchildren(node)) table = E.TABLE( E.TR(E.TH('Peripheral'), E.TH('Base Address'), E.TH('Size'), E.TH('Description'), *children), CLASS('component_list')) nodes = ([E.H1(title, id='title')] + [E.P(d) for d in node.description] + [E.HR(), table, self.footer(node)]) contentnode = E.DIV(*nodes, id='content') # Add a table of contents sidebar for each table row. instlist = E.UL() for elem in contentnode.xpath("//td[contains(@class, 'peripheral')]"): text = tostring(elem, method="text", encoding="unicode") id = escape(text) elem.attrib['id'] = id node = E.LI(E.A(text, href='#' + id)) instlist.append(node) # And put it all together. return E.HTML( E.HEAD( E.TITLE(title), E.LINK(rel='stylesheet', type='text/css', href=htmlpathjoin(self.styledir, 'reg.css'))), E.BODY( E.DIV(E.DIV(E.P(E.A(title, href='#title')), instlist, id='sidebar'), contentnode, id='wrapper')), )
def add_row(self, rows, level=0): """Create an HTML node to show this term and recurse for children. Pass: rows - sequence of rows to which we add new rows level - level of indent in the hierarchy Return: node object ready for insertion into an HTML tree """ args = [" " * (level - 1) * 2 + "+-"] if level else [] args += self.qc_link, " (", self.cdr_id, ")" row = builder.TR(builder.TD(*args)) if self.focus: row.set("class", "focus") rows.append(row) for child in self.children: child.add_row(rows, level + 1)
def related_info_table(self): """Table at the bottom of the report to links to other information.""" if not hasattr(self, "_related_info_table"): self._related_info_table = None rows = [drug_link.row for drug_link in self.drug_links] rows += [summary_ref.row for summary_ref in self.summary_refs] rows += [external_ref.row for external_ref in self.external_refs] rows += [name_link.row for name_link in self.name_links] rows += [pdq_term.row for pdq_term in self.pdq_terms] if self.thesaurus_ids: label = "NCI Thesaurus ID" args = [self.thesaurus_ids[0]] for id in self.thesaurus_ids[1:]: args += [builder.BR(), id] rows.append(builder.TR(builder.TD(label), builder.TD(*args))) if rows: self._related_info_table = builder.TABLE(*rows) self._related_info_table.set("class", "related-info-table") return self._related_info_table
async def zlistsaves(self, bot, event, game_id, room, user): room_id = room.room_id specific_savegame_dir = os.path.join( self.save_dir, ZGameModule.escape_room_id(room_id), game_id) os.makedirs(specific_savegame_dir, exist_ok=True) filenames = [(f, os.path.getmtime(os.path.join(specific_savegame_dir, f))) for f in os.listdir(specific_savegame_dir) if os.path.isfile(os.path.join(specific_savegame_dir, f))] print(specific_savegame_dir, filenames) filenames.sort(key=lambda x: x[1]) html = E.TABLE() if not filenames: await bot.send_room_text( room, "No savegames for '{}' in this room".format(game_id)) return for f, s in filenames: timestamp = datetime.fromtimestamp(s) html.append(E.TR(E.TD(timestamp.isoformat(' ')), E.TD(f))) html_data = lxml.html.tostring(html, pretty_print=True).decode('utf-8') await bot.send_room_html(room, html_data)
def create_table(): """HTML generation by lxml.html tree.""" divisions = ['All', 'E', 'CMS', 'T', 'A', 'AE', 'PPD', 'AD/APC', 'TD', 'CD', 'ND', 'LBN', 'Other'] pubtypes = ['All', 'PUB', 'THESIS', 'CONF', 'TM', 'FN', 'SLIDES', 'POSTER'] dates = [YEAR_2, YEAR_1, YEAR, MONTH_2, MONTH_1, MONTH] years = [YEAR_2, YEAR_1, YEAR] months = [MONTH_2, MONTH_1, MONTH] # This is a doctype work around for a lxml.etree bug doctype_wa = etree.parse(StringIO('''<!DOCTYPE html>\n<html>\n</html>''')) head_tag = E.HEAD( E.META({'charset': 'utf-8'}), E.TITLE("FERMILAB RESEARCH AT A GLANCE"), E.STYLE( {'type': 'text/css'}, "td {text-align: right;}", " td.l {text-align: left;padding: 7px;}", " a.t {display: block;}" ) ) body = E.BODY(E.P( E.A("Fermilab Technical Publications", href="http://ccd.fnal.gov/techpubs/fermilab_spires.html") )) tag_h3 = E.H3("FERMILAB RESEARCH AT A GLANCE") tag_p = E.P("Glossary at end.") tag_p_and_i = E.P(E.I("Updated: " + DATE_TIME_STAMP)) body.append(tag_h3) body.append(tag_p) body.append(tag_p_and_i) table = E.TABLE() tag_tr_td = E.TR(E.TD, E.TD("Date")) for division in divisions: if division == 'A': division = 'AT' tag_tr_td.append(E.TD(division)) table.append(tag_tr_td) pub_table_row = E.TR() for pubtype in pubtypes: pub_table_row.append(E.TD(pubtype)) pub_type_datelist = E.TD() year_list = E.UL() month_list = E.UL() for year in years: year_list.append(E.LI(year)) for month in months: month_list.append(E.LI(month)) pub_type_datelist.append(year_list) pub_type_datelist.append(month_list) pub_type_datelist.append(E.UL()) pub_table_row.append(pub_type_datelist) pub_type_datelist = E.TD() for division in divisions: tdg = E.TD() list_of_searches = E.UL() for date in dates: if division == 'All': division = '' if pubtype == 'All': pubtype = '' search = 'find r fermilab ' + pubtype if division == 'Other': for good_division in divisions[1:len(divisions)-1]: if good_division == 'AD/APC': search += ' not (r AD or APC)' else: search += ' not r ' + good_division elif division == 'AD/APC': search = 'find r fermilab ' + pubtype + \ ' and (r AD or APC)' else: search += ' ' + division search += ' and de ' + date search = re.sub(r'\s+', ' ', search) result = perform_request_search(p=search, cc="Fermilab") result = len(result) if result == 0: hit_number = E.LI() else: link = search.replace(' ', '+') link = 'https://inspirehep.net/search?cc=Fermilab&p=' + link link += '&rg=100&sf=earliestdate' hit_number = E.LI(E.A({'class': 't'}, str(result), href=link)) list_of_searches.append(hit_number) if date == YEAR or date == MONTH: tdg.append(list_of_searches) list_of_searches = E.UL() pub_table_row.append(tdg) table.append(pub_table_row) pub_table_row = E.TR() glos = E.H4('Glossary') table2 = E.TABLE() glos_tr_td = E.TR( E.TD({'class': 'l'}, "E: Experimental papers"), E.TD({'class': 'l'}, "PPD: Particle Physics Division papers") ) table2.append(glos_tr_td) glos_tr_td = E.TR(E.TD({'class': 'l'}, "T: Particle Physics Division \ Theoretical Physics Department papers"), E.TD({'class': 'l'}, "AD/APC: Accelerator Division \ and Accelerator Physics Center papers")) table2.append(glos_tr_td) glos_tr_td = E.TR(E.TD({'class': 'l'}, "AT: Fermilab Center for Particle \ Astrophysics theoretical papers"), E.TD({'class': 'l'}, "TD: Technical Division papers")) table2.append(glos_tr_td) glos_tr_td = E.TR(E.TD({'class': 'l'}, "AE: Fermilab Center for Particle \ Astrophysics experimental papers"), E.TD({'class': 'l'}, "CD: Computing Sector papers")) table2.append(glos_tr_td) glos_tr_td = E.TR(E.TD({'class': 'l'}, "ND: Neutrino Division papers"), E.TD({'class': 'l'}, "LBN: Long Baseline Neutrino \ Sector papers")) table2.append(glos_tr_td) glos_tr_td = E.TR(E.TD({'class': 'l'}, " "), E.TD({'class': 'l'}, " ")) table2.append(glos_tr_td) glos_tr_td = E.TR(E.TD({'class': 'l'}, " "), E.TD({'class': 'l'}, " ")) table2.append(glos_tr_td) glos_tr_td = E.TR(E.TD({'class': 'l'}, " "), E.TD({'class': 'l'}, " ")) table2.append(glos_tr_td) glos_tr_td = E.TR(E.TD({'class': 'l'}, "PUB: Paper intended for \ publication in a journal"), E.TD({'class': 'l'}, "FN: Physics note - short paper not \ fitting the other categories")) table2.append(glos_tr_td) glos_tr_td = E.TR(E.TD({'class': 'l'}, "CONF: Paper written as part of a \ conference"), E.TD({'class': 'l'}, "SLIDES: Slides presented at a \ conference or lecture")) table2.append(glos_tr_td) glos_tr_td = E.TR(E.TD({'class': 'l'}, "THESIS: Ph.D. thesis based on \ work done at Fermilab"), E.TD({'class': 'l'}, "POSTER: Poster presented at a \ conference")) table2.append(glos_tr_td) glos_tr_td = E.TR(E.TD({'class': 'l'}, "TM: Technical memo"), E.TD({'class': 'l'}, "")) table2.append(glos_tr_td) body.append(table) body.append(glos) body.append(table2) doctype_wa.getroot().append(head_tag) doctype_wa.getroot().append(body) out = lxml.html.tostring(doctype_wa, encoding='UTF-8', pretty_print=True, method='html').rstrip('\n') return out
def pr_table(token, jira_url, delta): u""" Return an Element that renders all changes in `delta` as a table listing merged PRs.abs Arguments: token: The github token to access the github API with. jira_url: The base url of the JIRA instance to link JIRA tickets to. delta (VersionDelta): The AMIs to compare. """ version = delta.new or delta.base match = re.search(u"github.com/(?P<org>[^/]*)/(?P<repo>.*)", version.repo) api = GitHubAPI(match.group(u'org'), match.group(u'repo'), token) try: prs = api.get_pr_range(delta.base.sha, delta.new.sha) change_details = E.TABLE( E.CLASS(u"wrapped"), E.TBODY( E.TR( E.TH(u"Merged By"), E.TH(u"Author"), E.TH(u"Title"), E.TH(u"PR"), E.TH(u"JIRA"), E.TH(u"Release Notes?"), ), *[ E.TR( E.TD( E.A( pull_request.merged_by.login, href=pull_request.merged_by.html_url, )), E.TD( E.A( pull_request.user.login, href=pull_request.user.html_url, )), E.TD(pull_request.title), E.TD( E.A( str(pull_request.number), href=pull_request.html_url, )), E.TD( format_jira_references(jira_url, pull_request.body)), E.TD(u""), ) for pull_request in sorted( prs, key=lambda pr: pr.merged_by.login) ])) except Exception: # pylint: disable=broad-except LOGGER.exception(u'Unable to get PRs for %r', delta) change_details = E.P("Unable to list changes") return SECTION( E.H3(u"Changes for {} (".format(delta.app), E.A(GITHUB_PREFIX.sub(u'', version.repo), href=version.repo), ")"), E.P(E.STRONG(u"Before: "), E.A(delta.base.sha, href=format_commit_url(delta.base))), E.P(E.STRONG(u"After: "), E.A(delta.new.sha, href=format_commit_url(delta.new))), change_details, )
def list_manifests(service): '''Replies to the client with criteria list for a service. The output should be similar to installadm list. Args service - the name of the service being listed Returns None Raises None ''' print 'Content-Type: text/html' # HTML is following print # blank line, end of headers print '<html>' print '<head>' sys.stdout.write('<title>%s %s</title>' % (_('Manifest list for'), service)) print '</head><body>' port = 0 try: smf.AISCF(FMRI="system/install/server") except KeyError: # report the internal error to error_log and requesting client sys.stderr.write( _("error:The system does not have the " "system/install/server SMF service.")) sys.stdout.write( _("error:The system does not have the " "system/install/server SMF service.")) return services = config.get_all_service_names() if not services: # report the error to the requesting client only sys.stdout.write(_('error:no services on this server.\n')) return found = False if config.is_service(service): service_ctrl = AIService(service) found = True # assume new service setup path = service_ctrl.database_path if os.path.exists(path): try: aisql = AIdb.DB(path) aisql.verifyDBStructure() except StandardError as err: # report the internal error to error_log and # requesting client sys.stderr.write( _('error:AI database access ' 'error\n%s\n') % err) sys.stdout.write( _('error:AI database access ' 'error\n%s\n') % err) return # generate the list of criteria for the criteria table header criteria_header = E.TR() for crit in AIdb.getCriteria(aisql.getQueue(), strip=False): criteria_header.append(E.TH(crit)) # generate the manifest rows for the criteria table body names = AIdb.getManNames(aisql.getQueue()) table_body = E.TR() allcrit = AIdb.getCriteria(aisql.getQueue(), strip=False) colspan = str(max(len(list(allcrit)), 1)) for manifest in names: # iterate through each manifest (and instance) for instance in range( 0, AIdb.numInstances(manifest, aisql.getQueue())): table_body.append(E.TR()) # print the manifest name only once (from instance 0) if instance == 0: href = '../' + service + '/' + manifest row = str(AIdb.numInstances(manifest, aisql.getQueue())) table_body.append( E.TD(E.A(manifest, href=href, rowspan=row))) else: table_body.append(E.TD()) crit_pairs = AIdb.getManifestCriteria(manifest, instance, aisql.getQueue(), onlyUsed=True, humanOutput=True) # crit_pairs is an SQLite3 row object which doesn't # support iteritems(), etc. for crit in crit_pairs.keys(): formatted_val = AIdb.formatValue( crit, crit_pairs[crit]) # if we do not get back a valid value ensure a # hyphen is printed (prevents "" from printing) if formatted_val and crit_pairs[crit]: table_body.append( E.TD(formatted_val, align="center")) else: table_body.append( E.TD(lxml.etree.Entity("nbsp"), align="center")) # print the default manifest at the end of the table, # which has the same colspan as the Criteria List label else: href = '../' + service + '/default.xml' table_body.append( E.TR( E.TD(E.A("Default", href=href)), E.TD(lxml.etree.Entity("nbsp"), colspan=colspan, align="center"))) web_page = E.HTML( E.HEAD(E.TITLE(_("OmniOS Automated " "Installation Webserver"))), E.BODY( E.H1( _("Welcome to the OmniOS " "Automated Installation webserver!")), E.P( _("Service '%s' has the following " "manifests available, served to clients " "matching required criteria.") % service), E.TABLE(E.TR(E.TH(_("Manifest"), rowspan="2"), E.TH(_("Criteria List"), colspan=colspan)), criteria_header, table_body, border="1", align="center"), )) print lxml.etree.tostring(web_page, pretty_print=True) # service is not found, provide available services on host if not found: sys.stdout.write(_('Service <i>%s</i> not found. ') % service) sys.stdout.write(_('Available services are:<p><ol><i>')) host = socket.gethostname() for service_name in config.get_all_service_names(): # assume new service setup port = config.get_service_port(service_name) sys.stdout.write( '<a href="http://%s:%d/cgi-bin/' 'cgi_get_manifest.py?version=%s&service=%s">%s</a><br>\n' % (host, port, VERSION, service_name, service_name)) sys.stdout.write('</i></ol>%s' % _('Please select a service ' 'from the above list.')) print '</body></html>'
def html_page_return(board, page, default_style): html = E.HTML( E.HEAD( E.META( **{ 'http-equiv': "Default-Style", 'content': default_style, 'id': 'stylemetatag' }), E.TITLE("/" + board + "/ - page " + str(page)), #title E.SCRIPT(type='text/javascript', src='/mainscript.js'), #js *initiate.style_cache), E.BODY( E.P(E.CLASS("board"), board, id='board'), E.P(E.CLASS("page"), str(page), id='page'), E.P(E.CLASS("thread"), '0', id='thread'), E.TABLE( E.CLASS("maintable"), E.THEAD(E.TR( E.TD( E.TABLE(E.TR( E.TD(E.CLASS('left'), copy.copy(initiate.board_cache_navigation)), E.TD( E.CLASS('right'), utilfunctions.generate_right_up_corner_menu()), ), id='headblock'), E.HR(E.CLASS("delimeter")), )), id='header'), E.TBODY(E.TR( E.TD( E.H2( E.CLASS("boardname"), E.A('/' + board + '/ - ' + initiate.board_cache[board].name, href='/' + board), ), E.HR(E.CLASS("delimeter")), initiate.board_cache[board].post_form, E.SCRIPT( 'function open_form() {document.getElementById("postform").style.display = "block"; document.getElementById("closeform").style.display = "block"; document.getElementById("threadcreate").style.display = "none";}' ), E.SCRIPT( 'function close_form() {document.getElementById("postform").style.display = "none"; document.getElementById("closeform").style.display = "none"; document.getElementById("threadcreate").style.display = "block";}' ), E.H3(E.A('Создать тред', href="javascript:open_form();"), id='threadcreate'), E.H4(E.A('Скрыть форму', href="javascript:close_form();"), id='closeform'), E.HR(E.CLASS("delimeter")), E.DIV('', id='mainframe'), )), id='mainpart'), E.TFOOT( E.TR( E.TD( E.DIV( E.TABLE( E.TR( E.TD( E.A('Предыдущая', id='prevpagelink')), E.TD('', id='pageslist'), E.TD( E.A('Следующая', id='nextpagelink')), ), id='pagestable'), E.SPAN(str( len(initiate.board_cache[board].threads)), id='threadsnumber'), id='pages'), E.DIV(E.HR(E.CLASS("delimeter"), id='end')), #we make it a footer initiate.board_cache_navigation, E.DIV( 'powered by ', E.A( 'Farlight Imageboard Engine', href= 'https://github.com/Alpherie/farlight_board_engine', target='_blank', ), id='credentials'), )), id='footer'), ), onload='boardfunc()')) return lxml.html.tostring(html)
def _lxml_form_generator(self): """Is used for generating lxml post form""" formargs = [] formargs.append(E.TR( E.TD('EMAIL'), E.TD(E.INPUT(type = 'text', name = 'email', value = '', id = 'emailfield'), E.INPUT(type = 'submit', value = 'POST', id = 'postbutton') ), ) ) formargs.append(E.TR( E.TD('THEME'), E.TD(E.INPUT(type = 'text', name = 'theme', value = '', size = '50')), ) ) formargs.append(E.TR( E.TD('NAME'), E.TD(E.INPUT(type = 'text', name = 'name', value = '', size = '50')), ) ) formargs.append(E.TR( E.TD('TEXT'), E.TD(E.TEXTAREA(name = 'text', rows = '8', cols = '50', placeholder = 'POST')), ) ) if self.pictures == 0: pass elif self.pictures == 1: formargs.append(E.TR(#should add checking if pics are available E.TD('PICTURE'), E.TD(E.INPUT(type = 'file', name = 'file0', accept = 'image/*'), id = 'filecellone'), ) ) else: formargs.append(E.TR(#should add checking if pics are available E.TD('PICTURE'), E.TD(E.INPUT(type = 'file', name = 'file0', accept = 'image/*'), E.BUTTON('+', type = 'button', onclick = 'add_file_input(this);', id = '0filebutton'), E.SPAN(str(self.pictures), style = 'display:none;', id = 'maxfiles'), id = 'filecellmany'), ) ) formargs.append(E.TR(#should add checking if deleting is available E.TD('PASSWORD'), E.TD(E.INPUT(type = 'password', name = 'password', value = '', size = '10'), id = 'passwordcell'), ) ) if True:#should add checking if captcha is available formargs.append(E.TR( E.TD( E.CENTER('CAPTCHA WILL BE HERE'), colspan = '2' ) ) ) formargs.append(E.TR(E.TD('CAPTCHA'), E.TD(E.INPUT(type = 'text', name = 'captcha', value = '')), ) ) form = E.FORM(E.CLASS("postform"), #postform E.INPUT(type = 'hidden', name = 'action', value = 'post'), E.INPUT(type = 'hidden', name = 'op', value = '0', id = 'op_referer'), E.SCRIPT('document.getElementById("op_referer").value = document.getElementById("thread").innerHTML;'), E.TABLE(*formargs), method = 'POST', action = '/'+self.address, enctype = 'multipart/form-data', id = 'postform') return form
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)))
def index(self): """ The server's main page """ # generate the list of criteria for the criteria table header criteriaHeader = E.TR() for crit in AIdb.getCriteria(self.AISQL.getQueue(), strip=False): criteriaHeader.append(E.TH(crit)) # generate the manifest rows for the criteria table body names = AIdb.getManNames(self.AISQL.getQueue()) tableBody = E.TR() for manifest in names: # iterate through each manifest (and instance) for instance in range(0, AIdb.numInstances(manifest, self.AISQL.getQueue())): tableBody.append(E.TR()) # print the manifest name only once (key off instance 0) if instance == 0: tableBody.append( E.TD(E.A(manifest, href="/manifests/" + manifest, rowspan=str(AIdb.numInstances(manifest, self.AISQL.getQueue()))) ) ) else: tableBody.append(E.TD()) critPairs = AIdb.getManifestCriteria(manifest, instance, self.AISQL.getQueue(), onlyUsed=True, humanOutput=True) # critPairs is an SQLite3 row object which doesn't support # iteritems(), etc. for crit in critPairs.keys(): formatted_val = AIdb.formatValue(crit, critPairs[crit]) # if we do not get back a valid value ensure a hyphen is # printed (this prevents "" from printing) if formatted_val and critPairs[crit]: tableBody.append(E.TD(formatted_val, align="center")) else: tableBody.append(E.TD(lxml.etree.Entity("nbsp"), align="center")) # print the default manifest at the end of the table else: tableBody.append( E.TR( E.TD( E.A("Default", href="/manifests/default.xml")), E.TD(lxml.etree.Entity("nbsp"), colspan=str(max(len(list( AIdb.getCriteria(self.AISQL.getQueue(), strip=False))), 1)), align="center") ) ) web_page = \ E.HTML( E.HEAD( E.TITLE(_("%s A/I Webserver") % _DISTRIBUTION) ), E.BODY( E.H1(_("Welcome to the %s A/I " "webserver!") % _DISTRIBUTION), E.P(_("This server has the following " "manifests available, served to clients " "matching required criteria.")), E.TABLE( E.TR( E.TH(_("Manifest"), rowspan="2"), E.TH(_("Criteria List"), colspan=str(max(len(list( AIdb.getCriteria(self.AISQL.\ getQueue(), strip=False))), 1))) ), criteriaHeader, tableBody, border="1", align="center" ), ) ) return lxml.etree.tostring(web_page, pretty_print=True)
# for other_thread in list(threads): # if thread != other_thread: # finalthreadclasses[thread] -= threadclasses[other_thread] #print(yaml.dump(threadclasses, default_flow_style=False)) from lxml.html import builder as E report_page = E.HTML( E.HEAD(E.TITLE('BSCS Threads Analysis')), E.BODY( E.H1('BSCS Threads Analysis'), E.H3('Common classes'), E.TABLE(*[ E.TR( E.TD(cls.hours), *[ E.TD(lxml.html.fromstring(req)) for req in cls.urlled_alternatives ]) for cls in commons ], border="1"), *[ E.DIV( E.H3(thread), E.TABLE(*[ E.TR( E.TD(cls.hours), *[ E.TD(lxml.html.fromstring(req)) for req in cls.urlled_alternatives ]) for cls in threadclasses[thread] ], border="1")) for thread in list(threads) ]))