cgi perl里如何改变某些字条符的颜色呀

#!/usr/bin/python

import cPickle as p
import sys
import os
import cgi

PLATFORMNUM=4
DATENUM=30
MYIP='9.125.53.162'
#INDEX_PATH='/new_cim_harness/logindex/'
INDEX_PATH='/var/www/cgi-bin/log/'
#LOG_PATH='/new_cim_harness/logcontent/'
LOG_PATH='/var/www/cgi-bin/log/'
form=cgi.FieldStorage()
print "Content-type: text/html\r\n\r\n"

#------------------------------------------------#
#    This function read a string to array,
#    each word is an item in the array.
#    Use blank as the separator.
#------------------------------------------------#
def readtoarray(a,s):
     i=1
     j=0
     l=len(s)
     while i<l:
         if s==' ' or i==l-1:
             a.append(s[j:i])
             j=i+1
         i=i+1

#---------------------------------------------------------------------------#
#    This function load data file to python dictionary dict.
#    Key of dict is data.
#    Each record of dict is a matrix of the following content:
#    Test_Bed PST Agent_Platform Agent_IP
#    Success_Num Fail_Num Disabled_Num Result_File
#
#    Before calling this function, PLATFORMNUM and DATENUM must be set.
#--------------------------------------------------------------------------#
def loadfile(dict, datelist, fname, pro='tmp.log'):
     #cmd='cp -f ' + fname + ' /tmp/tmp2.log'
     #os.system( cmd )
     #cmd='sort /tmp/tmp2.log  -t" " -k 1 -r|head -' + str(PLATFORMNUM*DATENUM) + ' >/tmp/tmp.log'
     cmd='sort ' + fname + ' -t" " -k 1 -r|head -' + str(PLATFORMNUM*DATENUM) + ' >/tmp/' + pro
     os.system( cmd )
     #os.system( 'id' )
     #dict={}
    #os.system('cat /tmp/tmp.log')
     f=file('/tmp/'+pro)
f=file('/tmp/'+pro)
     while True:
         line = f.readline()
         if len(line)==0:
             break;
         a=[]
         readtoarray(a, line)
         key=a[0]
         del a[0]
         if key in dict:
             dict[key].append(a)
         else:
             dict[key]=[a]
     f.close()
     #datelist=[]
     for d in dict:
         datelist.append(d)
     datelist.sort()


#os.system('echo "passw0rd"|gsa_login -p liuycdl')

print "<html>"
print '''<script>
     function dosubmit( dateobj ) {
         dateobj.form.submit();
     }
     </script>'''

#for product, combo_name in DICTFILES.items():
def showframe():
     dict={}
     datelist=[]
     product = 'SVC4.3'
     if form.has_key("product"):
         product = form["product"].value
     if form.has_key("type"):
         type = form["type"].value
          pfile=INDEX_PATH + product + '.index'
     loadfile(dict, datelist, pfile, product)
     #print datelist[0]
     l=len(datelist)
     selected=datelist[l-1]
     if form.has_key("rundate"):
         selected=form["rundate"].value
     print '''
     <hr noshade>
     <h1>''' + product + '  ' + selected + '''</h1>
     <form method=post action="/cgi-bin/nightly_frame.cgi">
     <table width="100%">
     <tr>
         <th colspan="3" align="center">
         <h3>
             <u>''' + type + '''</u>
             <u>''' + type + '''</u>
         </h3>
         </th>
         <th colspan="3" align="center">
             <input type=hidden name=product value="''' + product + '''">
             <select name="rundate" onChange="dosubmit(this);">
     '''
     for i in range (1, l+1):
         if datelist[l-i]==selected:
             print '<option value="' + datelist[l-i] + '" selected>',datelist[l-i],'</option>'
         else:
             print '<option value="' + datelist[l-i] + '">',datelist[l-i],'</option>'
     print '''
             </select>
         </th>
     </tr>
     </table>
     </form>
     <table width="100%">
     </table>
     <table width="90%" border=2>
     <tr>
     <th width="10%" align="center">Test Date</th>
     <th width="18%" align="center">System Notes</th>
     <th width="15%" align="center">System IP</th>
     <th width="10%" align="center">System Notes</th>
     <th width="13%" align="center">CLI Command</th>
     <th width="10%" align="center">Test Results</th>
     <th width="20%" align="center">Detail Report</th>
     </tr>
     '''
     for item in dict[selected]:
         print '''
             <tr>
             <th width="18%" align="center">''' + item[0] + '''</th>
             <th width="15%" align="center">''' + item[1] + '''</th>
             <th width="10%" align="center">''' + item[2] + '''</th>
             <th width="13%" align="center">''' + item[3] + '''</th>
             <th width="10%" align="center">''' + item[4] + '''</th>
             <th width="10%" align="center">''' + item[5] + '''</th>
             <th width="20%" align="center"><a href=https://bvrgsa.ibm.com/projects/i''' + item[6] + ''' target="_new">Click here</a></th>
             </tr>'''
     print '''</table>
     '''

showframe()

print "</html>"

好不容易硬着头皮看了一下, 有点门道
<select name="rundate" onChange="dosubmit(this);">
     '''
     for i in range (1, l+1):
         if datelist[l-i]==selected:
             print '<option value="' + datelist[l-i] + '" selected>',datelist[l-i],'</option>'
         else:
             print '<option value="' + datelist[l-i] + '">',datelist[l-i],'</option>'
     print '''
             </select>
这段select好像是是一个下拉筐的,可以选择时间的。但是怎么放到perl里呀?

我顶,高手请出马

看来大伙真的都忙元旦了,呵呵

好不容易硬着头皮看了一下, 有点门道
<select name="rundate" onChange="dosubmit(this);">
     '''
     for i in range (1, l+1):
         if datelist[l-i]==selected:
             print '<option value="' + datelist[l-i] + '" selected>',datelist[l-i],'</option>'
         else:
             print '<option value="' + datelist[l-i] + '">',datelist[l-i],'</option>'
     print '''
             </select>
这段select好像是是一个下拉筐的,可以选择时间的。但是怎么放到perl里呀?


---------------

这段跟 perl 一毛钱关系也没有
你放在 html 里就可以
选项要由perl生成吧
一下子两位高人都出现了, 那不管什么python, 我想在我的cgi的表格里加一个小下拉筐,按时间来分页,怎么作吧,perl 的脚本是cobrawgl   

大天使帮我搞定的

                                                                  _____________
                                                                 |      day          |
                                                                 -------------------


-----------------------------------------------------------------------------------------------
|                          |                   |                  |                     |                            |      
|        DATE            |    OS TYPE  |  IP             |    COMMAND|     RESULTS          |
|________ _______| ____________________________________________ ___________|
|                          |                   |                  |                     |                             |
|                          |                   |                  |                     |       false                |
|                          |                   |                  |                     |                            |
| ______________ |_________________________________________________________  |
|                          |                   |                  |                     |                            |
|                          |                   |                  |                     |     true                 |
|                          |                   |                  |                     |                            |
-----------------------------------------------------------------------------------------------

day是一个下拉筐,可以选哪天,选 到哪天,就可以出来哪天的页面在下面的大表里



没仔细看


QUOTE:
原帖由 cobrawgl 于 2008-12-31 16:48 发表


没仔细看

这个就是你写的呀

代码 vi cgi-pl

#!/usr/bin/perl


use strict;
use warnings;

use CGI qw/:standard/;
use HTML::Template;

use IO::File;

my $tmpl_file = '/var/www/cgi-bin/tmplate';  # Change it
my $data_file = '/var/www/cgi-bin/log/testlog';  # Change it

my $template = HTML::Template->new(filename => $tmpl_file);
my $file = IO::File->new($data_file);

my @log;
while ($_ = $file->getline) {
        my %t;
        @t{qw/date computer platform command result Detail/} = (split);
        push @log, \%t
}
$template->param(log => \@log);

print header, $template->output;
~


vi  tmple


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
  <meta http-equiv="Content-Type" content="text/html; charset=gbk">
  <TITLE> Log </TITLE>
</HEAD>
    <table align=center>
          <td><b>Hatteras CLI Automation Test Results</b> </td>
    </table>
<BODY>
  <table border="1" width="900" align=center bordercolor="#6595d6">
    <tr>
      <th align=center id=tabletitlelink height=25 width="20%" style="font-weight:normal"><b>Test Date</b></th>
      <th align=center id=tabletitlelink height=25 width="15%" style="font-weight:normal"><b>System Type</th>
      <th align=center id=tabletitlelink height=25 width="10%" style="font-weight:normal"><b>HostName</th>
      <th align=center id=tabletitlelink height=25 width="30%" style="font-weight:normal"><b>System Command</th>
      <th align=center id=tabletitlelink height=25 width="10%" style="font-weight:normal"><b>Results</th>
      <th align=center id=tabletitlelink height=25 width="15%" style="font-weight:normal"><b>Hatteras Version</th>
    <tr>
  <tmpl_loop name="log">
        <tr>
                <td align=center id=tabletitlelink height=25 style="font-weight:normal"><tmpl_var name=date></td>
                <td align=center id=tabletitlelink height=25 style="font-weight:normal"><tmpl_var name=computer></td>
                <td align=center id=tabletitlelink height=25 style="font-weight:normal"><tmpl_var name=platform></td>
                <td align=center id=tabletitlelink height=25 style="font-weight:normal"><tmpl_var name=command></td>
                <td align=center id=tabletitlelink height=25 style="font-weight:normal"><tmpl_var name=result></td>
                <td align=center id=tabletitlelink height=25 style="font-weight:normal"><tmpl_var name=Detail></td>
        </tr>
  </tmpl_loop>
  </table>
</BODY>
</HTML>
模板

QUOTE:
<CTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<TITLE> Log </TITLE>
<script>
function dosubmit(dateobj) {
     dateobj.form.submit();
}
</script>
</HEAD>
<BODY>
<table align=center>
     <tr><td><b>Hatteras CLI Automation Test Results</b> </td></tr>
</table>
<div align="center">
<form method=post action="cgi-pl">
  <select name="_date" id="_date" onChange="dosubmit(this);">
     <tmpl_var name=datelist>
  </select>
</form
</div>
<table border="1" width="900" align=center bordercolor="#6595d6">
     <tr>
         <th align=center id=tabletitlelink height=25 width="20%" style="font-weight:normal"><b>Test Date</b></th>
         <th align=center id=tabletitlelink height=25 width="15%" style="font-weight:normal"><b>System Type</th>
         <th align=center id=tabletitlelink height=25 width="10%" style="font-weight:normal"><b>HostName</th>
         <th align=center id=tabletitlelink height=25 width="30%" style="font-weight:normal"><b>System Command</th>
         <th align=center id=tabletitlelink height=25 width="10%" style="font-weight:normal"><b>Results</th>
         <th align=center id=tabletitlelink height=25 width="15%" style="font-weight:normal"><b>Hatteras Version</th>
     <tr>
     <tmpl_loop name="log">
     <tr>
         <td align=center id=tabletitlelink height=25 style="font-weight:normal"><tmpl_var name=date></td>
         <td align=center id=tabletitlelink height=25 style="font-weight:normal"><tmpl_var name=computer></td>
         <td align=center id=tabletitlelink height=25 style="font-weight:normal"><tmpl_var name=platform></td>
         <td align=center id=tabletitlelink height=25 style="font-weight:normal"><tmpl_var name=command></td>
         <td align=center id=tabletitlelink height=25 style="font-weight:normal"><tmpl_var name=result></td>
         <td align=center id=tabletitlelink height=25 style="font-weight:normal"><tmpl_var name=Detail></td>
     </tr>
     </tmpl_loop>
</table>
</BODY>
</HTML>

cgi

QUOTE:
#!/usr/local/bin/perl

use strict;
use warnings;

use CGI qw/:standard/;
use HTML::Template;

use IO::File;

my $tmpl_file = 'tmplate';  # Change it
my $data_file = 'testlog';  # Change it

my $template = HTML::Template->new(filename => $tmpl_file);
my $file = IO::File->new($data_file);

my @date;
for (1..10) {
    my $t = '<option value="2008-12-'.sprintf("%02d", $_).'">2008-12-'.sprintf("%02d", $_).'</option>';
    push @date, $t;
}
my @log;
while ($_ = $file->getline) {
    my %t;
    @t{qw/date computer platform command result Detail/} = (split);
    push @log, \%t
}
$template->param(log => \@log, datelist=> join("\n", @date));

print header, $template->output;

多了一句print