async def zlist(self, bot, event, room, user): html = E.TABLE() html.append(E.TR(E.TH('id'), E.TH('name'))) for unused_id, game in sorted(self.games.items(), key=lambda x: x[1]['name']): html.append(E.TR(E.TD(game['id']), E.TD(game['name']))) html_data = lxml.html.tostring(html, pretty_print=True).decode('utf-8') await bot.send_room_html(room, html_data)
def make_summary_doc(tests_w_results): tbody = B.TBODY( B.TR(B.TH('Test Name'), B.TH('Inserted (in # of blocks)'), B.TH('Deleted (in # of blocks)'), B.TH('Links'), B.TH('Notes'))) for (test, result) in tests_w_results: row = make_summary_row(test, result) tbody.append(row) return B.HTML( B.HEAD(B.TITLE('Readability Test Summary'), B.STYLE(SUMMARY_CSS, type='text/css')), B.BODY(B.TABLE(tbody)))
def list_boards_menu(board_list, purpose): """need to put boards table creating to a separate function in future""" posts_num_cell = E.DIV(E.SPAN('????', style = 'display:inline-block; width:4em; text-align:center;'), E.INPUT(type='number', size='6', min='0', value='1', style = 'width: 6em;'), E.SELECT(E.OPTION('Секунды', value='1'), E.OPTION('Минуты', value='60'), E.OPTION('Часы', value='3600'), E.OPTION('Дни', value='86400', selected='') ), E.BUTTON('GET', onclick='get_posts_num_from_time(this)', type = 'button')) tablerows = [E.TR(E.TD(E.A(b.address, href = '/'+b.address)), E.TD(b.tablename), E.TD(str(b.name)), E.TD(str(b.fullname)), E.TD(str(b.description)), E.TD(str(b.category)), E.TD(str(b.pictures)), E.TD(str(b.bumplimit)), E.TD(str(b.maxthreads)), E.TD(copy.copy(posts_num_cell)) )for b in board_list] #purpose will be applyed later html = E.HTML( E.HEAD( E.LINK(rel="stylesheet", href="/css/deeplight.css", type="text/css"), E.TITLE("Creating board"), E.SCRIPT(type = 'text/javascript', src = '/adminscript.js') #js ), E.BODY( E.DIV(E.CLASS('adminupdiv'), E.DIV(E.CLASS('logout'), E.A('Logout', href='/admin/logout')), E.H2(E.CLASS("heading"), "Listing boards"), ), E.TABLE( E.CLASS("boardstable"), E.TR(E.TH('Адрес'), E.TH('Таблица'), E.TH('Название'), E.TH('Полное название'), E.TH('Описание'), E.TH('Категория'), E.TH('Максимум картинок'), E.TH('Бамплимит'), E.TH('Максимум тредов'), E.TH('Постов за последнее время') ), *tablerows ) ) ) return lxml.html.tostring(html)
def html(self): from lxml.html import builder as E return E.TABLE( E.CLASS("register"), E.TR(E.TH("Register Table", colspan="3")), *[ E.TR(E.TD(k), E.TD(E.CLASS("fixed"), "%x" % id(v)), E.TD(str(v))) for k, v in self.__p.iteritems() ])
async def show_help(self, bot, room, user, event): table = E.TABLE( E.TR(E.TH("command"), E.TH("arguments"), E.TH("details")), ) html = E.DIV(E.P("Command list:"), table) for command in self.commands: table.append( E.TR( E.TD(', '.join(command.aliases)), E.TD('\xa0'.join(arg.get_help_name() for arg in command.arguments)), E.TD(command.get_help()))) html_data = lxml.html.tostring(html, pretty_print=True).decode('utf-8') print(html_data) await bot.send_room_html(room, html_data)
def format_stats(self): """ Create a formatted report summarizing deltas from last week's job. Values for the report are drawn from the colon-delimited records in the YYYYMM.changes file written to the job's vendor output directory. """ table = B.TABLE(style="width: 400px;") values = self.week, self.year caption = "Changed Documents for Week %s, %s" % values table.append(B.CAPTION(caption, style="border-bottom: solid 1px;")) header_row = B.TR() for header in ("Document Type", "Added", "Modified", "Removed"): header_row.append(B.TH(header, style="text-align: right;")) table.append(header_row) path = "%s/%s%02d.changes" % (self.directory, self.year, self.week) for line in sorted(open(path)): doctype, action, count = line.strip().split(":") if action == "added": name = doctype.split(".")[0] row = B.TR(B.TD(name, style="text-align: right;")) table.append(row) row.append(B.TD(count, style="text-align: right;")) return html.tostring(table, encoding="unicode")
def add_rows(self, tbody): name = builder.TH(self.name) if len(self.filters) > 1: name.set("rowspan", str(len(self.filters))) row = builder.TR(name, *self.filters[0].make_cells()) tbody.append(row) for f in self.filters[1:]: tbody.append(builder.TR(*f.make_cells()))
def draw_table(self, table, table_num=None): style = 'tt %s %s' % ( table.attrib.get('style', self.defaults['table_style']), table.attrib.get('align', self.defaults['table_align'])) cellpadding = '3' cellspacing = '0' htmltable = E.TABLE(cellpadding=cellpadding, ) htmltable.attrib['cellspacing'] = cellspacing htmltable.attrib['class'] = style # Add caption, if it exists if 'title' in table.attrib and table.attrib['title']: caption = '' if table_num and self.pis['tablecount'] == 'yes': caption = 'Table ' + str(table_num) + ': ' htmltable.append(E.CAPTION(caption + table.attrib['title'])) # Draw headers header_row = E.TR() col_aligns = [] for header in table.findall('ttcol'): th = E.TH() if header.text: th.text = header.text header_align = header.attrib.get('align', self.defaults['ttcol_align']) th.attrib['class'] = header_align # Store alignment information col_aligns.append(header_align) header_row.append(th) htmltable.append(E.THEAD(header_row)) # Draw body body = E.TBODY() tr = E.TR() num_columns = len(col_aligns) for i, cell in enumerate(table.findall('c')): col_num = i % num_columns if col_num == 0 and i != 0: # New row body.append(tr) tr = E.TR() td = E.TD() if cell.text: # Add text td.text = cell.text for child in cell: # Add any inline elements (references) for element in self._expand_ref(child): td.append(element) # Get alignment from header td.attrib['class'] = col_aligns[col_num] tr.append(td) body.append(tr) # Add final row htmltable.append(body) # Add to body buffer self.buf.append(self._serialize(htmltable))
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 list_bans_menu(ban_list, purpose): """need to put bans and boards table creating to a joint function in future""" tablerows = [E.TR(E.TD(str(b.id)), E.TD(b.ip), E.TD(b.initiator), E.TD(time.strftime('%d/%m/%Y %H:%M', time.localtime(b.date))), E.TD(str(b.level)), E.TD(E.BUTTON('Снять', type = 'button', onclick = 'remove_ban(this);')) )for b in ban_list] #purpose will be applyed later html = E.HTML( E.HEAD( E.LINK(rel="stylesheet", href="/css/deeplight.css", type="text/css"), E.TITLE("Creating board"), E.SCRIPT(type = 'text/javascript', src = '/adminscript.js') #js ), E.BODY( E.DIV(E.CLASS('adminupdiv'), E.DIV(E.CLASS('logout'), E.A('Logout', href='/admin/logout')), E.H2(E.CLASS("heading"), "Listing bans"), ), E.TABLE( E.CLASS("boardstable"), E.TR(E.TH('ID'), E.TH('IP'), E.TH('Забанивший'), E.TH('Дата'), E.TH('Уровень'), E.TH('') ), *tablerows ) ) ) return lxml.html.tostring(html)
def html(self): from lxml.html import builder as E return E.TABLE( E.CLASS("instruct"), E.TR(E.TH("Instruction", colspan="2")), E.TR( E.TD(str(tuple(self.outPointers)) + " ← " + self.name + str(tuple(self.inPointers)), colspan="2")), E.TR( E.TD(*[E.DIV(str(k)) for k in self.outData]), E.TD(*[E.DIV(str(k)) for k in self.inData]), ), )
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 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)