Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.stsci.edu/spst/UnixTransition/doc/get_by_cycle.py
Дата изменения: Fri Feb 28 14:46:10 2014
Дата индексирования: Sat Mar 1 16:16:55 2014
Кодировка:

Поисковые слова: п п п п п п п
#!/usr/bin/env python
#MODULE get_by_cycle
#
#***********************************************************************
"""

**PURPOSE** --
Get vists or proposals based on the input cycle number.

**DEVELOPER** --
Don Chance

**MODIFICATION HISTORY** --
Date Who What
==== === ====
5-20-05 Chance Initial implementation
5-23-05 Chance added visit_detail_report
8-17-05 Chance modified hash-bang for move to python 2.4.1
4-18-06 Chance warn if neither -proposals or -visits is input
7-18-06 Chance add status, types, excluded_lrps parameters
6-21-07 Chance fix bug when -detail is used
11-7-08 Chance add scenario as an input option.
11-17-08 Chance print the scenario name
5-10-12 Chance add exectime option
"""
#***********************************************************************
__version__ = "11/17/08"

import visit_util
import sys
import proposal_util
import spss_sys_util
import available
import spst_getopt
import time_util

def run(*args):
"""Get proposals/visits based on the input cycle number

Usage:
do get_by_cycle [...]
[-proposals] [-visits] [-detail] [-output=]
[-status=] [-types=] [-excluded_lrps=]
[-scenario_name=] [-exectime]
At least one cycle number must be input; multiple cycle numbers may be provided separated
by whitespace.

If the optional parameter, '-proposals', is given, a list of proposals will be produced.

If the optional parameter, '-visits', is given, a list of visits will be produced.

The '-detail' option will produce an 'available-style' report when '-visits' is specified.

If the optional parameter -output= is given, all output will
go to . Otherwise, output will go to the screen.

The -status list is a comma separated list (with no spaces and no quotes)
of allowed prop_track status values. Allowed prop_track values are 'pi',
'implementation', 'scheduling', 'completed', 'withdrawn', 'failed', and
'n/a'. The default is -status=pi,implementation,scheduling.

Similarly, the -types list is a comma separated list of allowed or disallowed
coverpage type values. Wildcards are allowed (_ for a single character or %
for multiple characters) and any value may be disallowed by appending NO to it.
For example, -types=NO%PARS will exclude all proposals (or visits from proposals)
that end with PARS in the coverpage type field. The default is
-types=GO%,GTO%,CAL%,ENG%.

The -excluded_lrps will exclude proposals or visits from proposals that are in
the listed LRPS. By default, no LRPs are excluded.

-scenairo_name defaults to the default scenario name from relation constraint_scenarios

When -exectime is specified, instead of plan windows execution start time and end time are printed.
Status defaults to "pi,implenetation,scheduling,completed" when exetime is specified.
"""
allowed_options = ['proposals',
'visits',
'output=',
'detail',
'status=',
'types=',
'excluded_lrps=',
'scenario_name=',
'exectime'
]

try:
options, parms = spst_getopt.spst_getopt(args, allowed_options)
except Exception,e:
print e
print "Illegal argument."
return not spss_sys_util.SUCCESS

if len(parms) < 1:
# User must pass in at least two arguments:
print "Cycle number must be supplied."
print run.__doc__
return spss_sys_util.SUCCESS

else:
cycles = parms

outfileName = ''
outfileId = None
if options.has_key('-output'):
outfileName = options['-output']
if not options.has_key('-output') or outfileName == 'stdout' or not outfileName:
print "All output will be sent to the screen."
outfileId = sys.stdout
else:
print "All output will be sent to:", outfileName
outfileId = open(outfileName, 'w')

if options.has_key('-exectime'):
use_exectime = True
else:
use_exectime = False

if options.has_key('-status'):
pt_status = tuple(options['-status'].split(','))
elif use_exectime == True:
pt_status = ("pi","implementation","scheduling", "completed")
else:
pt_status = ("pi","implementation","scheduling")

if options.has_key('-types'):
cp_types = tuple(options['-types'].split(','))
else:
cp_types = ('GO%', 'GTO%', 'CAL%', 'ENG%')

if options.has_key('-excluded_lrps'):
excluded_lrps = tuple(options['-excluded_lrps'].split(','))
else:
excluded_lrps = ()

if options.has_key("-scenario_name"):
scenario = options["-scenario_name"]
outfileId.write('Constraint scenario being used is %s.\n' % scenario)
else:
# Use the default scenario name when scenario name = None
scenario = None
outfileId.write('Default constraint scenario being used.\n')

if options.has_key('-proposals'):
props = proposal_util.get_proposals_by_cycle(cycles, cp_types, pt_status, excluded_lrps)
for prop in props:
outfileId.write(str(prop) + '\n')

if options.has_key('-visits'):
visits = visit_util.get_visits_by_cycle(cycles, cp_types, pt_status, excluded_lrps)
if options.has_key('-detail'):
visit_detail_report(visits, outfileId, scenario, use_exectime)
else:
for visit in visits:
outfileId.write(str(visit) + '\n')

if not options.has_key('-proposals') and not options.has_key('-visits'):
print "Please try again specifying either the -visits or -proposals option."

return spss_sys_util.SUCCESS

def visit_detail_report(visits, fileId, scenario=None, use_exectime=False):
ttime = time_util.spss_time()
if use_exectime:
available.HEADER_LINE1 = available.HEADER_LINE1.replace(' min', 'exec')
available.HEADER_LINE1 = available.HEADER_LINE1.replace(' max', 'exec')
available.HEADER_LINE2 = available.HEADER_LINE2.replace('PW begin', ' begin ')
available.HEADER_LINE2 = available.HEADER_LINE2.replace('PW end', 'end ')
t0 = time_util.spss_time("1980.001:00:00:00")
available.header(ttime, None, fileId)
for visit in visits:
try:
tup = available.get_tuple(visit, None, ttime, scenario)
if use_exectime:
sched_start, sched_end = visit.get_sched_times()
if sched_start == t0:
sched_start = " - "
else:
sched_start = sched_start.strftime('%y') + sched_start.strftime('.%j:%H')
if sched_end == t0:
sched_end = " - "
else:
sched_end = sched_end.strftime('%y') + sched_end.strftime('.%j:%H')

#tup = tuple(list(tup[:4]).extend([sched_start, sched_end].extend(list(tup[6:]))))
l1 = list(tup[:4])
l2 = list(tup[6:])
l1.extend([sched_start, sched_end])
tup = tuple(l1 + l2)
fileId.write((available.FORMAT + '\n') % tup)
except:
print "Error while working on visit:", visit
raise


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