#!/usr/bin/env python # encoding: utf-8 """ marchive.py Created by Greg Kellogg on 2007-01-01. Tool to run zgrep through a CS-MARS archive """ __author__ = "Greg Kellogg (greg@dunechaser.org)" __version__ = "$Revision: 0.1 $" __date__ = "$Date: 1/1/07 11:14:34 $" __copyright__ = "Copyright (c) 2005 Greg Kellogg" __license__ = "BSD" import cgi, os, time, sys marsDir = "/nfs/mars-lc/" zgrep = '/usr/bin/zgrep -iP' configFile = "/var/www/cgi-bin/marchive.queries" # OS X Does not support -P in zgrep # Required header that tells the browser how to render the HTML. print "Content-Type: text/html\n\n" # Style sheet stuff print """ \n """ #Bootstrap application when called, load up the variables with directory information def bootstrap(): try: dateDirectories = os.listdir(marsDir) return dateDirectories except os.error, value: print value[0], value[1] # Here is the form that dynamically builds from the directory structure def buildForm(fileName,searchString='',startDate='',endDate=''): print '
' print '
' print '' print '' print '' print "\t\n" print '

' # This is for the actual searching def searchRecords(dates, searchString, startDate, endDate): start = dates.index(startDate) end = dates.index(endDate) print '
' print '' print '' print '' print '' print '' print '' if start > end: print 'Start date must be less than end date...' else: x = start while x <= end: tail = marsDir+dates[x]+'/ES/rm*' get = '%s %s %s' % (zgrep, '"'+searchString+'"', tail) results = os.popen(get, "r") x = x+1 y=0 for ret in results.xreadlines(): splret = ret.split('\xbb') print '' print '' newSpl = splret[3].replace('>','>') newSpl = newSpl.replace('<','<') print '' y = y+1 print "
RegEx Search String: '+searchString+'
DateSourceMessage
'+splret[1]+''+splret[2]+''+newSpl+'
" # Define main function. def main(): form = cgi.FieldStorage() dates = bootstrap() dates.sort() if (form.has_key("action") and form.has_key("endDate") and form.has_key("startDate") and form.has_key("searchString")): if (form["action"].value == "display"): buildForm(dates,form["searchString"].value, form["startDate"].value, form["endDate"].value) searchRecords(dates, form["searchString"].value, form["startDate"].value, form["endDate"].value) else: buildForm(dates) print "" # Call main function. if __name__ == '__main__': main()