Exemple #1
0
def run():
    #
    # all the user preference cgi entry points come here
    #

    # The common page header:
    output.write(common.cgi_header_html)
    output.write(common.page_header())

    #

    form = pandokia.pcgi.form

    # find out whose preferences we are handling
    user = common.current_user()

    if user is None:
        output.write(
            'This web server does not perform authentication, so pandokia does not know about user names.<br>'
        )
        output.write(
            'Using the user name "nobody" for testing, but do not expect it to be useful.<br>'
        )
        user = '******'

    # dispatch this to the relevant subtype
    if 'subtype' in form:
        x = form['subtype'].value
    else:
        x = 'show'

    if x == 'show':
        show(user)
    elif x == 'save':
        if ('newuser' in form) and (user in cfg.admin_user_list):
            if form['submit'].value == 'newuser':
                newuser = form['newuser'].value
                save(newuser)
            else:
                save(user)
        else:
            save(user)
    elif x == 'add_project':
        add_project(user)
    elif x == 'list':
        if user in cfg.admin_user_list:
            list_users()

    if user in cfg.admin_user_list:
        output.write(
            '<p><a href=%s?query=prefs&subtype=list>list all</a></p>' %
            common.get_cgi_name())
        sys_report()
Exemple #2
0
def qid_list():
    import datetime

    print "content-type: text/html\n"
    print common.page_header()

    print "<h1>Interesting QID</h1>"

    input_query = pandokia.pcgi.form_to_dict(pandokia.pcgi.form)

    order_by = 'qid'
    order_dir = 'asc'
    if 'order_by' in input_query:
        x = input_query['order_by'][0]
        if x in ('qid', 'expires', 'username', 'notes'):
            order_by = x
    if 'order_dir' in input_query:
        x = input_query['order_dir'][0]
        if x in ('asc', 'desc'):
            order_dir = x

    def sl(s):
        d = 'asc'
        if order_dir == 'asc':
            d = 'desc'
        return common.selflink({
            'order_by': s,
            'order_dir': d
        },
                               linkmode='qid_list')

    t = text_table.text_table()
    t.define_column("QID", html='<a href=%s>QID</a>' % sl('qid'))
    t.define_column("Expires", html='<a href=%s>expires</a>' % sl('expires'))
    t.define_column("User", html='<a href=%s>username</a>' % sl('username'))
    t.define_column("Notes", html='<a href=%s>notes</a>' % sl('notes'))
    t.set_html_table_attributes("border=1")

    qdict = {}

    c = pdk_db.execute(
        "SELECT qid, expires, username, notes FROM query_id WHERE expires = :1 OR username <> '' OR notes <> '' ORDER BY %s %s"
        % (order_by, order_dir), (pandokia.never_expires, ))
    row = 0
    for x in c:

        v = int(x[0])
        qdict['qid'] = v
        t.set_value(row,
                    0,
                    v,
                    html='<a href="%s">%s</a>' %
                    (common.selflink(qdict, linkmode="summary"), v))

        try:
            v = int(x[1])
            if v == pandokia.never_expires:
                v = 'never'
            else:
                v = str(datetime.date.fromtimestamp(v))
        except:
            v = '?'
        t.set_value(row, 1, v)

        v = str(x[2])
        t.set_value(row, 2, v, html=cgi.escape(v))

        if x[3] is None:
            v = ''
        else:
            v = str(x[3])
        t.set_value(row, 3, v, html='<pre>' + cgi.escape(v) + '</pre>')

        row = row + 1

    print t.get_html()
Exemple #3
0
def linkout( ) :
    #
    # linking out of the test walker and into the test display
    #
    # This does not actually display anything.  It makes an entry in the
    # poorly named "query" table database that contains a list of test
    # results, then redirects to the cgi that displays that.
    #
    # It is html safe because it only outputs values that are created here.

    output = sys.stdout

    output.write(common.cgi_header_html)
    output.write(common.page_header())

    # don't issue the redirect for internet explorer
    if 'MSIE' in os.environ['HTTP_USER_AGENT'] :
        output.write('<p>Internet Explorer fumbles the redirect.  Click the link below.</p>')
        no_redirect = 1
    else :
        no_redirect = 0

    #
    # gather up all the expected parameters
    #

    form = pandokia.pcgi.form

    context = get_form(form,'context',  '*')
    host    = get_form(form,'host',     '*')
    test_run= get_form(form,'test_run', '*')
    project = get_form(form,'project',  '*')
    status  = get_form(form,'status',   '*')
    attn    = get_form(form,'attn',     '*')
    oldqid  = get_form(form,'qid',      None)
    test_name=get_form(form,'test_name','*')

    # handle special names of test runs
    test_run = common.find_test_run(test_run)

    # create a new qid - this is the identity of a list of test results

    now = time.time()
    expire = now+common.cfg.default_qid_expire_days*86400

    if pdk_db.next :
        newqid = pdk_db.next('sequence_qid')
        c = pdk_db.execute("INSERT INTO query_id ( qid, time, expires ) VALUES ( :1, :2, :3 ) ", 
            ( newqid, now, expire ) )
    else :
        c = pdk_db.execute("INSERT INTO query_id ( time, expires ) VALUES ( :1, :2 ) ", 
            ( now, expire ) )
        newqid = c.lastrowid

    print "content-type: text/plain\n"
    print "QID ",newqid
    pdk_db.commit()

    if oldqid is not None :
        print "WITH QID=",oldqid
        more_where = ' qid = %d AND result_scalar.key_id = query.key_id ' % int(oldqid)
    else :
        more_where = None

    # find a list of the tests
    where_text, where_dict = pdk_db.where_dict([ 
        ('test_name', test_name),
        ('test_run', test_run), 
        ('project', project),
        ('host', host),
        ('context', context),
        ('status', status),
        ('attn', attn),
        ], more_where = more_where )

    if oldqid is None :
        c1 = pdk_db.execute("SELECT key_id FROM result_scalar "+where_text, where_dict )
    else :
        c1 = pdk_db.execute("SELECT result_scalar.key_id FROM result_scalar, query %s" % where_text, where_dict )

    a = [ ]
    for x in c1 :
        (key_id, ) = x
        a.append(key_id)

    # Enter the test results with the current qid, then redirect to
    # displaying the qid.  That will get the user the list of all tests.

    # (This used to link directly to the detail display if there was only one,
    # but that makes the checkboxes unavailable in that case.)

    for key_id in a :
        pdk_db.execute("INSERT INTO query ( qid, key_id ) VALUES ( :1, :2 ) ", (newqid, key_id ) )
    pdk_db.commit()

    url = pandokia.pcgi.cginame + ( '?query=summary&qid=%s' % newqid )

    if form.has_key('add_attributes') :
        x = int(form['add_attributes'].value)
        if x :
            url += ('&show_attr=%d'%x)

    if not no_redirect :
        output.write(
            "<html><head><meta http-equiv='REFRESH' content='0;%s'>\n</head><body>\n" % url
            )
    output.write( 
        "redirecting: <a href='%s'> qid = %s </a><br>\n" % ( url, newqid )
        )
Exemple #4
0
def treewalk ( ) :

    form = pandokia.pcgi.form

    output = sys.stdout

    output.write(common.cgi_header_html)

    output.write(common.page_header())

    #
    # gather up all the expected parameters
    #

    if form.has_key("test_name") :
        test_name = form["test_name"].value
        if test_name == '' :
            test_name = '*'
    else :
        test_name = "*"

    context = get_form(form,'context',  '*')
    host    = get_form(form,'host',     '*')
    test_run= get_form(form,'test_run', '*')
    project = get_form(form,'project',  '*')
    status  = get_form(form,'status',   '*')
    attn    = get_form(form,'attn',     '*')
    qid     = get_form(form,'qid',      None)

    debug_cmp = get_form(form,'debug_cmp', 0)

    # look for input from the compare form
    cmp_test_run = get_form(form,'cmp_test_run', None )
    cmp_context  = get_form(form,'cmp_context',  None )
    cmp_host     = get_form(form,'cmp_host',     None )

    test_run     = common.find_test_run(test_run)
    if cmp_test_run :
        cmp_test_run = common.find_test_run(cmp_test_run)

    # look for whether the query asks for a comparison; we assume not
    comparing = 0
    if 'compare' in form :
        # ok, it explicitly says one of the 3 comparison values
        comparing = 1
        x = get_form(form,'compare','0')

        if x == '' or x == '0' or x.startswith('Turn Off') :
            # if it is a special value that ends the compare, 
            comparing = 0

        if x.startswith('Reverse') :
            t = cmp_test_run
            cmp_test_run = test_run
            test_run = t

            t = cmp_host
            cmp_host = host
            host = t

            t = cmp_context
            cmp_context = context
            context = t

            comparing = 1


    #
    # query values we will always pass back to the next instantion of ourself
    #

    query = { 
        'test_name' : test_name,
        'test_run' : test_run,
        'project' : project,
        'host': host,
        'status': status,
        'attn': attn,
        'context':context,
        'compare' : comparing,
    }

    if qid is not None :
        qid = int(qid)
        query['qid']= qid

    if cmp_test_run is not None :
        query['cmp_test_run'] =  cmp_test_run

    if cmp_context is not None :
        query['cmp_context'] = cmp_context

    if cmp_host is not None :
        query['cmp_host'] = cmp_host


    #
    # show the narrowing parameters
    #

    header_table = text_table.text_table()
    header_table.set_html_table_attributes( ' style="font-size: large; font-weight: bold" ' )

    row = 0

    #
    # if a test_run is selected, show the test_run here
    # include a link to clear the test_run selection
    #

    if test_run != "*" :
        lquery = copy.copy(query)
        lquery["test_run"] = "*"
        test_run_line = "<h2>%s = %s &nbsp;&nbsp;&nbsp; %s &nbsp;&nbsp;&nbsp; %s &nbsp;&nbsp;&nbsp; %s</h2>\n"
        header_table.set_value( row, 0, 'test_run' )
        header_table.set_value( row, 1, '=' )
        header_table.set_value( row, 2, cgi.escape(test_run) )
        header_table.set_value( row, 3, html=common.self_href(lquery,"treewalk",remove_arrow) )
        tmp2 = common.run_previous(None,test_run)
        tmp3 = common.run_next(None,test_run)

        if tmp2 is not None :
            lquery["test_run"] = tmp2
            tmp2 = common.self_href(lquery,"treewalk"," (%s)"%tmp2 )
            header_table.set_value( row, 4, html=tmp2 )
        else :
            tmp2 = ""

        if tmp3 is not None :
            lquery["test_run"] = tmp3
            tmp3 = common.self_href(lquery,"treewalk"," (%s)"%tmp3 )
            header_table.set_value( row, 5, html=tmp3 )
        else :
            tmp3 = ""

        row = row + 1

    for var, label in [
        ( 'project', 'project' ),
        ( 'host', 'host' ),
        ( 'context', 'context' ),
        ( 'status', 'status' ),
        ] :

        if query[var] != '*' :
            lquery = copy.copy(query)
            lquery[var] = "*"
            header_table.set_value( row, 0, label )
            header_table.set_value( row, 1, '=' )
            header_table.set_value( row, 2, cgi.escape(query[var]) )
            header_table.set_value( row, 3, html=common.self_href(lquery,"treewalk",remove_arrow) )
            row = row + 1

    if qid is not None :
        header_table.set_value( row, 0, 'QID' )
        header_table.set_value( row, 2, str(qid) )
        row = row + 1


    print header_table.get_html()

    ### start of "Test Prefix: line"

    #
    # Here is the actual tree browser for test names.  we are at some
    # prefix (specified by test_name), walking down the tree
    #

    output.write( "<h2>Test Prefix: ")

    #
    # show the prefix.  each component of the prefix is a link back
    # up to that level
    #
    lquery = copy.copy(query)

    # get a list of the levels
    t = test_name
    lst = [ ]
    while 1 :
        y = re.search("[/.]",t)
        if not y :
            break
        lst.append(t[0:y.start()+1])
        t = t[y.start()+1:]

    # display each level with the link
    t = ""
    for x in lst :
        t = t + x
        lquery["test_name"] = t+"*"
        line = common.self_href(lquery, 'treewalk', cgi.escape(x))
        output.write(line)

    # if we are not at the very top, also include a link that gets us back
    # to "" (i.e. no prefix at all)
    if test_name != "*" :
        lquery["test_name"]=""
        output.write("&nbsp;&nbsp;&nbsp;")
        output.write(common.self_href(lquery,"treewalk",remove_arrow))
        output.write("&nbsp;")

    output.write("</h2>\n")

    ### end of "Test Prefix: line"

    ### offer the form to compare with other runs
    print cmp_form(query, comparing)
    print "<p>"

    ### show the table

    # "show all" line before the table

    lquery = copy.copy(query)
    if comparing :
        t = 'show all (not just different)'
    else :
        t = 'show all'
    show_all_line = common.self_href(lquery, 'treewalk.linkout', t) + ' - '
    lquery['add_attributes'] = 1
    show_all_line += common.self_href(lquery, 'treewalk.linkout', 'with attributes')
    lquery['add_attributes'] = 2
    show_all_line += ' - ' + common.self_href(lquery, 'treewalk.linkout', 'Column Selector')
    output.write(show_all_line)
    output.write("<br>")

    ### begin table of test results


    # Gather the names of the rows

    prefixes = collect_prefixes( query )

    # create the table to display; if comparing, we want a link for
    # every table cell; this is because we don't know later which cells
    # we will need to have a link on
    table = collect_table( prefixes, query, comparing )

    if comparing :
        query_2 = query.copy()
        query_2['test_run'] = cmp_test_run
        query_2['host'] = cmp_host
        query_2['context'] = cmp_context
        t2 = collect_table( prefixes, query_2, 1 )
    
        # This part is very delicate.  We know that both tables
        # have the same dimensions because the parameters that we
        # used to deterimine the number of rows/cols are the same;
        # from that, we also know that the meaning of each cell is
        # the same.
        #
        # So, for each cell, if it appears to contain an int in
        # both cells, subtract them.
        #
        # We know that column 1 contains the test name, so we don't
        # even try to handle those.
        #
        for row in range(0, len(table.rows) ):
            for col in range(1,len(table.rows[row].list)) :
                # pick the table cell out of each table
                c1 = table.get_cell(row,col)
                c2 = t2   .get_cell(row,col)

                # see if we can convert both of them to integers.
                # if not, go on to the next cell
                try :
                    c1v = int(c1.text)
                    c2v = int(c2.text)
                except ValueError :
                    continue

                # suppress the link in this cell, but only if both
                # parts of the comparison are zero.  If they are equal,
                # you still might follow the link and see something.
                if c1v == 0 and c2v == 0 :
                    c1.link = None

                # compute the difference and poke the value directly back
                # into the table cell; this preserves the html attributes
                # and such
                diff = c1v - c2v
                if debug_cmp :
                    c1.text="%d - %d = %+d"%(c1v,c2v,diff)
                else :
                    if diff == 0 :
                        c1.text='0'
                    else :
                        c1.text = "%+d"%diff

    ###

    ### If we are comparing to another test run, show which it is.
    
    if comparing:
        

        output.write("<p>Net difference in counts, this - other</p>")


    output.write(table.get_html())

    output.write("<br>")
    output.write(show_all_line)
    output.write("<br>")

    output.flush()

    #
    # if no test_run specified, give an option to choose one (but only from the
    # test_runs that are in the tests specified)
    #

    if 'qid' in query :
        return  # bug: temporary work-around.  the narrow-to query is really slow, but doesn't really help the tree walker in qid mode
        more_where = ' qid = %d AND result_scalar.key_id = query.key_id ' % int(query['qid'])
    else :
        more_where = None

    # bug: This whole thing could happen early.  Then, when you find
    # exactly 1 item in the choices to narrow, you could automatically
    # include that in all the links.
    for field in ( 'test_run', 'project', 'context', 'host' ) :
        if not '*' in query[field] :
            continue
        lquery = { }
        for x in query :
            if query[x] is not None :
                lquery[x] = query[x]
        output.write("<h3>Narrow to %s</h3>" % field)

        tn = test_name
        if not tn.endswith("*") :
            tn = tn + "*" 
        where_text, where_dict = pdk_db.where_dict([ 
            ('test_name', tn),
            ('test_run', test_run), 
            ('project', project),
            ('host', host),
            ('context', context),
            ('status', status),
            ('attn',attn),
            ], more_where )

        if more_where is None :
            c = pdk_db.execute("SELECT DISTINCT %s FROM result_scalar %s GROUP BY %s ORDER BY %s" % ( field, where_text, field, field ), where_dict)
        else :
            c = pdk_db.execute("SELECT DISTINCT %s FROM result_scalar, query %s GROUP BY %s ORDER BY %s" % ( field, where_text, field, field ), where_dict)
        for x, in c :
            if x is None :
                continue
            lquery[field] = x
            output.write("<a href='"+pandokia.pcgi.cginame+"?query=treewalk&"+urllib.urlencode(lquery)+"'>"+x+"</a><br>")


    output.write("")
Exemple #5
0
def run():

    global any_attr

    any_attr = {}

    #
    # gather up all the expected parameters
    #

    input_query = pandokia.pcgi.form_to_dict(pandokia.pcgi.form)

    # print "context-type: text/plain\n\n"

    qid = int(input_query["qid"][0])
    #print qid

    # some fields are the names of submit buttons that we do not look
    # at and that we do not want to accumulate in the URL
    for x in ('x', ):
        if x in input_query:
            del input_query[x]

    #
    if 'cmp_run' in input_query:
        cmp_run = input_query["cmp_run"][0]
        if cmp_run == '':
            cmp_run = 'daily_yesterday'
        cmp_run = common.find_test_run(cmp_run)
    else:
        cmp_run = ''

    cmptype = 'c'

    if 'x_submit' in input_query:
        x = input_query['x_submit'][0]
        if x == 'same':
            cmptype = 's'
        elif x == 'different':
            cmptype = 'd'

    show_attr = 0
    if "show_attr" in input_query:
        show_attr = int(input_query["show_attr"][0])

        if show_attr == 2:
            return column_selector(input_query)

    # generate a link to click on to sort.  use sort_link+"thing" to sort
    # on thing.  thing must be "+xyz" or "-xyz" to sort on column xyz
    # either ascending or descending.
    #
    sort_query = {}
    for x in input_query:
        if x != 'sort' and x != 'query':
            sort_query[x] = input_query[x]

    sort_link = common.selflink(sort_query, 'summary') + "&sort="

    # Sorting is a little weak right now.  We only generate links to sort
    # ascending, and we don't draw little arrows or anything.  We really
    # need for text_table to offer html text for the column heading
    # instead of just link text.

    # generate the table - used to be written inline here
    result_table, all_test_run, all_project, all_host, all_context, rowcount, different = get_table(
        qid, sort_link, cmp_run, cmptype, show_attr)

    # suppressing columns that the user did not ask for
    if 'S' in input_query:
        column_select_values = input_query['S']
        column_select_values = set(column_select_values)
        for x in result_table.colmap:
            if x in ('line #', 'checkbox'):
                continue
            if not x in column_select_values:
                result_table.suppress(x)
    else:
        column_select_values = set([x for x in result_table.colmap])

    ## select output format

    if pandokia.pcgi.output_format == 'html':
        # HTML OUTPUT

        print "content-type: text/html\n\n"

        print common.page_header()

        #
        # main heading
        #

        output.write("<h1>Test summary</h1>")

        #
        #  Offer to compare to a previous run
        #
        # should we make clickable links of other runs or a drop list?  It
        # would be nice, but I discoverd that finding the list would slow
        # this cgi a _lot_
        output.write("""
    Compare to:
    <form action=%s id=compare_form name=compare_form>
    <input type=hidden name=qid value='%d'>
    <input type=hidden name=show_attr value='%d'>
    <input type=hidden name=query value='summary'>
    <input type=text name=cmp_run value='%s'>
    <br>
    <input type=submit name=x_submit value='compare'>
    <input type=submit name=x_submit value='same'>
    <input type=submit name=x_submit value='different'>
    </form>
    """ % (pandokia.pcgi.cginame, qid, show_attr, cgi.escape(cmp_run)))

        #
        output.write("""
    <form action=%s id=attribute_form name=attribute_form>
    <input type=hidden name=qid value=%d>
    <input type=hidden name=show_attr value=1>
    <input type=hidden name=query value=summary>
    <input type=hidden name=cmp_run value='%s'>
    <input type=submit name=x_submit value='Add Attributes'>
    </form>
    """ % (pandokia.pcgi.cginame, qid, cgi.escape(cmp_run)))

        qid_block(qid)

        # the link to jump in to the tree walker using this qid
        qdict = {"qid": qid}
        output.write("<a href='%s'>Tree walk this QID </a>, " %
                     common.selflink(qdict, linkmode="treewalk"))

        # the link to do and/or on qids
        qdict = {"qid": qid}
        output.write("<a href='%s'>Edit this QID </a>, " %
                     common.selflink(qdict, linkmode="qid_op"))

        # the link to the column selector
        qdict = input_query.copy()
        qdict['show_attr'] = 2
        del qdict['query']
        output.write('<a href="%s">Column Selector</a>' %
                     common.selflink(qdict, linkmode="summary"))

        # offer other output formats
        output.write("<br>Other formats: ")
        qdict = input_query.copy()
        del qdict['query']
        qdict['format'] = 'csv'
        output.write("<a href='%s'>CSV</a> " %
                     common.selflink(qdict, linkmode="summary"))
        qdict['format'] = 'rst'
        output.write("<a href='%s'>RST</a> " %
                     common.selflink(qdict, linkmode="summary"))
        qdict['format'] = 'awk'
        output.write("<a href='%s'>TAB</a> " %
                     common.selflink(qdict, linkmode="summary"))
        output.write("<br>\n")

        # suppose you have
        #   d = { 'A' : 1 }
        # how do you find out the name of the single index value?
        #   x = [tmp for tmp in d]
        # makes a list of all the index values
        #   [tmp for tmp in d][0]
        # is the first (and only) value in that list

        if len(all_test_run) == 1:
            result_table.suppress("test_run")
            output.write("<h3>test_run: " +
                         cgi.escape([tmp
                                     for tmp in all_test_run][0]) + "</h3>")
        if len(all_project) == 1:
            result_table.suppress("project")
            output.write("<h3>project: " +
                         cgi.escape([tmp for tmp in all_project][0]) + "</h3>")
        if len(all_host) == 1:
            result_table.suppress("host")
            output.write("<h3>host: " +
                         cgi.escape([tmp for tmp in all_host][0]) + "</h3>")
        if len(all_context) == 1:
            result_table.suppress("context")
            output.write("<h3>context: " +
                         cgi.escape([tmp for tmp in all_context][0]) + "</h3>")

        # suppressing the columns that are the same for every row
        same_table = suppress_attr_all_same(result_table, column_select_values)

        if same_table.get_row_count() > 0:
            output.write("<ul><b>attributes same for all rows:</b>")
            output.write(same_table.get_html())
            output.write("</ul><br>")

        if 'sort' in input_query:
            sort_order = input_query["sort"][0]
        else:
            sort_order = 'Utest_name'

        reverse_val = sort_order.startswith("D")

        result_table.set_sort_key(sort_order[1:], float)

        result_table.sort([sort_order[1:]], reverse=reverse_val)
        rows = len(result_table.rows)
        for i in range(0, rows):
            result_table.set_value(i, "line #", i + 1)

        output.write('''
    <script language=javascript type='text/javascript'>
    
        var flag_ok_clicked=false;
    
        function validate_flag_ok()
        {
            var comment = document.forms["testform"]["ok_comment"].value;

            if (flag_ok_clicked == true)
            {
                if (comment == "")
                {
                    alert("Doh!  You forgot to comment!");
                    flag_ok_clicked = false;
                    return false;
                }
            }
            return true;
        }
    
        function set_all(value)
            {
            len = document.testform.elements.length;
            ele = document.testform.elements;
            for (n=0; n<len; n++)
                ele[n].checked=value;
            }
        function set_range(value)
            {
            begin=document.getElementById("begin").value-1;
            end=document.getElementById("end").value-0;
            ele=document.testform.elements;
            for(n=begin; n<end; n++)
                ele[n].checked=value;
            }
        function toggle(value)
            {
            len = document.testform.elements.length;
            ele = document.testform.elements;
            for (n=0; n<len; n++)
                ele[n].checked= ! ele[n].checked;
            }
        function condclear(name)
            {
            n = document.getElementById(name);
            if ( n.value.substr(0,1) == '*' )
                n.value='';
            }
    </script>
    ''')

        # show the table, which contains a form
        output.write('''
        <form action=%s method=post name=testform onsubmit="return validate_flag_ok();">
        ''' % (pandokia.pcgi.cginame, ))

        # alter the column headers - violates the interface of text_table
        # for x in result_table.colmap :
        #     n = result_table.colmap[x]
        #     t = result_table.titles[n]
        #     result_table.title_html[n] = '<input type=checkbox name=S value=%s><br>'%t + t

        output.write(result_table.get_html(color_rows=5))
        output.write('''
        <input type=hidden name=query value='action'>
        <input type=hidden name=qid value=%d>
        ''' % (qid, ))
        output.write('Actions:<br>')
        output.write(
            """<input type=text name=begin id=begin value="*Begin line" onfocus='condclear("begin")'size=10> """
        )
        output.write(
            """<input type=text name=end id=end value="*End line" onfocus='condclear("end")' size=10> """
        )
        output.write(
            '<input type=button name="setrange" value="Set Range" onclick="set_range(true)">'
        )
        output.write('<br>')
        output.write(
            '<input type=button name="setall"   value="Select All"   onclick="set_all(true)">'
        )
        output.write(
            '<input type=button name="clearall" value="Clear All" onclick="set_all(false)">'
        )
        output.write(
            '<input type=button name="clearall" value="Toggle"    onclick="toggle()">'
        )
        output.write('<br>')
        output.write('<input type=submit name="action_remove" value="Remove">')
        output.write('<input type=submit name="action_keep"   value="Keep">')
        output.write(' on this report page<br>')

        output.write(
            '<input type=submit name="action_flagok" value="Flag OK" onclick="flag_ok_clicked = true;">'
        )
        output.write(
            '<input type=submit name="action_flagok_rem" value="Flag OK + Remove">'
        )
        output.write(
            ' with comment: <input type=text name=ok_comment value="" size=30><br>'
        )

        output.write(
            '<input type=submit name="action_cattn" value="Clear Attn">')
        output.write(
            '<input type=submit name="action_sattn" value="Set Attn"><br>')
        output.write(
            '<input type=submit name="not_expected" value="Not Expected"> in <input type=text name=arg1 value="%" size=10> test runs'
        )
        output.write('</form>')

        output.write("<br>rows: %d <br>" % rowcount)
        if cmp_run != "":
            output.write("different: %d <br>" % different)

        qdict = {"qid": qid}
        output.write("<a href='" + common.selflink(qdict, linkmode="detail") +
                     "'>")
        output.write("detail of all</a>")
        return

        # end HTML

    elif pandokia.pcgi.output_format == 'csv':
        # CSV OUTPUT
        result_table.suppress('checkbox')
        result_table.suppress('line #')
        print "content-type: text/plain\n\n"
        print result_table.get_csv(headings=1)

    elif pandokia.pcgi.output_format == 'rst':
        # RST OUTPUT
        result_table.suppress('checkbox')
        result_table.suppress('line #')
        print "content-type: text/plain\n\n"
        print result_table.get_rst(headings=1)

    elif pandokia.pcgi.output_format == 'awk':
        # AWK OUTPUT
        result_table.suppress('checkbox')
        result_table.suppress('line #')
        print "content-type: text/plain\n\n"
        print result_table.get_awk(headings=1)
Exemple #6
0
def column_selector(input_query):

    qid = int(input_query["qid"][0])
    print "content-type: text/html\n\n"

    # page header
    print common.page_header()
    print "<h1>Column Selector</h1>"
    qid_block(qid)

    # these columns are common to every test
    l0 = [
        'runner', 'attn', 'test_run', 'project', 'host', 'context',
        'test_name', 'contact', 'diff', 'other', 'stat', 'start', 'duration'
    ]

    # make diff, other only required when compare ?
    # compare totally loses the column selections

    # get the names of the attributes
    c = pdk_db.execute(
        "SELECT DISTINCT result_tda.name FROM result_tda, query WHERE query.qid = :1 AND query.key_id = result_tda.key_id",
        {'1': qid})
    l1 = ['tda_' + x for x, in c]

    c = pdk_db.execute(
        "SELECT DISTINCT result_tra.name FROM result_tra, query WHERE query.qid = :1 AND query.key_id = result_tra.key_id",
        {'1': qid})
    l2 = ['tra_' + x for x, in c]

    #  all the column names
    col_list = l0 + sorted(l1) + sorted(l2)

    # list of the column names that are initially checked
    column_select_values = ['test_name', 'stat']
    if 'S' in input_query:
        column_select_values += input_query['S']
    column_select_values = set(column_select_values)

    # buttons at the top of the form
    output.write(
        '<form action=%s method=get name=colselectform id=colselectform>' %
        pandokia.pcgi.cginame)
    output.write(column_selector_buttons)

    # show each check box
    for t in col_list:
        if t in column_select_values:
            checked = ' checked '
        else:
            checked = ''
        output.write(
            '<label><input type=checkbox name=S %s value=%s>%s</label><br>' %
            (checked, urllib.quote(t), urllib.quote(t)))

    # all the other parameters that got us here go as hiddens
    for x in input_query:
        if not x in exclude_cgi_params_from_selector:
            for y in input_query[x]:
                output.write('<input type=hidden name=%s value=%s>' %
                             (x, urllib.quote(y)))
    output.write('<input type=hidden name=show_attr value=1>')

    # buttons at the bottom of the form
    output.write(column_selector_buttons)
    output.write('</form>')

    # javascript for all the buttons
    output.write("""
<script type="text/javascript">

    function vis_toggle()
        {
        len = document.colselectform.S.length;
        ele = document.colselectform.S;
        for (n=0; n<len; n++)
            ele[n].checked= ! ele[n].checked;
        }

    function vis_all(value)
        {
        len = document.colselectform.S.length;
        ele = document.colselectform.S;
        for (n=0; n<len; n++)
            ele[n].checked= value;
        ele[6].checked=1;   // test_name
        }

    function vis_some(value)
        {
        len = document.colselectform.S.length;
        ele = document.colselectform.S;
        if ( value == '' ) {
            for (n=0; n<len; n++) {
                if ( ele[n].value.search('t.a_') == 0 )
                    return;
                ele[n].checked= 1
                }
            return;
            }
        for (n=0; n<len; n++)
            if ( ele[n].value.search(value) == 0 )
                ele[n].checked= 1
        }

</script>
""")
Exemple #7
0
def latest():
    import pandokia.text_table as text_table
    pdk_db = pandokia.cfg.pdk_db

    if pandokia.pcgi.output_format == 'html':
        sys.stdout.write(common.cgi_header_html)
        sys.stdout.write(common.page_header())
    elif pandokia.pcgi.output_format == 'csv':
        sys.stdout.write(common.cgi_header_csv)

    postfixes = ('latest', 'today', 'yesterday')

    for postfix in postfixes:
        sys.stdout.write('<h2>%s</h2>' % postfix)
        t = text_table.text_table()

        t.define_column('prefix')
        t.define_column(postfix)
        t.define_column('n')

        d = {}
        total = 0
        for row, prefix in enumerate(sorted(common.cfg.recurring_prefix),
                                     start=1):

            t.set_value(row, 0, prefix)

            test_run = common.find_test_run(prefix + '_' + postfix)
            c = pdk_db.execute(
                'SELECT test_run, record_count FROM distinct_test_run WHERE test_run = :1',
                (test_run, ))
            n = c.fetchone()
            if n is None:
                t.set_value(row, 1, '')
                t.set_value(row, 2, '')
                continue
            (tr, count) = n
            if count == 0 or count is None:
                import pandokia.cleaner as cleaner
                count = cleaner.recount_test_run(tr)

            if count is None:
                count = 0

            total = total + count

            d['test_run'] = test_run
            t.set_value(row,
                        1,
                        text=test_run,
                        link=common.selflink(d, "day_report.2"))
            count_link = common.selflink({'count_run': test_run}, 'action')
            t.set_value(row, 2, text=count, link=count_link)

        t.set_value(row + 1, 2, total)

        if pandokia.pcgi.output_format == 'html':
            t.set_html_table_attributes(' border=1 ')
            sys.stdout.write(t.get_html(headings=1))
        elif pandokia.pcgi.output_format == 'csv':
            sys.stdout.write(t.get_csv())