コード例 #1
0
ファイル: cmf_models.py プロジェクト: steve855/metfie
    def html(
            self,       # Provenance instance
            name,       # Component name qualified by branch indices
            ):
        '''Add to html view of self.
        '''
        from markup import oneliner
        import os.path

        # Start with a description list key
        return_value = oneliner.dt(name,id=name)+'\n'

        # Construct text for inclusion as description list value
        href = 'file://'+self.file # EG, "file:///absolute_path/calc.py"
        text = '{0}\n line {1:d}: {2}\n'.format(
                oneliner.a(os.path.basename(self.file),href=href),
                self.line_num,
                self.line)
        if self.text != '':
            text += oneliner.p(self.text)+'\n'
        if len(self.branches) == 0:
            text += oneliner.p('No more provenance of {0}'.format(name))+'\n'
        else:
            text += 'Parent Components: '
            for i,branch in enumerate(self.branches):
                name_ = '{0}.{1}'.format(name,i)
                text += oneliner.a(name_,href='#{0}'.format(name_))+', '

        # Insert description list value
        return_value += oneliner.dd(text.rstrip(' ,'))

        # Recursion on branches
        for i,branch in enumerate(self.branches):
            return_value += branch.html('{0}.{1}'.format(name,i))
        return return_value
コード例 #2
0
ファイル: abiFG.py プロジェクト: UCSC-MedBook/external-tools
def putResultsTable(p, b, data, id):
    # p -> page
    # data -> html_filename, pathwayName, summary dictionary (one row per pathway)
    r = data[0]
    summaryVals = r[2]
    header = summaryVals["order"]

    p.table(border=b, id=id, class_='tablesorter')
    p.thead()
    p.tr()
    p.th("Image")
    p.th("Name")
    p.th(header, class_="{sorter:'digit'}")
    p.tr.close()
    p.thead.close()

    p.tbody()
    rowCount = 0
    rowSum = [0 for h in header]
    for r in data:
        htmlFile = r[0]
        pathwayName = r[1]
        summaryVals = r[2]
        p.tr()

        base = os.path.basename(htmlFile)
        #plot of ipls
        p.td(o.a(o.img(src=pngBase + base[:-5] + ".png", width=100),
                 href=base))
        #link to pathway details page
        p.td(o.a(pathwayName, href=base))

        vals = [round(summaryVals[h], 3) for h in header]
        #additional columns of data
        p.td(vals)

        i = 0
        #add data to totals for bottom of page
        for h in header:
            rowSum[i] += summaryVals[h]
            i += 1

        #end of row
        p.tr.close()

    p.tbody.close()
    p.tbody()
    p.tr()
    p.td('')
    p.td('Total')
    # last row in table is sums
    p.td(rowSum)
    p.tr.close()
    p.tbody.close()

    p.table.close()
コード例 #3
0
ファイル: output_html.py プロジェクト: koglin/PyDataSource
 def mk_nav(self):
     self.page.div(class_='col-md-3 blog-sidebar text-muted')
     self.page.div(id_='sticky-anchor') # sticky nav from here: jsfiddle.net/livibetter/HV9HM
     self.page.div.close()
     self.page.div(class_='nav sidebar-module',id_='sticky')
     self.page.h4('Navigation')
     self.page.ul(class_='list-unstyled',role='navigation',style='font-size:90%')
     for sec in self.sections:
         self.page.li( e.a( sec['title'], href='#{:}'.format(sec['id']) ), style="border-bottom: 1px solid #eee; margin-top:8px;")
         for subsec in sec['subsections']:
             self.page.li( e.a( subsec['title'], href='#{:}'.format(subsec['id']) ) )
     self.page.ul.close()
     self.page.div.close()
     self.page.div.close()
コード例 #4
0
ファイル: calc.py プロジェクト: steve855/metfie
    def __init__(
            self,             # GUN instance
            C=Float(2.56e10,  # dynes (cm)^3
'Constant in nominal equation of state: F = C/x^3 dynes', max_hist=10),
            xi=Float(0.4, 'Initial position of projectile / cm'),
            xf=Float(4.0, 'Final/muzzle position of projectile /cm'),
            m=Float(
                100.0,
                '{0} of projectile / g'.format(
                    oneliner.a('Mass', href='http://en.wikipedia.org/wiki/Mass')
                )),
            N=400,            # Number of intervals between xi and xf
            sigma_sq_v=1.0e5, # Variance attributed to v measurements
            ):
        x = Float(1e10,'Just for exercising Float operations')
        C = C + x
        C = C - x
        C = C/x
        C = C*x
        C = -C
        C = -C
        self.C = C + 0.0 # Vacuous demonstration of Float + float
        self.xi = xi
        self.xf = xf
        self.m = m
        self._set_N(N)
        self.sigma_sq_v = sigma_sq_v
        self.components = set(('C','xi','xf','m'))#Component instance names
        return
コード例 #5
0
ファイル: abiFG.py プロジェクト: UCSC-MedBook/external-tools
def putSummaryTable(p, b, data, id, tsv):
    labels = data["sample"]["labels"]

    p.table(border=b, id=id, class_='tablesorter')
    p.thead()
    p.tr()
    p.th("Entity - Gene or Complex or Molecule")
    p.th(labels, class_="{sorter:'digit'}")
    p.tr.close()
    p.thead.close()

    p.tbody()
    for d in data["sample"]:
        if d == "labels":
            continue
        vals = data["sample"][d]
        p.tr()
        #name of gene
        geneUrl = 'http://www.genecards.org/cgi-bin/carddisp.pl?gene=' + d
        tsv.write('<a href=%s target="_blank">%s</a>\t' % (geneUrl, d))
        p.td(o.a(d, href=geneUrl, target="_blank"))
        tmp = [round(v, 3) for v in vals]
        p.td(tmp)
        tsv.write('%s\n' % tmp)
        p.tr.close()
    p.tbody.close()

    tsv.close()
    p.table.close()
コード例 #6
0
    def __str__(self):
        page = markup.page( )
        page.init(
            title=self.title, 
            css=self.css, 
            header=self.header, 
            footer=self.footer
            )
        
        page.h1(self.title)
        
        if len(self.subdirs):
            links = []
            for s in sorted(self.subdirs, key=operator.attrgetter('path')):
                print s.path
                base = os.path.basename(s.path)
                link = e.a(base,
                           href='/'.join([base, 'index.html']))
                links.append(link)
            page.h2('Subdirectories:')
            page.ul( class_='mylist' )
            page.li( links, class_='myitem' )
            page.ul.close()

        size = 100/self.nimagesperrow - 1
        if len(self.images):
            for rimgs in split(sorted(self.images), self.nimagesperrow):
                page.img( src=rimgs, width='{size}%'.format(size=size),
                          alt=rimgs)
                page.br()
        return str(page)
コード例 #7
0
ファイル: output_html.py プロジェクト: koglin/PyDataSource
    def start_subblock(self, title, id=None, doc=None, hidden=False, **kwargs):
        if not id:
            id = re.sub('-|:|\.| ','_', title)

        if isinstance(doc, list):
            #self.page.p('<pre>')
            for p in doc:
                self.page.p(p)
            #self.page.p('</pre>')
        elif doc:
            self.page.p(doc)
            #self.page.p('<pre>'+doc+'</pre>')

        if hidden:
            self.page.p(e.a(title, class_='btn btn-sm btn-default',
                                  onclick="toggler('{:}extra');".format(id)),
                                  class_="text-center")
            self.page.div(id='{:}extra'.format(id), class_="myhidden")
            self.page.div()
        else:
            self.page.a('',id=id,class_='anchor')
            self.page.div()
            self.page.h4(title)
            self.sections[-1]['subsections'].append({})
            self.sections[-1]['subsections'][-1]['title'] = title
            self.sections[-1]['subsections'][-1]['id'] = id

        return
コード例 #8
0
    def __str__(self):
        page = markup.page()
        page.init(title=self.title,
                  css=self.css,
                  header=self.header,
                  footer=self.footer)

        page.h1(self.title)

        if len(self.subdirs):
            links = []
            for s in sorted(self.subdirs, key=operator.attrgetter('path')):
                print s.path
                base = os.path.basename(s.path)
                link = e.a(base, href='/'.join([base, 'index.html']))
                links.append(link)
            page.h2('Subdirectories:')
            page.ul(class_='mylist')
            page.li(links, class_='myitem')
            page.ul.close()

        size = 100 / self.nimagesperrow - 1
        if len(self.images):
            for rimgs in split(sorted(self.images), self.nimagesperrow):
                page.img(src=rimgs,
                         width='{size}%'.format(size=size),
                         alt=rimgs)
                page.br()
        return str(page)
コード例 #9
0
def putResultsTable(p, b, data, id):
    r = data[0]
    summaryVals = r[2]
    header = summaryVals["order"]

    p.table(border=b, id=id, class_='tablesorter')
    p.thead()
    p.tr()
    p.th("Image")
    p.th("Name")
    p.th(header, class_="{sorter:'digit'}")
    p.tr.close()
    p.thead.close()

    p.tbody()
    rowCount = 0
    rowSum = [0 for h in header]
    for r in data:
        htmlFile = r[0]
        pathwayName = r[1]
        summaryVals = r[2]
        p.tr()

        base = os.path.basename(htmlFile)
        p.td(o.a(o.img(src=pngDir + base[:-5] + ".png", width=100), href=base))
        p.td(o.a(pathwayName, href=base))

        vals = [round(summaryVals[h], 3) for h in header]
        p.td(vals)

        i = 0
        for h in header:
            rowSum[i] += summaryVals[h]
            i += 1

        p.tr.close()

    p.tbody.close()
    p.tbody()
    p.tr()
    p.td('')
    p.td('Total')
    p.td(rowSum)
    p.tr.close()
    p.tbody.close()

    p.table.close()
コード例 #10
0
def inputPage(amrString, errors):
    page = markup.page(mode='html')
    page.init(lang="en",
              charset='utf-8',
              doctype=markup.doctype.strict,
              title="GoPhiPy: an AMR Verbalizer",
              script=('http://code.jquery.com/jquery-latest.min.js',
                      '../gophi-web/ace/ace.js', '../gophi-web/amr-verb.js'),
              css=('../gophi-web/amr-verb.css'))

    page.form(action="", method="POST", id='form')
    page.h1(
        e.a('Γω-Φ-∏', href="https://github.com/rali-udem/gophipy") +
        ': an AMR verbalizer')
    page.p(
        'AMR Color coding: ' + e.span('variable', class_='ace_variable') +
        ", " + e.span('concept', class_='ace_concept') + ", " +
        e.span('role', class_='ace_role') + e.span(e.a(
            "Editor help",
            target="_blank",
            href='https://github.com/ajaxorg/ace/wiki/Default-Keyboard-Shortcuts'
        ) + " " + e.a('Drag bottom border to resize editor', class_='resize'),
                                                   class_="help"))
    page.div(
        e.div("", id="amr", style="height:" + editorHeight + "px") +
        e.div("", id="amr_dragbar", class_="app_editor_dragbar"))
    page.div(amrString, id="inputAMR", name="amr")
    page.textarea("", name="amr")
    if len(errors) > 0:
        page.pre(e.code(errors))
        m = re.match(r"line +(\d+),(\d+) :", errors)
        if m != None:
            page.script(
                '$(document).ready(function() {ace.edit("amr").gotoLine(%s,%s,true);})'
                % m.groups())
    page.input(id="indent", type="button", value="Indent")
    page.input(name="submit", type="submit", value="Verbalize")
    page.input(name="editorHeight", type="hidden", value="editorHeigth")
    page.fieldset(
        e.legend("Show Representations") + e.label("Semantic", for_="semR") +
        makeCB("semR") + e.label("Syntactic", for_="syntR") + makeCB("syntR"))
    page.input(name="mode", type="hidden", value="reply")
    page.form.close()
    return page
コード例 #11
0
ファイル: cmf_models.py プロジェクト: steve855/metfie
 def html(
         self, # Component instance
         name, # Component name
         ):
     '''Return tuple containing:
          
          1. html description of self suitable for page.li()
          
          2. html description of provenance sutible for page.add
             inside of page.dl(), page.dl.close() pair
     '''
     from markup import oneliner
     if self.display == False:
         return '{0}: value={1}, {2}'.format(
             name,
             self.value,
             oneliner.a('provenance',href='#{0}'.format(name))
             )
     return '{0}: {1}, {2}'.format(
         name,
         oneliner.a('value_link', href='#value of {0}'.format(name)),
         oneliner.a('provenance',href='#{0}'.format(name))
         )
コード例 #12
0
ファイル: output_html.py プロジェクト: koglin/PyDataSource
    def _build_header(self,*args,**kwargs):
        self.page.div(class_='header')

        self.page.nav(class_='navigation')

        self.page.ul(class_='nav nav-pills pull-right')
        self.page.li(e.a('Top',href='#top'),class_='active')
        self.page.ul.close()
        self.page.nav.close()
        
        hutch = args[0].split('/')[0]

        self.page.h3('{:} Data Summary '.format(hutch) +e.small('{:}, {:}'.format(*args),style='font-family:monospace;')
                ,class_='text-muted',style='color: {:};'.format( hutchcolor.get(hutch, 'gray') ))

        self.page.div.close()
コード例 #13
0
ファイル: htmlify.py プロジェクト: znicholls/ESMValTool
def link_to_single(page, singles, panel):
    # Produce link to single plots
    page.p("Individual model plots:", style='padding-top:100px;')
    page.ul()
    if panel.descr == 'JJAS-rp-timelat':
        use_these = singles
    else:
        use_these = [ss for ss in singles if ss.descr == re.sub("(?:-diff)?(?:-page)?[0-9]?", "", panel.descr)]
    
    #remove_rp_timelon = [ss for ss in singles if re.sub("-rp-timelon", "", ss.descr) == panel.descr]
    #diff_removed = [ss for ss in remove_rp_timelon if ss.descr == re.sub("-diff", "", panel.descr)]
#    if panel.descr == 'JJAS-rp-timelat':
#        pdb.set_trace()
    for s in sorted(use_these, key=lambda name:name.name):
        single_html = s.fig + panel.fig + '.html'
        page.li(e.a(s.name, href=single_html))
    page.ul.close()
コード例 #14
0
def createPage(droneurl):
    req = Request(droneurl, headers={"X-Api-Key": apikey})
    try:
        response = urlopen(req)
    except HTTPError as e:
        page.div('HTTPError:' + str(e.code), class_="show")
        writeout(config.get('output', 'filename') + '.html', str(page))
    except URLError as e:
        page.div('URLError: ' + str(e.reason), class_="show")
        writeout(config.get('output', 'filename') + '.html', str(page))
    else:
        try:
            data = loads(response.read())
        except ValueError as e:
            page.div('ValueError: ' + str(e), class_="show")
            writeout(config.get('output', 'filename') + '.html', str(page))
        else:
            if len(data) == 0:
                page.div(
                    "Uh oh! Doesn't look like you have any shows today! :(\nAdd more "
                    + nest.a("here!", href=ndbaseurl),
                    class_="show")
                writeout(config.get('output', 'filename') + '.html', str(page))
            else:
                page.div(config.get('output', 'head'), id="head")
                for x in range(len(data)):
                    title = data[x]['title'].encode('utf-8')
                    series = data[x]['series']['title'].encode('utf-8')
                    airtime = data[x]['series']['airTime'].encode('utf-8')
                    overview = data[x]['overview'].encode('utf-8')
                    banner = data[x]['series']['images'][0]['url'].encode(
                        'utf-8')
                    if overview:
                        page.div(
                            nest.img(src=banner, class_="roundimg") +
                            nest.div(series + ": " + title, class_="title") +
                            nest.div(airtime, class_="airtime") +
                            nest.div(overview, class_="overview"),
                            class_="show")
                    else:
                        page.div(
                            nest.img(src=banner, class_="roundimg") +
                            nest.div(series + ": " + title, class_="title") +
                            nest.div(airtime, class_="airtime"),
                            class_="show")
                writeout(config.get('output', 'filename') + '.html', str(page))
コード例 #15
0
def replyPage(amrString, semR, syntR, semErrors):
    page = markup.page(mode='html')
    page.init(lang="en",
              charset='utf-8',
              doctype=markup.doctype.strict,
              title="AMR verbalized by Γω-Φ-∏",
              script=('http://code.jquery.com/jquery-latest.min.js',
                      '../gophi-web/jsRealB.min.js',
                      '../gophi-web/addLexicon-dme.js',
                      '../gophi-web/realize.js'))
    page.style(
        '.sent {font-weight:bold} textarea {font-family:monospace;font-size:large}'
    )
    page.h1('AMR verbalized by ' +
            e.a('Γω-Φ-∏', href="https://github.com/rali-udem/gophipy"))
    page.h2("AMR")

    page.form(action="", method="POST", id='form')
    page.pre(e.code(amrString))
    if semRflag != "off":
        page.h2("Semantic Representation")
        page.pre(semR.prettyStr())
    if len(semErrors) > 0:
        page.h3(
            "Errors in semantic to syntactic representation transformation")
        page.pre(semErrors)
    if syntRflag != "off":
        page.h2("Syntactic Representation")
        page.pre(syntR)
    page.h2("English Sentence")
    ## HACK: combined uses of multiline strings in both Python and Javascript, this is "delicate"
    page.script(f'''var syntR=`{syntR}`; '''
                )  # syntR must be quoted to prevent immediate evaluation
    page.p('', id="realization")

    page.input(name="amr", type="hidden", value=amrString)
    page.input(name="editorHeight", type="hidden", value=editorHeight)
    page.input(name="semR", type="hidden", value=semRflag)
    page.input(name="syntR", type="hidden", value=syntRflag)
    page.input(name="submit", type="submit", value="Edit the AMR")
    page.input(name="mode", type="hidden", value="input")
    page.form.close()
    return page
コード例 #16
0
def createTraitListingsHTML(traitListDir):
    
    traitSet = set(gwasDB.__studyByTrait.keys())
    
    for trait in traitSet:
        if trait not in __traitMetaAnalysis:
            continue
        
        traitMetadata = __traitMetaAnalysis[trait]
        RE_proteins = traitMetadata['RE']
        drug_proteins = traitMetadata['drugbank']
        other_proteins = traitMetadata['other']
        
        chi_RE = traitMetadata['RE_chi']
        chi_Drugbank = traitMetadata['drugbank_chi']
        
        traitListFilename = os.sep.join([traitListDir, trait.replace(" ","_").replace("/", " or ").replace("\\", " or ") + ".html"])
        
        traitpage = htmltools.createPage("Trait Summary: " + trait, css_file='../genereport.css')
        
        htmltools.pageDescription(traitpage, "Gene list overlap summary for trait: %s" % (trait))
        
        # two of these
        
        htmltools.createContingencyTable(traitpage, "Overlap with rapidly evolving genes:", "RE", "trait", chi_RE[0], chi_RE[1], chi_RE[2],
                chi_RE[3], chi_RE[4], chi_RE[5], chi_RE[6], chi_RE[7] )
        
        htmltools.createContingencyTable(traitpage, "Overlap with drugbank genes:",
                "Drugbank", "trait", chi_Drugbank[0], chi_Drugbank[1],
                chi_Drugbank[2], chi_Drugbank[3], chi_Drugbank[4],
                chi_Drugbank[5], chi_Drugbank[6], chi_Drugbank[7])
        
        chi_drugs = traitMetadata['drugchi']
        htmltools.createContingencyTable(traitpage, "Drug contingency for targeting disease vs targeting rapidly evolving proteins:",
                "Targets Disease Genes", "Targets RE Genes", chi_drugs[0], chi_drugs[1],
                chi_drugs[2], chi_drugs[3], chi_drugs[4],
                chi_drugs[5], chi_drugs[6], chi_drugs[7])


        traitpage.table.open(class_="invisible")
        traitpage.tr.open()

        traitpage.td.open()
        traitpage.div("Gene Lists:", class_="header")
        
        traitpage.div("Trait genes indicated as rapidly evolving: ", class_="description")
        createGeneListTable(traitpage, RE_proteins)
        
        traitpage.div("Trait genes associated with Drugbank targets: ", class_="description")
        createGeneListTable(traitpage, drug_proteins)
        
        traitpage.div("Other trait genes: ", class_="description")
        createGeneListTable(traitpage, other_proteins)
        
        traitpage.td.close()
        traitpage.td.open()

        traitpage.div("Drug Lists:", class_="header")
        
        druglistlen = len(__traitMetaAnalysis[trait]['RE_drugs'])
        traitpage.div("%d drugs targeting associated rapidly evolving proteins" % (druglistlen), class_="description")
        
        traitpage.div.open(class_="druglist")
        traitpage.ul.open()
        for drug in __traitMetaAnalysis[trait]['RE_drugs']:
            link = "http://www.drugbank.ca/drugs/%s" % (drug)
            if drug not in drugDB.__drugs:
                traitpage.li(oneliner.a(drug, href=link))
            else:
                traitpage.li(oneliner.a(drugDB.__drugs[drug]['name'], href=link))
        traitpage.ul.close()
        traitpage.div.close()
        
        druglistlen = len(__traitMetaAnalysis[trait]['other_drugs'])
        traitpage.div("%d Drugs targeting other proteins" % (druglistlen), class_="description")
        
        
        traitpage.div.open(class_="druglist")
        traitpage.ul.open()
        for drug in __traitMetaAnalysis[trait]['other_drugs']:
            link = "http://www.drugbank.ca/drugs/%s" % (drug)
            if drug not in drugDB.__drugs:
                traitpage.li(oneliner.a(drug, href=link))
            else:
                traitpage.li(oneliner.a(drugDB.__drugs[drug]['name'], href=link))
        traitpage.ul.close()
        traitpage.div.close()


        traitpage.td.close()
        traitpage.tr.close()
        traitpage.table.close()
        
        htmltools.savePage(traitpage, traitListFilename)
コード例 #17
0
def createGeneListingsHTML(geneListDir):

    pbar = ProgressBar()
    pbar.setMaximum(len(gwasDB.__geneSet))
    pbar.updateProgress(0)

    i=0
    for gene in gwasDB.__geneSet:
        if i % 10 == 0:
            pbar.updateProgress(i)
        i+=1
        genePage = htmltools.createPage("Gene Summary: " +
                geneDB.__original_names[gene], css_file='../genereport.css',
                scripts = {'../sorttable.js':'javascript'})
        
        
        # Create the disease trait tables
        traits = []
        for trait in gwasDB.__traitDict[gene]:
            traits.append(trait)
            
        traits = sorted(traits, key=lambda trait: -__traitMetaAnalysis[trait]['RE_chi'][0])
        
        traitTable = []
        for trait in traits:
            cnt       = len(__traitMetaAnalysis[trait]['RE'])
            oddsratio = __traitMetaAnalysis[trait]['RE_chi'][4]
            kappa     = __traitMetaAnalysis[trait]['RE_chi'][5]
            fisher_exact = __traitMetaAnalysis[trait]['RE_chi'][6]
            fisherp    = __traitMetaAnalysis[trait]['RE_chi'][7]
            numgenes  = __traitMetaAnalysis[trait]['geneset_size']
            translate = trait.replace(" ","_").replace("/", " or ").replace("\\", " or ")
            
            if len(trait) > 38:
                trait = trait[:35] + "..."
            traitTable.append(["<a href=\"../traitlists/%s.html\">%s</a>" %
                (translate,trait), cnt, numgenes, "%.7f" % (fisher_exact),
                "%.7f" % (fisherp), "%.1f" % (oddsratio), "%.4f" % (kappa), ])
            
        genePage.div("Gene %s, total traits: %d" % (geneDB.__original_names[gene],len(traitTable)), class_="header")
        
        htmltools.createTable(genePage, traitTable, ["Disease/Trait", "#RE Genes", 
            "#Trait Genes", "fisher exact", "P-value",
            "oddsratio", "kappa"], "traitlisthead", None,
            ["traitcol","recol",
                "genecol","fishercol","pcol",
                "oddscol","kappacol"], "sortable", None)
        
        # Create drug bank links
        
        
        if gene not in drugDB.__drugDict:
            genePage.div("No drugs target gene %s" % (geneDB.__original_names[gene]), class_="header")
        else:
            drugbank_size = len(drugDB.__drugDict[gene])
            
            genePage.div("%d drugs targeting gene %s" % (drugbank_size, geneDB.__original_names[gene]), class_="header")
            
            genePage.div.open(class_="druglist")
            genePage.ul.open()
            for drug in drugDB.__drugDict[gene]:
                link = "http://www.drugbank.ca/drugs/%s" % (drug)
                if drug not in drugDB.__drugs:
                    genePage.li(oneliner.a(drug, href=link))
                else:
                    genePage.li(oneliner.a(drugDB.__drugs[drug]['name'], href=link))
            genePage.ul.close()
            genePage.div.close()
            
        
        htmltools.savePage(genePage, os.sep.join([geneListDir, gene + ".html"]))
    pbar.finalize()
コード例 #18
0
        plots.append(htmlify.Diags(root_path, diag, panels, singles))

page = markup.page(mode='strict_html')
shutil.copy(os.path.join(run_path, 'htmlify.css'), options.target_folder)
page.init(css=os.path.join("..", 'htmlify.css'))

# Sort plots
plots = sorted(plots, key=attrgetter('diag'))
for plot in plots:
    plot.panels.sort('descr')

# Write html with figures
page.h1("Diagnostics", id="the_top")
for diag in plots:
    page.ul()
    page.li(e.a(diag.diag, href='#' + diag.diag))
    page.ul.close()

for diag in plots:
    # Work with panel plots
    for panel in diag.panels.files:
        page.div(class_='diag', id=diag.diag)
        page.img(src=os.path.join("..", fig_path, diag.diag, panel.fig),
                 id=panel.fig,
                 class_="figure")

        # Create single plots
        single_page = markup.page(mode='strict_html')
        single_page.init(css=os.path.join(fig_path, 'htmlify.css'))
        remove_err_vars = [s for s in diag.singles.files if s.var == panel.var]
        htmlify.write_single(options.target_folder, options.link_folder,
コード例 #19
0
def main(initfile, ntop):
    # read configuration options and process
    par = Parameters(initfile)
    gpsb = par.res_param['gpsb']
    gpse = par.res_param['gpse']
    pdir = par.res_param['pdir']
    hdir = par.res_param['hdir']
    data = Data(hdir + 'post_proc_data.dat')

    # relative paths of the stilesheets and javascripts for the results page
    stylesheets = ('general.css', 'table.css', 'modal.css')
    script = 'scripts.js'

    # copy them in the results folder (that should already exist)
    for sheet in stylesheets:
        copy2(os.path.dirname(os.path.abspath(__file__)) + '/' + sheet, hdir)
    copy2(os.path.dirname(os.path.abspath(__file__)) + '/' + script, hdir)

    # Create summary web page
    print "Generating Web Page..."
    page = markup.page()
    page.init(title="NonStatMoni",
              css=stylesheets,
              footer="(2017)" +
              ol.a("Michele Valentini", href='mailto:[email protected]'))

    # best coherences and ccfs summary table generation
    page.button("Auxillary channels summary table", class_="accordion")
    page.div(class_="panel")
    page.input(type="text",
               id="myInput",
               onkeyup="myFunction()",
               placeholder="Search for aux_channel names..")
    page.table(id="t01")
    for aux_name, aux_groups in data.aux_dict.iteritems():
        page.tr()
        page.td()
        page.h4(aux_name)
        page.td.close()
        # Sort the dictionary according to the abs of the values,
        #  from highest to lowest
        ccf_sorted = OrderedDict(
            sorted(data.ccfs[aux_name].iteritems(),
                   key=lambda x: abs(x[1]),
                   reverse=True))
        mean_coh_sorted = OrderedDict(
            sorted(data.mean_cohs[aux_name].iteritems(),
                   key=lambda x: x[1],
                   reverse=True))

        for chan_band, ccf in ccf_sorted.items()[0:4]:
            pagename = 'cohe_{}.html'.format(chan_band.split('_')[0])
            page.td(style="width:10%; font-size :11px;")

            page.add(
                "<a target=_blank href={}#{}>{}</a><br>(ccf={:3f})".format(
                    pagename,
                    aux_name.split(':')[1], chan_band, ccf))
            page.td.close()

        page.td()
        page.add('<a>      ********     </a>')
        page.td.close()

        for chan_band, coh in mean_coh_sorted.items()[0:4]:
            pagename = 'cohe_{}.html'.format(chan_band.split('_')[0])
            page.td(style="width:10%; font-size:11px;")
            page.add(
                '<a target=_blank href={}#{}>{}</a><br>(mncoh={:3f})'.format(
                    pagename,
                    aux_name.split(':')[1], chan_band, coh))
            page.td.close()

        page.tr.close()
    page.table.close()
    page.div.close()

    # build the page menu
    onclick_gen = ("openGroup(event, '{}')".format(group)
                   for group in data.group_dict.keys())
    page.div(ol.button(data.group_dict.keys(),
                       class_='tablinks',
                       onclick=onclick_gen),
             class_='tab')

    # build each group subpage
    for group, g_dict in data.group_dict.iteritems():
        # Build the highest ccf and coherence for this group table
        ccftab = {group: np.zeros(ntop)}
        cohtab = {group: np.zeros(ntop)}
        ccftab_names = {group: np.zeros(ntop, dtype='string')}
        cohtab_names = {group: np.zeros(ntop, dtype='string')}
        cohe_page_name = 'cohe_{}.html'.format(group)
        for aux_n, (aux_name,
                    aux_groups) in enumerate(data.aux_dict.iteritems()):
            if group in aux_groups:
                for band in g_dict['band_list']:
                    if aux_n == 0:
                        ccftab[band] = np.zeros(ntop)
                        cohtab[band] = np.zeros(ntop)
                        ccftab_names[band] = np.zeros(ntop, dtype='string')
                        cohtab_names[band] = np.zeros(ntop, dtype='string')
                    ccf = data.ccfs[aux_name][group + '_' + band]
                    coh = data.mean_cohs[aux_name][group + '_' + band]
                    # todo: build single band tables too
                    if abs(ccf) > min(np.abs(ccftab[band])):
                        ccftab[band] = np.concatenate((ccftab[band], [ccf]))
                        ccftab_names[band] = np.concatenate(
                            (ccftab_names[band], [aux_name]))
                        best_indexes = np.abs(ccftab[band]).argsort()[1:][::-1]
                        ccftab[band] = ccftab[band][best_indexes]
                        ccftab_names[band] = ccftab_names[band][best_indexes]
                    if coh > min(cohtab[band]):
                        cohtab[band] = np.concatenate((cohtab[band], [coh]))
                        cohtab_names[band] = np.concatenate(
                            (cohtab_names[band], [aux_name]))
                        best_indexes = cohtab[band].argsort()[1:][::-1]
                        cohtab[band] = cohtab[band][best_indexes]
                        cohtab_names[band] = cohtab_names[band][best_indexes]

                    # Build the full group best tabs
                    if abs(ccf) > min(np.abs(ccftab[group])):
                        ccftab[group] = np.concatenate((ccftab[group], [ccf]))
                        ccftab_names[group] = np.concatenate(
                            (ccftab_names[group], [aux_name + ' with ' + band
                                                   ]))
                        best_indexes = np.abs(
                            ccftab[group]).argsort()[1:][::-1]
                        ccftab[group] = ccftab[group][best_indexes]
                        ccftab_names[group] = ccftab_names[group][best_indexes]
                    if coh > min(cohtab[group]):
                        cohtab[group] = np.concatenate((cohtab[group], [coh]))
                        cohtab_names[group] = np.concatenate(
                            (cohtab_names[group], [aux_name + ' with ' + band
                                                   ]))
                        best_indexes = cohtab[group].argsort()[1:][::-1]
                        cohtab[group] = cohtab[group][best_indexes]
                        cohtab_names[group] = cohtab_names[group][best_indexes]
        tab = [[" CCF ", "Coherence"]]
        for i in xrange(ntop):
            row = [
                "<a target=_blank href={0}#{1}>{2}</a><br>CCFs = {3:.2f}".
                format(cohe_page_name,
                       ccftab_names[group][i].split(' ')[0].split(':')[1],
                       ccftab_names[group][i], ccftab[group][i]),
                "<a target=_blank href={0}#{1}>{2}</a>"
                "<br>Mean Coher. = {3:.3f}".format(
                    cohe_page_name,
                    cohtab_names[group][i].split(' ')[0].split(':')[1],
                    cohtab_names[group][i], cohtab[group][i])
            ]
            tab.append(row)
        tab_str = OrderedDict({group: tb.tabmaker(tab, True, False)})

        for band in g_dict['band_list']:
            tab = [[" CCF ", "Coherence"]]
            for i in xrange(ntop):
                row = [
                    "<a target=_blank href={0}#{1}>{2}</a><br>CCFs = {3:.2f}".
                    format(cohe_page_name, ccftab_names[band][i].split(':')[1],
                           ccftab_names[band][i], ccftab[band][i]),
                    "<a target=_blank href={0}#{1}>{2}</a>"
                    "<br>Mean Coher. = {3:.3f}".format(
                        cohe_page_name, cohtab_names[band][i].split(':')[1],
                        cohtab_names[band][i], cohtab[band][i])
                ]
                tab.append(row)
            tab_str[band] = tb.tabmaker(tab, True, False)

        # build the rest of the frame
        frame = ol.div(
            ol.h1("NonStatMoni BRMS for {} GPS {:d} - {:d}".format(
                g_dict['channel'], gpsb, gpse),
                  style="display:inline") +
            ol.h3(ol.a("Coherences with slow channels",
                       target='_blank',
                       href=cohe_page_name),
                  style="display:inline"))
        # todo: normalized by what?
        time_title = ol.h2("Normalized BRMS time series")
        time_img = ol.img(class_="myImg",
                          src=pdir + group + "_time.png",
                          alt=group + "Time plot",
                          width="400")
        spec_title = ol.h2("Spectrum of BRMS time series")
        spec_img = ol.img(class_="myImg",
                          src=pdir + group + "_psd.png",
                          alt=group + "PSD plot",
                          width="400")
        frame += ol.div(time_title + time_img + spec_title + spec_img,
                        style="float:left")
        tab_title_gen = (ol.h2("Best Correlations"
                               " and best Coherences for {}".format(c))
                         for c in ([group] + g_dict['band_list']))
        frame += ol.div(
            (title + tbl
             for title, tbl in zip(tab_title_gen, tab_str.values())),
            class_="v_tabcontent",
            id=(['v_' + group] + g_dict['band_list']))
        onclick_gen = ("openBand(event, '{}')".format(band)
                       for band in (['v_' + group] + g_dict['band_list']))

        frame += ol.div(ol.button([group] + g_dict['band_list'],
                                  class_='v_tablinks',
                                  onclick=onclick_gen,
                                  id=['defaultOpen', '']),
                        class_='vertical_tab')

        page.div(frame, id=group, class_='tabcontent')

        # create coherence subpage
        page2 = markup.page()
        page2.init(title="NonStatMoni", css='../style/style.css')
        page2.h1("Coherences with slow channels")
        for aux_name, aux_groups in data.aux_dict.iteritems():
            if group in aux_groups:
                page2.div(ol.img(src=(pdir + group + '_' + 'cohe_' +
                                      aux_name.split(':')[1] + '.png'),
                                 alt=(" No plots for" + aux_name)),
                          id=aux_name.split(':')[1])
        page2.savehtml(hdir + cohe_page_name)

    # create the modal for the plot images
    modal = ol.span("&times;", class_="close")
    modal += ol.img(class_="modal-content", id="img01")
    modal += ol.div('', id="caption")
    page.div(modal, id='myModal', class_="modal")

    page.br()
    page.h2("Contacts")
    page.scripts({script: 'javascript'})
    page.savehtml(hdir + 'index.html')
コード例 #20
0
def putResultsTable(p, b, data, id):
    # p -> page
    # data -> html_filename, pathwayName, summary dictionary (one row per pathway)
    r = data[0]
    summaryVals = r[2]
    header = summaryVals["order"]

    p.table(border=b, id=id, class_='tablesorter')
    p.thead()
    p.tr()
    p.th("Image")
    p.th("Name")
    p.th(header, class_="{sorter:'digit'}")
    p.tr.close()
    p.thead.close()

    summary_tsv = open(rootDir + '/summary.tsv', 'wb')
    summary_tsv.write(
        "Pathway\tAvg num Alterations\tTotal alterations\tnum genes\tmin mean truth\tmax mean truth\tmin mean any\tmax mean any\tnormalized activity\n"
    )
    p.tbody()
    rowCount = 0
    rowSum = [0 for h in header]
    for r in data:
        htmlFile = r[0]
        pathwayName = r[1]
        summaryVals = r[2]
        p.tr()

        base = os.path.basename(htmlFile)
        #plot of ipls
        p.td(o.a(o.img(src=pngBase + base[:-5] + ".png", width=100),
                 href=base))
        #link to pathway details page
        p.td(o.a(pathwayName, href=base))
        summary_tsv.write(pathwayName + '\t')

        vals = [round(summaryVals[h], 3) for h in header]
        for v in vals:
            summary_tsv.write(str(v) + '\t')
        #additional columns of data
        p.td(vals)

        i = 0
        #add data to totals for bottom of page
        for h in header:
            rowSum[i] += summaryVals[h]
            i += 1

        #end of row
        summary_tsv.write('\n')
        p.tr.close()

    summary_tsv.close()
    p.tbody.close()
    p.tbody()
    p.tr()
    p.td('')
    p.td('Total')
    # last row in table is sums
    p.td(rowSum)
    p.tr.close()
    p.tbody.close()

    p.table.close()
コード例 #21
0
def generate(nims, no_quiz_feedback="False", test_time=300):
    """
    Generate the HTML page based on the list of `nims` to be passed to `treatment`.

    NOTE: Must be called within directory containing materials!  This is done
    by `generate_study.py`.  Probably should rewrite to take paths as
    arguments.

    :param nims: list containing {t,e,f}
    :param test_time: time for a single test fault scenario
    :param no_quiz_feedback: turn off showing quiz scores

    :return: HTML page as markup object
    """

    test_time_minutes = format(test_time / 60.0, ".1f")

    page = markup.page()

    title = "Automated Student Benchmark Study"
    page.init(title=title)
    page.h1(title)

    page.p(
        """Please follow the instructions on this page.  The first few
    linked documents (under the heading 'Reference Material') you may have
    already seen; they are provided for your reference."""
    )
    page.p(
        """REMEMBER: You may refer to the material under 'Reference' at any
    time, but you may <b>not</b> refer to the 'Curriculum' material during
    quizzes or tests."""
    )

    page.h2("Reference Material")
    page.ul()
    page.li(e.a("Cover Letter", href=path.join("reference", "cover-letter.pdf"), target="blank"))
    page.li(e.a("Student Instructions", href=path.join("reference", "student-instructions.pdf"), target="blank"))
    page.li(e.a("Background Knowledge", href=path.join("reference", "background-knowledge.pdf"), target="blank"))
    page.ul.close()

    page.h2("Pre-Test")
    page.p(
        "In this pre-test you will be given "
        + test_time_minutes
        + " minutes to diagnose and fix the satellite tracking rig."
    )
    page.p(
        """ Please begin by double-clicking the 'Pre-Test' link in the main
    study folder to open the pre-test simulator.  Click 'Start Simulation' when
    you are ready to begin the timed test.  After the timer runs out and the
    simulation ends, please close the simulator and return to this page."""
    )

    # Get the rung info
    curriculum_path = "curriculum"
    rung_paths = glob(path.join(curriculum_path, "*"))
    rung_paths.sort()
    rung_names = [path.split(rung)[1] for rung in rung_paths]

    # Glob the paths to the T, E, and BF slides by their names
    slides_path = {}
    for nim in ["T", "E", "BF"]:
        slide_path = glob(path.join(curriculum_path, "*", "*", "*" + nim + "_slides*.pdf"))
        slides_path[nim] = sorted(slide_path)

    # Glob the quiz files
    if no_quiz_feedback:
        quiz_paths = glob(path.join("quizzes", "Rung*no_feedback.html"))
    else:
        quiz_paths = glob(path.join("quizzes", "Rung*yes_feedback.html"))
    quiz_paths.sort()

    quiz_full_names = [path.splitext(path.split(filename)[1])[0] for filename in quiz_paths]
    pattern = "(Rung_\d(-\d)?_\d)_.+_feedback"
    quiz_names = [re.search(pattern, full_name).groups()[0] for full_name in quiz_full_names]

    quiz_dict = dict(zip(quiz_names, quiz_paths))

    page.h2("Curriculum")
    page.p(
        """Please complete the following lessons and quizzes in order. When
    you have finished with one document, close the window or tab and move on to
    the next. You are allowed to take notes, either on the scratch paper
    provided or in Notepad."""
    )
    page.p(
        """Feedback lessons require you to interact with the simulator. To
    launch the simulator for practice, double-click the shortcut labeled
    'Simulator' in the main study folder."""
    )
    # """For Rung 6_4 only, instead double-click the shortcut labeled
    #'Realtime-Simulator'.""")

    nim_names = translate_treatment(nims)
    nim_tuples = zip(*[slides_path[x] for x in nim_names])

    for (rung_name, nim_set) in zip(rung_names, nim_tuples):
        page.h3(rung_name)
        page.ul()
        for nim in nim_set:
            file_name = path.split(nim)[1]
            # pull out the descriptive rung name
            match = re.search("(Rung_\d(-\d)?_\d_)?(.+)_slides", file_name)
            desc_name = match.groups()[-1]  # we want the last group
            page.li(e.a(desc_name, href=nim, target="blank"))
        page.ul.close()

        if rung_name in quiz_names:
            page.a(e.h3("Quiz"), href=quiz_dict[rung_name], target="blank")

    page.h2("Post-Test 1")
    page.p(
        "In this post-test you will be given "
        + test_time_minutes
        + """ minutes per scenario to diagnose and fix any faults in the satellite
    tracking rig (if any exist), for each of five scenarios."""
    )
    page.p(
        """Please begin by double-clicking the 'Post-Test-1' link in the main
    study folder to open the post-test simulator.  Click 'Start Simulation'
    when you are ready to begin a scenario.  After the timer runs out and the
    simulation ends, please click 'Start Simulation' again to begin the next
    scenario.  After you have completed five scenarios, please close the
    simulator and return to this page."""
    )

    page.h2("Post-Test 2")
    page.p(
        "In this post-test you will be given "
        + test_time_minutes
        + """ minutes to diagnose and fix any faults in the satellite tracking rig
    (if any exist) for a single scenario."""
    )
    page.p(
        """Please begin by double-clicking the 'Post-Test-2' link in the
    main study folder to open the post-test simulator.  Click 'Start
    Simulation' when you are ready to begin the scenario.  After the timer runs
    out and the simulation ends, please close the simulator and return to this
    page."""
    )

    # give the all-fault case with a certain probability
    if random.uniform(0, 1) < ALLFAULT_PROBABILITY:
        page.h2("Final Test")
        page.p(
            "In this final test you will be given "
            + test_time_minutes
            + """ minutes to diagnose and fix the satellite tracking rig."""
        )
        page.p(
            """ Please begin by double-clicking the 'Final-Test' link
        in the main study folder to open the additional-test simulator.  Click
        'Start Simulation' when you are ready to begin the timed test.  After
        the timer runs out and the simulation ends, please close the simulator
        and return to this page."""
        )

    page.p(
        """You are finished.  Please raise your hand to alert the study
    supervisor."""
    )

    return page
コード例 #22
0
ファイル: createhtml.py プロジェクト: ddunkijaco/DailyDrone
def createPage(droneurl):
    req = Request(droneurl, headers={"X-Api-Key" : apikey})
    try:
        response = urlopen(req)
    except HTTPError as e:
        page.div('HTTPError:' + str(e.code),class_="show")
        writeout(config.get('output', 'filename') + '.html',str(page))  
    except URLError as e:
        page.div('URLError: ' + str(e.reason),class_="show")
        writeout(config.get('output', 'filename') + '.html',str(page))  
    else:
        try:
            data = loads(response.read())
        except ValueError as e:
            page.div('ValueError: ' + str(e),class_="show")
            writeout(config.get('output', 'filename') + '.html',str(page))  
        else:
            if len(data) == 0:
                page.div("Uh oh! Doesn't look like you have any shows today! :(\nAdd more " + nest.a("here!",href=ndbaseurl),class_="show")
                writeout(config.get('output', 'filename') + '.html',str(page))            
            else:
                page.div(config.get('output', 'head'),id="head")
                for x in range(len(data)):
                    title = data[x]['title'].encode('utf-8')
                    series = data[x]['series']['title'].encode('utf-8')
                    airtime = data[x]['series']['airTime'].encode('utf-8')
                    overview = data[x]['overview'].encode('utf-8')
                    banner = data[x]['series']['images'][0]['url'].encode('utf-8')
                    if overview:
                        page.div(nest.img(src=banner,class_="roundimg") + nest.div(series + ": " + title, class_="title") + nest.div(airtime, class_="airtime") + nest.div(overview, class_="overview"), class_="show")
                    else:
                        page.div(nest.img(src=banner,class_="roundimg") + nest.div(series + ": " + title, class_="title") + nest.div(airtime, class_="airtime"), class_="show")
                writeout(config.get('output', 'filename') + '.html',str(page))       
コード例 #23
0
ファイル: theme.py プロジェクト: BackupTheBerlios/capimin
def theme_header(title, image=None, help=None, config=None, nomodule=None, nowebmin=None,
                 rightside="", header=None, body=None, below=None):
    acl = read_acl()

    for l in list_languages():
        if l["lang"] == current_lang:
            lang = l    

    if force_charset:
        charset = force_charset
    elif lang.has_key("charset"):
        charset = lang["charset"]
    else:
        charset = "iso-8859-1"    

    print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"\n\"http://www.w3.org/TR/REC-html40/loose.dtd\">"

    if gconfig.has_key("real_os_type"):
        os_type = gconfig["real_os_type"]
    else:
        os_type = gconfig["os_type"]

    if gconfig.has_key("real_os_version"):
        os_version = gconfig["real_os_version"]
    else:
        os_version = gconfig["os_version"]

    print "<html>\n<head>"
    if (charset):
        print "<meta http-equiv=\"Content-Type\" "\
              "content=\"text/html; charset=%s\">" % charset
    
    print "<link rel='icon' href='images/webmin_icon.png' type='image/png'>"

    if gconfig.get("sysinfo") == 1:
        print "<title>%s : %s on %s (%s %s)</title>" % \
              (title, remote_user, get_system_hostname(), os_type, os_version)
    else:
        print "<title>%s</title>" % title

    if header:
        print header

    # Where does gconfig["sysinfo"] come from? 
    if gconfig.get("sysinfo") == 0 and remote_user:
        print "<SCRIPT LANGUAGE=\"JavaScript\">"
        if os.environ.has_key("SSL_USER"):
            userstring = " (SSL certified)"
        elif os.environ.has_key("LOCAL_USER"):
            userstring = " (Local user)"
        else:
            userstring = ""
        
        print "defaultStatus=\"%s%s logged into %s %s on %s (%s %s)\";" % \
              (remote_user, userstring, text["programname"], get_webmin_version(), 
               get_system_hostname(), os_type, os_version)
        print "</SCRIPT>"

    msc_modules = get_all_module_infos(module_infos_access)

    print "</head>"

    if theme_no_table:
        print '<body bgcolor="#6696bc" link="#000000" vlink="#000000" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" ', body, '>'

    else:
        print '<body bgcolor="#6696bc" link="#000000" vlink="#000000" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" ', body, '>'
        

    if None != session_id:
        logout = "/session_login.cgi?logout=1"
        loicon = "logout.jpg"
        lowidth = 84
        lotext = text["main_logout"]
    else:
        logout = "switch_user.cgi"
        loicon = "switch.jpg"
        lowidth = 27
        lotext = text["main_switch"]


    hpage = markup.page()    

##    top_table = TableLite(width="100%", border="0", cellspacing="0",
##                          cellpadding="0", background="/images/top_bar/bg.jpg",
##                          height="32")
##    t_body = TR()

    hpage.table(width="100%", border="0", cellspacing="0",
                          cellpadding="0", background="/images/top_bar/bg.jpg",
                          height="32")
    hpage.tr()    
    
##    TDList = [TD(IMG("/images/top_bar/left.jpg", height=32),
##                 width=4, nowrap="nowrap"),
##              TD(Href(pytheme_logo_link,
##                      IMG(pytheme_logo, width=99,
##                          height=32,
##                          border="0", alt=pytheme_logo_alt)),
##                 width="100%", nowrap="nowrap")]

    # TODO (Carsten) : missig auto alt tags for images (really needed ?)
    hpage.td(e.img(src="/images/top_bar/left.jpg", height="32"),width="4", nowrap="nowrap")
    hpage.td(width="100%", nowrap="nowrap")
    hpage.a(e.img(src=pytheme_logo,width=99, height=32,alt=pytheme_logo_alt,border=0),href=pytheme_logo_link)
    hpage.td.close()
    

    if not os.environ.has_key("ANONYMOUS_USER"):
        # XXX: acl.get("feedback") might not be correct
        if gconfig.get("nofeedbackcc") != 2 and acl.get("feedback"):
##            TDList.append(TD(Href("/feedback_form.cgi?module=%s" % module_name,
##                                  IMG("/images/top_bar/feedback.jpg", width=97,
##                                      height=32,
##                                      border="0", alt=text["feedback"]))))
            hpage.td()
            hpage.a(e.img(src="/images/top_bar/feedback.jpg",width=97,height=32,border=0,
                       alt=text["feedback"]),href="/feedback_form.cgi?module=%s" % module_name)
            hpage.td.close()
            
##            TDList.append(TD(IMG("/images/top_bar/top_sep.jpg", width=12,
##                                 height=32)))
            hpage.td(e.img(src="/images/top_bar/top_sep.jpg", width=12, height=32))

##        TDList.append(TD(Href(logout,
##                              IMG("/images/top_bar/"+loicon, width=lowidth,
##                                  height=32,
##                                  alt=lotext, border="0"))))
        hpage.td()
        hpage.a(e.img(src="/images/top_bar/"+loicon,width=lowidth ,height=32,border=0,alt=lotext),href=logout)
        hpage.td.close()

##    TDList.append(TD(Div(IMG("/images/top_bar/right.jpg", width=3, height=32)),
##                     width="3"))
    hpage.td(e.div(e.img(src="/images/top_bar/right.jpg", width="3", height="32")),width=3)
    
##    top_table.append(t_body + TDList)

    hpage.tr.close()
    hpage.table.close()

    # print top_table

    

##    cat_top_table = TableLite(width="100%", border="0", cellspacing="0",
##                           cellpadding="0", height="7")
##
##    
##    cat_top_table.append(TR(TD(IMG("/images/top_bar/shadow.jpg",width=8, height=7),
##                           background="/images/top_bar/shadow_bg.jpg",
##                           nowrap="nowrap")))

    hpage.table(width="100%", border="0", cellspacing="0",
                           cellpadding="0", height="7")
    hpage.tr()
    hpage.td(e.img(src="/images/top_bar/shadow.jpg",width=8, height=7),
             background="/images/top_bar/shadow_bg.jpg",nowrap="nowrap")
    hpage.tr.close()
    hpage.table.close()

    # print cat_top_table
    print hpage
   

    catnames = read_file(os.path.join(config_directory, "webmin.catnames"))
    cats = {}

    for module in msc_modules:
        c = module.get("category", "")
        if cats.has_key(c):
            continue
        if catnames.has_key(c):
            cats[c] = catnames[c]
        elif text.has_key("category_%s" % c):
            cats[c] = text["category_%s" % c]
        else:
            mtext = load_language(module["dir"])
            if mtext.has_key("category_%s" % c):
                cats[c] = mtext["category_%s" % c]
            else:
                c = ""
                module["category"] = ""
                cats[c] = text["category_%s" % c]
    sorted_cats = cats.keys()
    sorted_cats.sort()
    sorted_cats.reverse()

    if 0 == len(cats):
        per = 100
    else:
        per = 100.0 / float(len(cats))

    ## Navigation Bar START ##
    # (Carsten) Mode loose_html for the center tag 
    nav_page = markup.page(mode='loose_html')
       
##    nav_table = TableLite(width="100%", border="0", cellspacing="0",
##                          cellpadding="0", height="57",
##                          background="/images/nav/bg.jpg")
    # (Carsten) The background attribute is not in the final html code with HTMLgen
##    nav_table_body = TR(background="/images/nav/bg.jpg")

    nav_page.table(width="100%", border="0", cellspacing="0",
                          cellpadding="0", height="57",
                          background="/images/nav/bg.jpg")
    nav_page.tr(background="/images/nav/bg.jpg")

##    TDList = [TD(IMG("/images/nav/left.jpg", width=3, height=57),
##                 width="6", nowrap="nowrap")]
    nav_page.td(e.img(src="/images/nav/left.jpg", width="3", height="57"),width="6", nowrap="nowrap")

    for cat in sorted_cats:
        uri = "/?cat=%s" % cat
##        cont = Container()
        nav_page.td(nowrap="nowrap")
        nav_page.center()
        nav_page.a(href=uri)
        if cat in available:
            if "" == cat:
##                cont.append(IMG("/images/cats/others.jpg", width=43, height=44,
##                                        border="0", alt=cat))
                nav_page.img(src="/images/cats/others.jpg",width=43, height=44,
                                        border="0", alt=cat)
            else:
##                cont.append(IMG("/images/cats/%s.jpg" % cat, width=43, height=44,
##                                border="0", alt=cat))
                nav_page.img(src="/images/cats/%s.jpg" % cat, width=43, height=44,
                                border="0", alt=cat)

        else:
##            cont.append(IMG("/images/cats/unknown.jpg", width=43, height=44,
##                            border="0", alt=cat))
            nav_page.img(src="/images/cats/unknown.jpg", width=43, height=44,
                            border="0", alt=cat)

##        cont.append(BR())
##        cont.append(chop_font(cats[cat]))
        nav_page.br()
        # (carsten) : str is needed becaus chop_font might return a HTMLgen/markup instance
        nav_page.add(str(chop_font(cats[cat])))
        
                
##        TDList.append(TD(Center(Href(uri, cont)), nowrap="nowrap"))
        nav_page.a.close()
        nav_page.center.close()
        nav_page.td.close()

##        TDList.append(TD(IMG("/images/nav/sep.jpg", width=17, height=57),
##                         width=17))
        nav_page.td(e.img(src="/images/nav/sep.jpg", width=17, height=57),width=17)

##    TDList.append(TD(Container('&nbsp;'), nowrap="nowrap", width="100%"))
    nav_page.td("&nbsp;",nowrap="nowrap", width="100%")

##    nav_table.append(nav_table_body + TDList)

    nav_page.tr.close()
    nav_page.table.close()

    # UGLY!
    # The reason we replace all "\n" with "" is that Mozilla
    # won't render the menu correctly otherwise. GAAAAH!
    # Note (Carsten) : could be done by a simple change in page class
    
    # print str(nav_table).replace("\n", "")
    print str(nav_page).replace("\n", "")
    
    
##    nav_under_table = TableLite(width="100%", border="0", cellspacing="0",
##                                cellpadding="0",
##                                background="/images/nav/bottom_bg.jpg",
##                                height="4")
##
##    nav_under_table.append(TR()+[TD(IMG("/images/nav/bottom_left.jpg",
##                                        width=3, height=4), width="100%")])

##    print nav_under_table

    nav_under_page = markup.page()
    nav_under_page.table(width="100%", border="0", cellspacing="0",cellpadding="0",
                         background="/images/nav/bottom_bg.jpg",height="4")
    nav_under_page.tr()
    nav_under_page.td(e.img(src="/images/nav/bottom_left.jpg",width=3, height=4),width="100%")
    nav_under_page.tr.close()
    nav_under_page.table.close()


##    tab_under_modcats = TableLite(width="100%", border="0",
##                                  cellspacing="0", cellpadding="0",
##                                  background="/images/nav/bottom_shadow2.jpg")
    nav_under_page.table(width="100%", border="0",cellspacing="0",
                         cellpadding="0",background="/images/nav/bottom_shadow2.jpg")

    # ---new/changed display (user) preference tab
##    tab_under_modcats_prefs=None
##    tab_under_modcats_help=None
    ptab_under_modcats_prefs=None
    ptab_under_modcats_help=None
    # woraround because "if ptab_under_modcats_help" causes an error when it is actually not None
    isptab_under_modcats_prefs=False
    isptab_under_modcats_help=False
    
    
    if help:        
        if type(help) == types.ListType:
            helplink =  hlink(text["header_help"], help[0], help[1])
        else:
            helplink = hlink(text["header_help"], help)
##        tab_under_modcats_help = TableLite(border="0",cellspacing="0", cellpadding="0")
##        tab_under_modcats_help.append(TR() + [TD(IMG("/images/tabs/left.jpg", width=12, height="21"),background="/images/tabs/bg.jpg")]+\
##                                [TD(Code(helplink),background="/images/tabs/bg.jpg")]+\
##                                [TD(IMG("/images/tabs/right.jpg", width=15, height="21"),background="/images/tabs/bg.jpg")])    
##        tab_under_modcats_help.append(TR() + [TD(IMG("/images/tabs/right_bottom.jpg", width=12, height="4"))]+\
##                                [TD(IMG("/images/tabs/bottom.jpg", width=17, height="4"),background="/images/tabs/bottom.jpg")]+\
##                                [TD(IMG("/images/tabs/left_bottom.jpg", width=15, height="4"))])

        ptab_under_modcats_help = markup.page()
        ptab_under_modcats_help.table(border="0",cellspacing="0", cellpadding="0")
        ptab_under_modcats_help.tr()
        ptab_under_modcats_help.td(e.img(src="/images/tabs/left.jpg", width=12, height="21"),
                                   background="/images/tabs/bg.jpg")
        # TODO (carsten) : Check what HTMLgen Code(helplink) does - Update: already done?
        ptab_under_modcats_help.td(background="/images/tabs/bg.jpg")
        ptab_under_modcats_help.code(helplink)
        ptab_under_modcats_help.td.close()
        ptab_under_modcats_help.td(e.img(src="/images/tabs/right.jpg", width=15, height="21"),
                                   background="/images/tabs/bg.jpg")
        ptab_under_modcats_help.tr.close()

        ptab_under_modcats_help.tr()
        ptab_under_modcats_help.td(e.img(src="/images/tabs/right_bottom.jpg", width=12, height="4"))
        ptab_under_modcats_help.td(e.img(src="/images/tabs/bottom.jpg", width=17, height="4"),
                                   background="/images/tabs/bottom.jpg")
        ptab_under_modcats_help.td(e.img(src="/images/tabs/left_bottom.jpg", width=15, height="4"))
        ptab_under_modcats_help.tr.close()
        ptab_under_modcats_help.table.close()
        isptab_under_modcats_help = True
        
    
    if config:
        access = get_module_acl();
        if not access.get("noconfig") and not noprefs:
            if user_module_config_directory:
                cprog = "uconfig.cgi"
            else:
                cprog = "config.cgi"            
    
            uri='%s/%s?%s' % (gconfig.get("webprefix", ""), cprog, module_name)	    
##            tab_under_modcats_prefs = TableLite(border="0",cellspacing="0", cellpadding="0")
##            tab_under_modcats_prefs.append(TR() + [TD(IMG("/images/tabs/left.jpg", width=12, height="21"),background="/images/tabs/bg.jpg")]+\
##                                    [TD(Href(uri,text["header_config"]),background="/images/tabs/bg.jpg")]+\
##                                    [TD(IMG("/images/tabs/right.jpg", width=15, height="21"),background="/images/tabs/bg.jpg")])    
##            tab_under_modcats_prefs.append(TR() + [TD(IMG("/images/tabs/right_bottom.jpg", width=12, height="4"))]+\
##                                    [TD(IMG("/images/tabs/bottom.jpg", width=17, height="4"),background="/images/tabs/bottom.jpg")]+\
##                                    [TD(IMG("/images/tabs/left_bottom.jpg", width=15, height="4"))])

            ptab_under_modcats_prefs = markup.page()
            ptab_under_modcats_prefs.table(border="0",cellspacing="0", cellpadding="0")
            ptab_under_modcats_prefs.tr()
            ptab_under_modcats_prefs.td(e.img(src="/images/tabs/left.jpg", width=12, height="21"),
                                        background="/images/tabs/bg.jpg")
            ptab_under_modcats_prefs.td(e.a(text["header_config"],href=uri),background="/images/tabs/bg.jpg")
            ptab_under_modcats_prefs.td(e.img(src="/images/tabs/right.jpg",width=15, height="21"),
                                        background="/images/tabs/bg.jpg")
            ptab_under_modcats_prefs.tr.close()
            ptab_under_modcats_prefs.tr()
            ptab_under_modcats_prefs.td(e.img(src="/images/tabs/right_bottom.jpg", width=12, height="4"))
            ptab_under_modcats_prefs.td(e.img(src="/images/tabs/bottom.jpg", width=17, height="4"),
                                        background="/images/tabs/bottom.jpg")
            ptab_under_modcats_prefs.td(e.img(src="/images/tabs/left_bottom.jpg", width=15, height="4"))
            ptab_under_modcats_prefs.tr.close()
            ptab_under_modcats_prefs.table.close()
            isptab_under_modcats_prefs=True

##    tab_under_modcats_inner = TableLite(width="100%", border="0",
##                                  cellspacing="0", cellpadding="0",
##                                  background="/images/nav/bottom_shadow2.jpg")
##    tab_under_modcats_inner.append(TR() + [TD(IMG("/images/nav/bottom_shadow.jpg", width=43, height="9"))])

    

    # workariund, see above
    # if ptab_under_modcats_prefs or ptab_under_modcats_help:
    if isptab_under_modcats_prefs or isptab_under_modcats_help:
##        tabTR = TR()
        nav_under_page.tr()
        if isptab_under_modcats_help==True:
##            tabTR = tabTR + [TD(tab_under_modcats_help)]
            nav_under_page.td(str(ptab_under_modcats_help))
        if isptab_under_modcats_prefs==True:
##            tabTR = tabTR + [TD(tab_under_modcats_prefs)]
            nav_under_page.td(str(ptab_under_modcats_prefs))            
##        tabTR = tabTR + [TD(tab_under_modcats_inner,background="/images/nav/bottom_shadow2.jpg",width="100%",nowrap="nowarp",valign="top")]
        nav_under_page.td(background="/images/nav/bottom_shadow2.jpg",width="100%",nowrap="nowarp",valign="top")
        # tab_under_modcats_inner 
        nav_under_page.table(width="100%", border="0",cellspacing="0", cellpadding="0",
                         background="/images/nav/bottom_shadow2.jpg")
        nav_under_page.tr()
        nav_under_page.td(e.img(src="/images/nav/bottom_shadow.jpg", width=43, height="9"))
        nav_under_page.tr.close()
        nav_under_page.table.close()
        # end tab_under_modcats_inner
        nav_under_page.td.close()
        nav_under_page.tr.close()

##        tab_under_modcats(tabTR)
        # tab_under_modcats.append(TR() + [TD(tab_under_modcats_prefs)]+ [TD(tab_under_modcats_inner,background="/images/nav/bottom_shadow2.jpg",width="100%",nowrap="nowarp",valign="top")])	
    else:
##        tab_under_modcats.append(TR() + [TD(IMG("/images/nav/bottom_shadow.jpg", width=43, height="9"))])
        nav_under_page.tr()
        nav_under_page.td(e.img(src="/images/nav/bottom_shadow.jpg", width=43, height="9"))
        nav_under_page.tr.close()
    nav_under_page.table.close()
    
##    print tab_under_modcats

    
##    print "<br>"
    nav_under_page.br()
    print nav_under_page
    # ----end new display (user) preference tab


    if not nowebmin:
        title = title.replace("&auml;", "ä")
        title = title.replace("&ouml;", "ö")
        title = title.replace("&uuml;", "ü")
        title = title.replace("&nbsp;", " ")

        print "<!-- ================== New Markup code =================== -->"
##        title_table = TableLite(border=0, cellpadding=0, cellspacing=0,
##                                width="95%", align="center")
##        inr_tt = TableLite(border=0, cellpadding=0, cellspacing=0, height=20)
##        inr_tt_body = TR()
##        inr_tt_TDList = [TD(IMG("/images/tabs/blue_left.jpg", width=13,
##                                height=22), bgcolor="#bae3ff"),
##                         TD(Strong(title), bgcolor="#bae3ff"),
##                         TD(IMG("/images/tabs/blue_right.jpg", width=13,
##                                height=22), bgcolor="#bae3ff")]
##        inr_tt.append(inr_tt_body + inr_tt_TDList)
##        title_table.append(TR(TD(inr_tt)))

        ptitle_table = markup.page()
        ptitle_table.table(border=0, cellpadding=0, cellspacing=0,
                                width="95%", align="center")
        ptitle_table.tr()
        ptitle_table.td()
        ptitle_table.table(border=0, cellpadding=0, cellspacing=0, height=20)
        ptitle_table.tr()
        ptitle_table.td(e.img(src="/images/tabs/blue_left.jpg", width=13,height=22),bgcolor="#bae3ff")
        ptitle_table.td(e.strong(title),bgcolor="#bae3ff")
        ptitle_table.td(e.img(src="/images/tabs/blue_right.jpg", width=13,height=22),bgcolor="#bae3ff")
        ptitle_table.tr.close()
        ptitle_table.table.close()
        ptitle_table.td.close()
        ptitle_table.tr.close()
        ptitle_table.table.close()        

##        print title_table
        print ptitle_table
        print "<!-- ================== New Markup code end =================== -->"
        theme_prebody()
コード例 #24
0
ファイル: log_parsing.py プロジェクト: songshen06/NSXTS
def main():
    path = os.getcwd()
    use_count
    print('-' * 80) 
    NSX_Version = get_nsx_version(path)
    print 'NSX version is %s \n' %NSX_Version
    NSX_IP = get_nsx_ip(path)
    print 'NSX manager IP is %s \n' %NSX_IP
    
    vpxa_cfg_list = get_file_list(path,"vpxa.cfg")
    vpxa_cfg = vpxa_cfg_list[0]
    VC_ip = get_vc_ip(vpxa_cfg)
    VC_version = get_vc_version(path)
    print 'vCenter IP is  %s  \n' %VC_ip
    print 'vCenter version is %s \n' %VC_version
    print 'Please check product matrix \n'
    print 'https://www.vmware.com/resources/compatibility/sim/interop_matrix.php \n'
    
    vdr_info_list = get_file_list(path,"dump-vdr-info.sh.txt")
    vxlan_info_list = get_file_list(path,"dump-vxlan-info.py.txt")
    vmk_info_list = get_file_list(path,"esxcfg-vmknic_-l.txt")
    ## Get VC IP from esxi bundle
    vpxa_cfg_list = get_file_list(path,"vpxa.cfg")
    if len(vpxa_cfg_list) > 0:
        get_vc_ip(vpxa_cfg_list[0])
    num_file = len(vdr_info_list)
   

    for i in range(num_file):
        page = markup.page( )
        page.init( title="NSX log ", 
                   header="NSX vxlan info ", 
                   footer="I will develop more ....." )
        page.style("""
                    body {
                            background-color: AliceBlue ;
                        }

                        table {
                                font-family: arial, sans-serif;
                                border-collapse: collapse;
                                width: 70%;
                                }

                        td, th {
                                    border: 1px solid #dddddd;
                                    text-align: left;
                                    padding: 8px;
                                }

            tr:nth-child(even) {
                                background-color: #dddddd;
                                }
                        p {
                            font-family: verdana;
                            font-size: 20px;
                            }
                    """)
        page.h1
        esx_info = get_vmk_info(vmk_info_list[i])   # esxi_info is a list  [hostname,vmk0,vxlan_vmk]
        
        page.br()
        page.p(esx_info)
        page.br()
        
        controller_mapping_dict = get_vxlan_info(vxlan_info_list[i]) # this is a dict
        
        for vxlan,controller in controller_mapping_dict.items():
            print('{} {}'.format(vxlan,controller))
        print('-' * 80)
        # create table for vxlan mapping to controller 
        page.div(style="overflow-x:auto;")
        page.table(border="1")
        page.tr()
        page.th('vxlan')
        page.th('controller')
        page.th('status')
        page.tr.close()
        for vxlan,controller in controller_mapping_dict.items():
            page.tr()
            page.td(vxlan)
            page.td(controller)
            page.tr.close()
        page.table.close()
        
        vxlan_list = controller_mapping_dict.keys()    # this a vlxan list
        # create vxlan link table 
        page.br()
        page.table(border="1")
        page.tr()
        page.th('vxlan')
        page.th('vtep')
        page.th('arp')
        page.th('mac')
        page.tr.close()
        for vxlan in vxlan_list:
            page.tr()
            page.td(vxlan)
            page.td(e.a(vxlan+'_vtep',href='#'+vxlan+'_vtep'))
            page.td(e.a(vxlan+'_arp',href='#'+vxlan+'_arp'))
            page.td(e.a(vxlan+'_mac',href='#'+vxlan+'_mac'))
            page.tr.close()
        page.table.close()
    
        vds_name = get_vds_name(vxlan_info_list[i])
       
        for vxlan_num in vxlan_list:
            VTEP = get_vtep_table(vxlan_info_list[i],vds_name,vxlan_num) # this is a list 
            ARP = get_arp_table(vxlan_info_list[i],vds_name,vxlan_num)
            MAC = get_mac_table(vxlan_info_list[i],vds_name,vxlan_num)
            #create vtep,arp,mac
            name_vtep = vxlan_num + '_vtep'
            page.br()
            page.h2(e.a(id=name_vtep))
            page.p(VTEP)
            page.br()
            page.h2(e.a(id=vxlan_num+'_arp'))
            page.p(ARP)
            page.br()
            page.h2(e.a(id=vxlan_num+'_mac'))
            page.p(MAC)
            page.br()
        filename = esx_info[0] +'.html'
    
        h = open(filename,'w')
        h.write(str(page))
        h.close()