Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.stsci.edu/spst/UnixTransition/doc/passcat_report.py
Дата изменения: Fri Feb 28 14:46:11 2014
Дата индексирования: Sat Mar 1 17:13:37 2014
Кодировка:
# MODULE passcat_report
#
#******************************************************************************
"""Produces a report of the desired contents of the pass_catalog relation.

TITLE: passcat_report.py
DEVELOPER: Merle Reinhart, 1-Aug-2002

PURPOSE: To produce a human readable report of the contents of the
pass_catalog relation.

USAGE: do passcat_report [-file=] [-type=]
[-passid=] [-since=]
[-before=] [-convert_cat_time]
[-output=]
where -file= : This switch allows one to query for
a particular cataloged filename.
Standard SQL wildcards are allowed.
-type= : This switch allows one to query for
a particular file type. Current
values are MS, MTL and TDRS.
Standard SQL wildcards are allowed.
-passid= : This switch allows one to query for
a particular pass id of the form
Sadddypr. Standard SQL wildcards
are allowed.
-since= : This switch allows one to query for
any products cataloged since a
particular time of the form
yyyy.ddd[:hh:mm:ss.ccc]
-before= : This switch allows one to query for
any products cataloged before a
particular time of the form
yyyy.ddd[:hh:mm:ss.ccc]
-convert_cat_time : This switch allows one to convert
the format of the cataloged time
to include the day of the week.
-output= : This switch allows one to write the
output to the filename of choice.
The default name is passcat_report.rpt.
Output may be routed to the screen
by using a value of 'tt:' on VMS or
'/dev/tty' on Unix.

RETURNS: completion status

MOD HISTORY:
1/16/03 drc allow passid to be lower case.
1/13/09 gab add -convert_cat_time option.
"""
#******************************************************************************

def run (*args):
"""This routine produces a report of the pass_catalog relation."""

import time, sys
import spss_sys_util, spst_getopt, stpydb, string
import re

# Define the layout of and parse the commandline
allowed_options = ['file=','type=','passid=','since=','before=',
'convert_cat_time','output=']
options, parms = spst_getopt.spst_getopt(args, allowed_options)

# Set up the database connection
spssdb = spss_sys_util.get_environ_variable('SPSS_DB')[0]
db = stpydb.stpydb(dbmsName=spssdb)

# Do the query
db.query('select distinct pass_filnam, ' + \
'file_type, ' + \
'pass_sms_nm, ' + \
'date_recv, ' + \
'start_time, ' + \
'end_time, ' + \
'pass_fil_dir, ' + \
'gen_time, ' + \
'podps_filnam, ' + \
'podps_status ' + \
'from pass_catalog ')
if (len(options) != 0):
# This dummy line is needed since all the other may wind up
# non-existant...ie, this line allows for a legal query
db.query('where gen_time = gen_time ')
if ('-file' in options.keys()):
db.query('and pass_filnam like "%s" ' % options['-file'])
# endif
if ('-type' in options.keys()):
db.query('and file_type like "%s" ' % string.upper(options['-type']))
# endif
if ('-passid' in options.keys()):
db.query('and pass_sms_nm like "%s" ' % string.upper(options['-passid']))
# endif
if ('-since' in options.keys()):
db.query('and date_recv >= "%s" ' % options['-since'])
# endif
if ('-before' in options.keys()):
db.query('and date_recv <= "%s" ' % options['-before'])
# endif
# endif
db.query('order by start_time desc, ' + \
'pass_sms_nm desc, ' + \
'file_type asc, ' + \
'date_recv desc ')
passcat = [{}]
db.executeAll(passcat)

# Deal with the output file name
if ('-output' in options.keys()):
outfile = options['-output']
else:
outfile = 'passcat_report.rpt'
#endif

if (outfile == 'stdout'):
rf = sys.stdout
else:
rf = open(outfile, 'w')
# endif

# Write out the data to the file
rf.write('\n')
rf.write(22*' '+'Report of PASS Products Cataloged\n')
rf.write(25*' '+'Date %s\n' % \
time.strftime("%d-%b-%Y (%Y.%j)",time.gmtime(time.time())))

old_pass_name = "########"

for i in passcat:
if (i['pass_sms_nm'] != old_pass_name):
old_pass_name = i['pass_sms_nm']
rf.write('\n')
rf.write(80*'-'+'\n')
rf.write('|'+35*' '+'%s' % i['pass_sms_nm'])
rf.write(35*' '+'|\n')
rf.write(80*'-'+'\n')
# endif
rf.write('\n')
rf.write(6*' '+'File: %-20s' % i['pass_filnam'])
rf.write(15*' '+'File type: %-s\n' % i['file_type'])
rf.write('Start time: %-21s' % i['start_time'])
rf.write(11*' '+'Cataloged on: %-s\n' % i['date_recv'])
if ('-convert_cat_time' in options.keys()):
# Strip off fractions of seconds.
if re.search(r'.{17,17}\.\d{3,3}$',i['date_recv']):
time_in = i['date_recv'][:17]
else:
raise ValueError ("Cataloged time format not understood.")
time_obj = time.strptime(time_in,'%Y.%j:%H:%M:%S')
local_time = time.strftime('%a %Y-%b-%d %H:%M:%S',time_obj)
rf.write(58*' '+'%s\n' % local_time)
rf.write(' End time: %-21s' % i['end_time'])
rf.write(11*' '+'Generated on: %-s\n' % i['gen_time'])
rf.write(' Directory: %-64s\n' % i['pass_fil_dir'])
rf.write(' OPUS name: %-30s' % i['podps_filnam'])
rf.write(8*' '+'Status: %-s\n' % i['podps_status'])
# end for i

if (outfile != 'stdout'):
rf.close()
# endif

return spss_sys_util.SUCCESS
# end def fun

if __name__ == '__main__':
import sys, string
if len(sys.argv) > 1:
print sys.argv
apply(run, tuple(sys.argv[1:]))
else:
run()