Ejemplo n.º 1
0
def cmp_form( query, comparing ) :
    lquery = query.copy()

    del lquery['compare']
 
    # look for input from the compare form
    lquery['cmp_test_run'] = lquery.get('cmp_test_run', common.run_previous(None,lquery['test_run'])  )
    lquery['cmp_context'] = lquery.get('cmp_context', lquery['context'])
    lquery['cmp_host'] = lquery.get('cmp_host', lquery['host'])

    lquery['query'] = 'treewalk'

    l = [ 
        """<a href='javascript:toggle("cmpform",1)'>[<span id='cmpform_plus'></span> Compare]</a>
        <div id='cmpform'>
        <ul>
        """,
        "<form action=%s method=GET>"%common.get_cgi_name(),
        "<table>"
        ]
    for x in ( 'cmp_test_run', 'cmp_context', 'cmp_host' ) :
        l.append( "<tr><td>%s</td><td> <input type=text name=%s value='%s'></td></tr>"%(x,x,lquery[x]) )
        del lquery[x]
    l.append("</table>")


    l.append( common.query_dict_to_hidden( lquery ) )

    l.append(" <input type=submit name='compare' value='Compare'> ")
    l.append(" <input type=submit name='compare' value='Turn Off Compare'> ")
    l.append(" <input type=submit name='compare' value='Reverse Comparison'>" )

    l.append("</form>")

    ##

    l.append(
        """
        </ul>
        </div>
        <script>
        vis = new Array();
        """ )

    if comparing :
        l.append(""" vis['cmpform']=1; """)

    l.append( """
        function toggle(f) {
            vis[f] = ! vis[f];
            if (vis[f]) v="none"; else v="block";
            if (vis[f]) plus='+'; else plus='-';
            document.getElementById(f).style.display=v;
            document.getElementById(f+'_plus').innerHTML=plus;
        }
        toggle("cmpform")
        </script>
        """ )

    return '\n'.join(l)
Ejemplo n.º 2
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()
Ejemplo n.º 3
0
def add_project(user):
    form = pandokia.pcgi.form

    project = form['project'].value

    if not project_name_ok(project):
        output.write(
            'Project names can contain upper/lower case letters, digits, underline, dot, and slash.'
        )

    else:
        cfg.pdk_db.execute(
            "INSERT INTO user_email_pref ( username, project, format, maxlines ) VALUES ( :1, :2, 'n', 0)",
            (user, project))
        cfg.pdk_db.commit()
        output.write('added %s' % cgi.escape(project))

    output.write('<br>')
    output.write('<a href=%s?query=prefs>Back to preference page</a>' %
                 common.get_cgi_name())
Ejemplo n.º 4
0
def hostinfo():

    admin = common.current_user() in common.cfg.admin_user_list

    print common.cgi_header_html

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

    for x in input_query['host']:
        host, os, description = common.hostinfo(x)
        if os is None:
            os = ''
        if description is None:
            description = ''

        print '<b>%s</b><br>' % cgi.escape(host)

        cols = len(os)
        if cols < 40:
            cols = 40
        if admin:
            print "<form action=%s method=POST>" % common.get_cgi_name()
            print "<input type=hidden name=query value=set_hostinfo>"
            print "<input type=hidden name=host value=%s>" % host
        print '<input type=text cols=%d name=os value="%s">' % (
            cols, cgi.escape(os, True))

        l = [len(s) for s in description.split('\n')]
        cols = max(l)
        if cols < 40:
            cols = 40
        rows = len(l)
        if rows < 4:
            rows = 4
        print "<br><textarea name=description rows=%d cols=%d>%s</textarea>" % (
            rows, cols, cgi.escape(description))
        if admin:
            print "<br><input type=submit value='change'>"
            print "</form>"
Ejemplo n.º 5
0
def show(user):

    form = pandokia.pcgi.form

    #
    output.write('<h1>User Preferences: %s</h1>' % cgi.escape(user))

    # write the start of form, including hidden fields needed to dispatch
    # to the save() function after we submit the form.
    output.write('<form action=%s method=GET>' % common.get_cgi_name())
    output.write('<input type=hidden name=query value=prefs>')
    output.write('<input type=hidden name=subtype value=save>')

    # show the user's email address
    c = cfg.pdk_db.execute('SELECT email FROM user_prefs WHERE username = :1',
                           (user, ))
    x = c.fetchone()
    if x is None:
        email = user
    else:
        email, = x

    output.write('<h3>Email address</h3>')
    output.write('Email address: <input type=text name=email value="%s">' %
                 email)
    output.write('<br>\n')

    # make a table of what the user has selected for each project
    output.write('<h3>Email Preferences</h3>')

    tb = text_table.text_table()
    tb.define_column("project", showname='Project')
    tb.define_column("none", showname='None')
    tb.define_column("contact", showname='Contact')
    tb.define_column("summ", showname='Summary')
    tb.define_column("full", showname='Full')
    tb.define_column("all", showname='Always')
    tb.define_column("line", showname='Max')

    row = 0

    def ckif(x):
        if format == x:
            return 'checked'
        else:
            return ''

    c = cfg.pdk_db.execute(
        'SELECT username, project, format, maxlines FROM user_email_pref WHERE username = :1 ORDER BY project',
        (user, ))

    c = [x for x in c]

    if len(c) == 0:
        try:
            x = cfg.default_user_email_preferences
        except:
            x = []
        c = [(user, x[0], x[1], x[2]) for x in x]

    for username, project, format, maxlines in c:
        if not project_name_ok:
            output.write('bad project name in table<br>')
            continue
        tb.set_value(row, 'project', project)

        project = urllib.quote(project)
        # projects will be a list of all the projects we are submitting in the form
        output.write('<input type=hidden name=projects value="%s">' % project)

        # radio.%s will be the radio button for that project name
        tb.set_value(row,
                     'none',
                     html='<input type=radio name="radio.%s" value="n" %s>' %
                     (project, ckif('n')))
        tb.set_value(row,
                     'contact',
                     html='<input type=radio name="radio.%s" value="c" %s>' %
                     (project, ckif('c')))
        tb.set_value(row,
                     'summ',
                     html='<input type=radio name="radio.%s" value="s" %s>' %
                     (project, ckif('s')))
        tb.set_value(row,
                     'full',
                     html='<input type=radio name="radio.%s" value="f" %s>' %
                     (project, ckif('f')))
        tb.set_value(row,
                     'all',
                     html='<input type=radio name="radio.%s" value="F" %s>' %
                     (project, ckif('F')))

        # maxlines is an integer, but 0 means no limit.  display it as a blank field
        if (maxlines == 0):
            maxlines = ''

        # radio.%s will be the radio button for that project name
        tb.set_value(
            row,
            'line',
            html='<input type=text name="line.%s" value="%s" size=5>' %
            (project, maxlines))
        row = row + 1

    tb.set_html_table_attributes('border=1')
    output.write(tb.get_html())

    # some explanatory text
    output.write('''<p>None=no email about that project<br>
     Contact=email only tests you are a contact for<br>
     Summary=email contains only a count<br>
     Full=show all tests with problems, skip projects with none<br>
     Always=show all tests with problems, show all projects with problems or not<br>
     Max=list at most max tests in the email</p>''')
    output.write('<input type=submit name=submit value=save>')

    if user in cfg.admin_user_list:
        output.write('<br>')
        output.write('<input type=text name=newuser>')
        output.write('<input type=submit name=submit value=newuser>')
    output.write('</form>')

    # this is a different form - it just adds a project to the list of
    # projects that the user has preferences for
    output.write('<form action=%s method=GET>' % common.get_cgi_name())
    output.write('<input type=hidden name=query value=prefs>')
    output.write('<input type=hidden name=subtype value=add_project>')
    output.write('<input type=text name=project>')
    output.write('<input type=submit name=submit value="Add Project">')
    output.write('</form>')
Ejemplo n.º 6
0
def save(user):
    form = pandokia.pcgi.form

    email = None
    if 'email' in form:
        email = form['email'].value

    if email is None or email == 'None':
        email = user

    # save the email address that they entered
    cfg.pdk_db.execute('DELETE FROM user_prefs WHERE username = :1', (user, ))
    cfg.pdk_db.execute(
        'INSERT INTO user_prefs ( email, username ) VALUES ( :1, :2 )',
        (email, user))

    # projects is a list of all the projects that the form is submitting
    for project in form.getlist('projects'):
        if not project_name_ok(project):
            continue

        # pick out the value of the radio button.
        field_name = 'radio.%s' % project
        if field_name in form:
            format = form[field_name].value
        else:
            format = 'n'

        # ignore it if they are messing with us
        if not format in ['c', 'n', 'f', 'F', 's']:
            format = 'n'

        # pick out the value of the text field that shows how many tests
        # we want reported
        field_name = 'line.%s' % project
        if field_name in form:
            maxlines = form[field_name].value
        else:
            maxlines = ''

        # if it is not blank or an integer, blank it out
        try:
            maxlines = int('0' + maxlines)
        except ValueError:
            maxlines = ''

        # delete and insert instead of update because we may be adding new projects.
        cfg.pdk_db.execute(
            'DELETE FROM user_email_pref WHERE username = :1 and project = :2',
            (user, project))
        try:
            maxlines = int(maxlines)
        except:
            maxlines = 0
        cfg.pdk_db.execute(
            'INSERT INTO user_email_pref ( username, project, format, maxlines ) VALUES ( :1, :2, :3, :4 )',
            (user, project, format, maxlines))

    cfg.pdk_db.commit()
    output.write('Preferences saved.<br>')
    output.write('<a href=%s?query=prefs>Back to preference page</a><br>' %
                 common.get_cgi_name())
    output.write('<a href=%s>Back to top level</a><br>' %
                 common.get_cgi_name())
Ejemplo n.º 7
0
def run():
    #
    # take actions based on the button a user slected from the summary page
    #

    output = sys.stdout

    text_present = 0

    output.write(common.cgi_header_html)

    form = pandokia.pcgi.form

    qid = int(form['qid'].value)

    output.write('<h2>QID = %d</h2>' % qid)

    output.write('<p>operate on this QID</p>')

    change = 0

    if 'other' in form:
        other_qid = int(form['other'].value)

    if 'nameremove' in form:
        #####

        output.write('nameremove operation<br>')
        c = pdk_db.execute(
            "SELECT result_scalar.test_name FROM result_scalar, query WHERE query.qid = %d AND query.key_id = result_scalar.key_id "
            % other_qid)
        remove_names = []
        for x, in c:
            remove_names.append(x)

        remove_key_ids = []

        c = pdk_db.execute(
            "SELECT query.key_id, result_scalar.test_name  FROM query, result_scalar WHERE query.qid = %d AND query.key_id = result_scalar.key_id"
            % qid)
        for key_id, name in c:
            if name in remove_names:
                remove_key_ids.append(key_id)

        for key_id in remove_key_ids:
            pdk_db.execute(
                "DELETE FROM query WHERE query.qid = %d AND query.key_id = %d"
                % (qid, key_id))

        pdk_db.commit()
        change = 1

    if 'add' in form:
        pdk_db.execute(
            "INSERT INTO query ( qid, key_id ) SELECT %d, key_id FROM query WHERE qid = %d AND key_id NOT IN ( SELECT key_id FROM query WHERE qid = %d )"
            % (qid, other_qid, qid))
        pdk_db.commit()
        change = 1

    if 'remove' in form:
        # mysql doesn't like it if you
        #       DELETE FROM query WHERE ... IN ( SELECT ... FROM query )
        pdk_db.execute(
            "CREATE TEMPORARY TABLE IF NOT EXISTS temporary_xyzzy ( key_id INTEGER )"
        )
        pdk_db.execute(
            "INSERT INTO temporary_xyzzy ( key_id ) SELECT key_id FROM query WHERE qid = %d "
            % other_qid)
        pdk_db.execute(
            "DELETE FROM query WHERE ( qid = %d ) AND ( key_id IN ( SELECT key_id FROM temporary_xyzzy ) ) "
            % (qid, ))
        pdk_db.execute("DELETE FROM temporary_xyzzy")
        pdk_db.commit()
        change = 1

    if change or 1:
        c = pdk_db.execute("SELECT COUNT(*) FROM query WHERE query.qid = %d" %
                           qid)
        x = c.fetchone()
        output.write('%d rows<br>' % x[0])

    output.write('<br>')

    output.write("<a href='" +
                 common.selflink({'qid': qid}, linkmode="summary") + "'>")
    output.write('back to summary page')
    output.write('</a> <br>\n')

    #
    # present an input field and possible actions
    #

    output.write('<br>')

    output.write('<form action=%s method=GET>' % common.get_cgi_name())
    output.write('<input type=hidden name=query value=qid_op>')
    output.write('<input type=hidden name=qid value=%d>' % qid)

    output.write('Enter another qid:<br><input type=text name=other><br><br>')

    output.write(
        '<input type=submit name=nameremove value="Remove tests that have the same test_name as tests in the other QID"> <br><br>\n'
    )
    output.write(
        '<input type=submit name=add value="Add tests from the other QID by key"> <br>\n'
    )
    output.write(
        '<input type=submit name=remove value="Remove tests that are also in other QID by key"> <br>\n'
    )
    output.write('</form>')