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

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

**PURPOSE** --
Identify the prime external visits which cna potentially can (and
cannot) execute in a given interval.

**DEVELOPER** --
Don Chance

**MODIFICATION HISTORY** --
Date Who What
==== === ====
3/09/05 Chance Initial implementaion.
3/10/05 Chance enhance documentation, return visits lists
from report function.
3/24/05 Chance add progess meter
8/17/05 Chance modified hash-bang for move to python 2.4.1
10/18/05 Chance add available header
10/18/05 Chance add verified constraint window controls
7/07/06 Chance add scenario option
"""
#***********************************************************************
__version__ = "7/05/06"

import lrp_util
import sys
import time_util
import spss_sys_util
import available
import progress
import spst_getopt

def run(*args):
"""Produce a report of visits which can move from one interval to another.

Usage:
do move_it [-[no]vcw] [-scenario_name=] [LRP]
start_check_interval end_check_interval [target_start_time] [target_end_time] [output_options]

where:
- -vcw/-novcw controls whether verified constraint windows are included when
determining schedulability. With -vcw, visits with verified contraint windows
intersecting the target interval will be included output to the move_it.rpt
file. With -novcw (the default), visits with only verified constraint windows
intersecting the target interval will be included in the stuck.rpt file.
- scenairo_name defaults to the default scenario name from relation constraint_scenarios
- LRP defaults to the latest released lrp
- start_check_interval, end_check_interval, target_start_time, target_end_time must
all be of the form yyyy.ddd:hh:mm:ss
- output_options can be 'm' for reporting visits which can move (file move_it.rpt)
or 'f' for reporting visits which cannot move (file stuck.rpt)
The default is to produce both files. The files are written
into the current working directory.

(The 'do' is not needed from the LRP account, just 'move_it ...' should work.)


Examples:
do move_it 2002.007 2002.021

Check for any visits not having plan windows in 007-021 which can move into 007-021
from the latest released LRP. Report both visits which can and cannot move with
separate summaries.

do move_it 01198A 2002.007 2002.021

Check for any visits not having plan windows in the specified interval which can
move into that interval from LRP 01198A. Produce both summary files.

do move_it 2002.161 2002.175 2002.007 2002.021

Check for visits with plan windows intersecting 161-175 which can move into 007-021
from the latest released LRP. Produce both summary files.

do move_it 01198A 2002.161 2002.175 2002.007 2002.021

Check for visits with plan windows intersecting 161-175 which can move into 007-021
from LRP 01198A. Produce both summary files.

do move_it 01198A 2002.161 2002.175 2002.007 2002.021 f

Check for visits with plan windows intersecting 161-175 which can move into 007-021
from LRP 01198A. Produce only the report showing visits which cannot move (stuck.rpt).

do move_it 01198A 2002.161 2002.175 2002.007 2002.021 m

Check for visits with plan windows intersecting 161-175 which can move into 007-021
from LRP 01198A. Produce only the report showing visits which can move (move_it.rpt).

Output is like that for the 'available' report except that for the visits that can
move (ie. those in the move_it.rpt file). For those visits, at the end of each line is
a 'w' if there were constraint windows for the target time interval, 'v' if there were
verified constraint windows for the interval, or 'wv' if there were both.

"""
output_option = 'b'
lrp = None
start_check_interval = None
end_check_interval = None
allowed_options = ["novcw", "vcw", "scenario_name="]
include_vcw = False

# Filter out the -vcw/-novcw switch.
options, args = spst_getopt.spst_getopt(args, allowed_options)
if options.has_key("-vcw"):
include_vcw = True
if options.has_key("-vcw") and options.has_key("-novcw"):
print "-vcw and -novcw options are mutually exclusive"
return not spss_sys_util.SUCCESS

if options.has_key("-scenario_name"):
scenario = options["-scenario_name"]
else:
# Use the default scenario name when scenario name = None
scenario = None

if len(args) < 2:
# User must pass in at least two arguments:
print "At least, two argument must be supplied."
print run.__doc__
return spss_sys_util.SUCCESS

elif len(args) == 2:
try:
target_start_time = time_util.spss_time(args[0])
target_end_time = time_util.spss_time(args[1])
except Exception, e:
print e
print run.__doc__
return not spss_sys_util.SUCCESS

elif len(args) == 3:
# If the first argument is a time, the last argument must be the output options
try:
target_start_time = time_util.spss_time(args[0])
target_end_time = time_util.spss_time(args[1])
output_option = args[2]
except:
# If the first argument is not a time, it must
# be the LRP.
try:
lrp = lrp_util.lrp(args[0])
target_start_time = time_util.spss_time(args[1])
target_end_time = time_util.spss_time(args[2])
except Exception, e:
print e
print run.__doc__
return not spss_sys_util.SUCCESS

elif len(args) == 4:
try:
start_check_interval = time_util.spss_time(args[0])
end_check_interval = time_util.spss_time(args[1])
target_start_time = time_util.spss_time(args[2])
target_end_time = time_util.spss_time(args[3])
except:
try:
lrp = lrp_util.lrp(args[0])
target_start_time = time_util.spss_time(args[1])
target_end_time = time_util.spss_time(args[2])
output_option = args[3]
except Exception, e:
print e
print run.__doc__
return not spss_sys_util.SUCCESS

elif len(args) == 5:
try:
start_check_interval = time_util.spss_time(args[0])
end_check_interval = time_util.spss_time(args[1])
target_start_time = time_util.spss_time(args[2])
target_end_time = time_util.spss_time(args[3])
output_option = args[4]
except:
try:
lrp = lrp_util.lrp(args[0])
start_check_interval = time_util.spss_time(args[1])
end_check_interval = time_util.spss_time(args[2])
target_start_time = time_util.spss_time(args[3])
target_end_time = time_util.spss_time(args[4])
except Exception, e:
print e
print run.__doc__
return not spss_sys_util.SUCCESS

else:
try:
lrp = lrp_util.lrp(args[0])
start_check_interval = time_util.spss_time(args[1])
end_check_interval = time_util.spss_time(args[2])
target_start_time = time_util.spss_time(args[3])
target_end_time = time_util.spss_time(args[4])
output_option = args[5]
except Exception, e:
print e
print run.__doc__
return not spss_sys_util.SUCCESS

if output_option not in ['f', 'm', 'b']:
print "Input output option =", output_option
print "The only legal values for output_option are 'f' and 'm'."
return not spss_sys_util.SUCCESS

if not lrp:
lrp = lrp_util.get_released_lrp()

print "LRP: ", lrp
print "Start time of check interval: ", start_check_interval
print "End time of check interval: ", end_check_interval
print "Target start time: ", target_start_time
print "Target end time: ", target_end_time
print "Use verified constraint windows:", include_vcw
if scenario:
print "Constraint scenario name: ", scenario
else:
print "Constraint scenario name: use default scenario name from relation constraint_scenarios"
if output_option == 'f':
print "Output reports: stuck.rpt"
elif output_option == 'm':
print "Output reports: move_it.rpt"
else:
print "Output reports: stuck.rpt, move_it.rpt"

report(lrp,
start_check_interval,
end_check_interval,
target_start_time,
target_end_time,
output_option,
include_vcw,
scenario)

return spss_sys_util.SUCCESS

def report(lrp,
start_check_interval,
end_check_interval,
target_start_time,
target_end_time,
output_options,
include_vcw=False,
scenario=None):
if start_check_interval:
visits = lrp_util.get_available_visits(start_check_interval,
end_check_interval,
lrp)
else:
visits = lrp_util.get_unavailable_visits(target_start_time,
target_end_time,
lrp)

if output_options in ['f', 'b']:
stuckFileId = open("stuck.rpt", 'w')
stuckFileId.write("Visits that CANNOT move to interval: %s - %s\n" % (str(target_start_time), str(target_end_time)))
if start_check_interval:
stuckFileId.write("from interval: %s - %s\n" % (str(start_check_interval), str(end_check_interval)))
available.header(target_start_time, lrp, stuckFileId, scenario)
else:
stuckFileId = None

if output_options in ['m', 'b']:
moveitFileId = open("move_it.rpt", 'w')
moveitFileId.write("Visits that can move to interval: %s - %s\n" % (str(target_start_time), str(target_end_time)))
if start_check_interval:
moveitFileId.write("from interval: %s - %s\n" % (str(start_check_interval), str(end_check_interval)))
available.header(target_start_time, lrp, moveitFileId, scenario)
else:
moveitFileId = None

format = available.FORMAT
target_window = time_util.window_list(time_util.window(target_start_time, target_end_time))
i = 0
stuck_visits = []
moveable_visits = []
progress_meter = progress.thermometer(len(visits))
progress_meter.update(0)
for visit in visits:
i += 1
try:
tup = available.get_tuple(visit, lrp, target_start_time, scenario)
cwv = visit.get_verified_constraint_windows()
cw = visit.get_constraint_windows()
cwv_intersect = cwv.intersection(target_window)
cw_intersect = cw.intersection(target_window)
if not cwv_intersect and not cw_intersect and stuckFileId:
stuckFileId.write((format + '\n') % tup)
stuck_visits.append(visit)
elif not cwv_intersect and cw_intersect and moveitFileId:
moveitFileId.write((format + ' w\n') % tup)
moveable_visits.append(visit)
elif cwv_intersect and not cw_intersect:
if include_vcw and moveitFileId:
moveitFileId.write((format + ' v\n') % tup)
moveable_visits.append(visit)
elif not include_vcw and stuckFileId:
stuckFileId.write((format + ' v\n') % tup)
stuck_visits.append(visit)
elif cwv_intersect and cw_intersect and moveitFileId:
moveitFileId.write((format + ' wv\n') % tup)
moveable_visits.append(visit)
except:
print "Error while working on visit:", visit
raise
progress_meter.update(i)
progress_meter.end()
return stuck_visits, moveable_visits

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