⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 granny.cgi

📁 PHP写的图片查看器
💻 CGI
📖 第 1 页 / 共 2 页
字号:
         opts = self.get_opts()         if opts.has_key('-r'):             self.revision = '-r%s' % opts['-r']         if opts.has_key('-h'):             self.usage(help=1)         if opts.has_key('-i'):             if opts['-i'] != '-':                 self.filename = v                 infile = open(filename, 'r')                 sys.stdin = infile             else:                 self.file = sys.stdin         else:             self.filename = sys.argv[len(sys.argv) - 1]             cmd = 'cvs annotate %s %s' % (self.revision, self.filename)             status, text = self.getoutput(cmd)             if status != 0 or text == '':                 sys.stderr.write("Can't run cvs annotate on %s\n" %                                                                 self.filename)                 sys.stderr.write('%s\n' % text)                 sys.exit(1)             self.file = cStringIO.StringIO(text)         if opts.has_key('-o'):             if opts['-o'] != '-':                 outfile = open(v, 'w')                 sys.stdout = outfile         else:             # this could be done without a temp file             target = sys.argv[len(sys.argv) -1]             self.tmpfile = tempfile.mktemp()             self.tmp = open(self.tmpfile, 'w')             sys.stdout = self.tmp         if opts.has_key('-d'):             if opts['-d'] > 0:                 self.day_range = opts['-d']         if opts.has_key('-D'):             self.showDate = 1         if opts.has_key('-U'):             self.showUser = 1         if opts.has_key('-V'):             self.showVersion = 1     def parse_raw_annotated_file(self):         ann = re.compile('((\d+\.?)+)\s+\((\w+)\s+(\d\d)-'\                          '(\w{3})-(\d\d)\): (.*)')         text = self.file.read()         lines = string.split(text, '\n')         for line in lines:             # Parse an annotate string             m = ann.search(line)             if m:                 self.version[self.counter] = m.group(1)                 self.user[self.counter] = m.group(3)                 oldtime = self.today - time.mktime((                                                 int(m.group(6)),                                                 int(month_num[m.group(5)]),                                                 int(m.group(4)),0,0,0,0,0,0))                 self.rtime[self.counter] = oldtime / 86400                 self.source[self.counter] = self.html_quote(m.group(7))             else:                 self.source[self.counter] = self.html_quote(line)                 pass             self.counter = self.counter + 1     def write_annotated_html_file(self):         if os.environ.has_key('SCRIPT_NAME'):             print 'Status: 200 OK\r\n'             print 'Content-type: text/html\r\n\r\n'         print ('<html><head><title>%s</title></head>\n' \                '<body bgcolor="#000000">\n' \                '<font color="#FFFFFF"><H1>File %s</H1>\n' \                '<H3>Code age in days</H2>' % (self.filename, self.filename))         for i in range(self.day_range + 1):             self.color_table[i] = \                 self.hsvtorgb(240.0 * i / self.day_range, 1.0, 1.0)         step = self.day_range / 40         if step < 5:             step = 1             while self.day_range/step > 40:                 step = step + 1         if step >= 5:             if step != 5:                 step = step + 5 - (step % 5)             while self.day_range / step > 20:                 step = step + 5         for i in range(self.day_range + 1, step):             print '<font color=%s>%s ' % (self.color_table[i], i),         print '<pre><code>'         for i in range(self.counter):             if self.showUser and self.user.has_key(i):                 print '%s%s ' % ('<font color=#FFFFFF>',                                  string.ljust(self.user[i],10)),             if self.showVersion and self.version.has_key(i):                 print '%s%s ' % ('<font color=#FFFFFF>',                                  string.ljust(self.version[i],6)),             if self.showDate and self.rtime.has_key(i):                 (year,mon,day,hour,min,sec,dow,doy,dst) = time.gmtime(                                            self.today - self.rtime[i] * 86400)                 print '<font color=#FFFFFF>%02d/%02d/%4d ' % (mon, day, year),             if self.rtime.get(i, self.day_range) < self.day_range:                 fcolor = self.color_table.get(                                         self.rtime[i],                                         self.color_table[self.day_range])             else:                 fcolor = self.color_table[self.day_range]             print '<font color=%s> %s' % (fcolor, self.source[i])         print ('</code></pre>\n' \                '<font color=#FFFFFF>\n' \                '<H5>Granny original Perl version by' \                '<I>J. Gabriel Foster</I>\n' \                '<ADDRESS><A HREF=\"mailto:gabe@sgrail.com\">'\                'gabe@sgrail.com</A></ADDRESS>\n' \                'Python version by <I>Brian Lenihan</I>\n' \                '<ADDRESS><A HREF=\"mailto:brianl@real.com\">' \                'brianl@real.com</A></ADDRESS>\n' \                '</body></html>')         sys.stdout.flush()     def hsvtorgb(self,h,s,v):         """         a veritable technicolor spew         """         if s == 0.0:             r = v; g = v; b = v         else:             if h < 0:                 h = h + 360.0             elif h >= 360.0:                 h = h - 360.0             h = h / 60.0             i = int(h)             f = h - i             if s > 1.0:                 s = 1.0             p = v * (1.0 - s)             q = v * (1.0 - (s * f))             t = v * (1.0 - (s * (1.0 - f)))             if   i == 0: r = v; g = t; b = p             elif i == 1: r = q; g = v; b = p             elif i == 2: r = p; g = v; b = t             elif i == 3: r = p; g = q; b = v             elif i == 4: r = t; g = p; b = v             elif i == 5: r = v; g = p; b = q         return '#%02X%02X%02X' % (r * 255 + 0.5, g * 255 + 0.5, b * 255 + 0.5)     def usage(self, help=None):         sys.stderr.write('\nusage: %s %s\n\n' % (                         sys.argv[0],                         '[-hDUV][-d days][-i input][-o output][-r rev] FILE')         )         if help is not None:             sys.stderr.write(                 '-h:      Get this help display.\n' \                 '-i:      Specify the input file. (Use - for stdin.)\n' \                 '-o:      Specify the output file. (Use - for stdout.)\n' \                 '-d:      Specify the day range for the coloring.\n' \                 '-r:      Specify the cvs revision of the file.\n' \                 '-D:      Display the date the line was last edited.\n' \                 '-U       Display the user that last edited the line.\n' \                 '-V:      Display the version the line was last edited.\n\n' \                 'By default, %s executes a cvs annotate on a FILE and\n' \                 'runs netscape to display the graphical ' \                 'annotation\n' % sys.argv[0]             )         sys.exit(0)class CGIAnnotate(Annotate):     def __init__(self,tempdir='/usr/tmp'):         Annotate.__init__(self)         if os.name == 'nt':             self.tempdir = os.environ.get('TEMP') or os.environ.get('TMP')         else:             # XXX need a sanity check here             self.tempdir = tempdir         os.chdir(self.tempdir)     def process_args(self):         f = cgi.FieldStorage()         cvsroot = f['root'].value         if f.has_key('showUser'):             self.showUser = 1         if f.has_key('showDate'):             self.showDate = 1         if f.has_key('showVersion'):             self.showVersion = 1         if f.has_key('rev'):             self.revision = '-r%s' % f['rev'].value         path = f['Name'].value         module = os.path.dirname(path)         self.workingdir = 'ann.%s' % os.getpid()         self.filename = os.path.basename(path)         os.mkdir(self.workingdir)         os.chdir(os.path.join(self.tempdir, self.workingdir))         os.system('cvs -d %s co %s' % (cvsroot, path))         os.chdir(module)         cmd = 'cvs annotate %s %s' % (self.revision, self.filename)         status, text = self.getoutput(cmd)         if status != 0 or text == '':             text = "Can't run cvs annotate on %s\n" % path         self.file = cStringIO.StringIO(text)     def cleanup(self):         os.chdir(self.tempdir)         os.system('rm -rf %s' % self.workingdir)     def display_annotated_html_file(self):         pass     def usage(self):         passif __name__ == '__main__':     if os.environ.has_key('SCRIPT_NAME'):         import cgi         A = CGIAnnotate()     else:         A = Annotate()     A.run()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -