Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.stsci.edu/spst/UnixTransition/doc/batsms.py
Дата изменения: Fri Apr 8 12:46:10 2016
Дата индексирования: Sun Apr 10 19:33:16 2016
Кодировка:

Поисковые слова: star
#
#MODULE batsms
#
#***********************************************************************
"""

**PURPOSE** --
Generate an SMS and all the ancillary files that go with it.

This tool is not generally called by users directly, but invoked
from sms.py.

Based on BATSMS2.COM.

**DEVELOPER** --
Don Chance

**MODIFICATION HISTORY** --

o Initial implementation 11/14/01
o fixed spacing problem on generate command. drc 11/28/01
o add code review enhancements. drc 12/3/01
o Fixup mapfile directory access. mdr 12/10/01
o Fix filename for SMS copied to todev. drc 12/21/01
o Make seperate map directory for plantest. drc 3/2/04
o Mods for new check_sms_gsacq tool and for smsg -eps -offset switch. mdr 1/21/05
o fix bug. drc 1/21/05
o put try block around sqr. drc 11/07/06
o Mods to generated dss html query. mdr 3/5/07
o add -trace as an smsg option. drc 8/13/08
o create and plot the calendar pointing profile. mdr 10/13/09
o change from $PMSQR/spec_inst_by_ccl.sqr to
o special_commanding_check.py. gab 12/4/12
o PR 80999 -- mdr 5/22/15
+ Mods for the updated check_sms_gsacq.py.
o PR 81072 -- mdr 6/1/15
+ Pass the full path to the gsacq history file to check_sms_gsacq.run
+ Missing the cclist part of the path - mdr 6/3/15
"""
#***********************************************************************
import spss_sys_util
import sms_util
import string
import spst_getopt
import os
import time_util
import shutil
import speccom_check
import check_sms_gsacq
import dss_query_by_calendar
import pointing_profile

__version__ = "15.06.03"

def run(smsname=None, *args):
"""Generate an SMS.

Usage:
do batsms sms_name [-glrest=]
[-restore=]
[-override]
[-offset]
[-initial_saang=]
[-same_ut=]
[-trace=]
[-test]

The -glrest option indicates the continuity SMS (for smsg -generate
and smsg -check).

The -restore option indicates the cache SMS name (for smsg -generate).

The -override option indicates an EPS merge will be generated with
an override file (for smsg -eps_merge).

The -offset option indicates an EPS merge will be generated with an
offset override file (for smsg -eps_merge).

The -initial_saang option indicates the initial solar array angle (for
smsg -eps_merge).

The -same_ut options indicates the reference time (for smsg -generate).

The -trace options governs the amount of output put into the trace file.
It may take one of the following values: brief, full, debug:cache,
debug:callframe, debug:globals, debug:labels, debug:pseudos, debug:query,
debug:tcs, debug:times, debug:values. Default is brief.

The -test option, if present, indicates that this is a test sms.
Otherwise, it's assumed this is a flight SMS.
"""

if not smsname:
# Spew out the usage and quit when no SMS name
# is provided.
print run.__doc__
return spss_sys_util.SUCCESS

# Parse the arguments
allowed_options = ['glrest=', 'override', 'offset', 'initial_saang=',
'same_ut=', 'restore=', 'test', 'trace=']
options, parms = spst_getopt.spst_getopt(args, allowed_options)

continuity = ""
link = ""
link_sms = None
eps_override = ""
eps_offset = ""
init_sa_angle = ""
ref_ut = ""
cache = ""
trace = ""
test_sms = 0

cal = sms_util.sms(sms_name=smsname)

if options.has_key('-glrest'):
continuity = ' -glrest=' + options['-glrest'] + ' '
link = ' -link=' + options['-glrest'] + ' '
link_sms = cal.set_continuity_sms(options['-glrest'])
else:
link = ' -link=default '
if options.has_key('-override'):
eps_override = ' -override '
if options.has_key('-offset'):
eps_offset = ' -offset '
if options.has_key('-initial_saang'):
init_sa_angle = ' -initial_saang=' + options['-initial_saang'] + ' '
if options.has_key('-same_ut'):
ref_ut = ' -same_ut=' + options['-same_ut'] + ' '
if options.has_key('-restore'):
cache = ' -restore=' + options['-restore'] + ' '
if options.has_key('-trace'):
trace = ' -trace=' + options['-trace'] + ' '
if options.has_key('-test'):
test_sms = 1

# Setup environment variables
if spss_sys_util.get_environ_variable('LOGNAME')[0] == 'planinst97':
pref = 'sm_'
elif spss_sys_util.get_environ_variable('LOGNAME')[0] == 'plantest':
pref = 'pt_'
else:
pref = ''

bmapdir = os.path.join( \
spss_sys_util.get_environ_variable('SPSS_DATA_DK')[0], 'mapdir')
if test_sms:
map_dir = os.path.join(bmapdir, pref + 'test_sms')
else:
map_dir = os.path.join(bmapdir, pref + 'flight_sms')

# Make the mapfile directory. Since mode doesn't seem to work in
# os.mkdir, use os.chmod immediately afterward.
if not os.path.isdir(map_dir):
os.mkdir(map_dir)
os.chmod(map_dir, 0777)

spss_sys_util.easyusr(map_space_dir=map_dir)


# Double check that the calendar exists before generating the SMS
calname = string.lower(cal.get_name())
if not cal.exists():
raise sms_util.SMSError("Cclist %s does not exist." % calname)

# Get the C&C list
cal.get()

# Generate the SMS
print "Current time =", time_util.spss_time()
smsg_generate = "smsg -generate -save " + trace + cache + continuity + calname
print smsg_generate
status, text = spss_sys_util.command(smsg_generate, 1)
print "Current time =", time_util.spss_time()
if status != spss_sys_util.SUCCESS:
raise sms_util.SMSError("smsg -generate failed! See log file (%s)." % cal.log_file)

# Format the SMS
smsg_format = "smsg -format " + calname
print smsg_format
spss_sys_util.command(smsg_format, 1)
print "Current time =", time_util.spss_time()

# Create the tree directory if it doesn't already exist
if not os.path.isdir(cal.sms_tree_path):
os.mkdir(cal.sms_tree_path)

# Copy the SMS to the tree directory
os.chdir(cal.sms_tree_path)
shutil.copy(cal.sms_path, os.path.join(cal.sms_tree_path,
calname + ".sms"))

# Create the special instruction report in the tree directory
try:
speccom_check.run(calname, cal.get_version(), '%s_spec_inst.rpt' % calname)
except:
print "Error running %s" % speccom_check
print spss_sys_util.get_traceback_string()

# For flight SMSs, copy the SMS to the 'instruct/to_dev' directory and
# check the GS acqs and generate DSS html.
if not test_sms:
shutil.copy(calname + ".sms", spss_sys_util.resolver('IM_TODEV'))
shutil.copy(calname + ".cal", spss_sys_util.resolver('IM_TODEV'))

prev_sms = cal.get_continuity_sms()
if (prev_sms is None):
check_sms_gsacq.run(calname, calname + ".gsacq")
else:
prev_hist_file = os.path.join(os.path.split(cal.sms_tree_path)[0], str(prev_sms).lower(), str(prev_sms).lower() + "_gsacq_history.pickle")
check_sms_gsacq.run(calname, calname + ".gsacq", prev_hist_file)
# end if

dss_query_by_calendar.run(calname, calname + "_dss.html", "-get_cal=0", "-sel_flag=1", \
"-obs_list=ALL", "-image_size=5")
print "Current time =", time_util.spss_time()

# Run smsg schedule
smsg_schedule = "smsg -schedule " + calname
print smsg_schedule
spss_sys_util.command(smsg_schedule, 1)
print "Current time =", time_util.spss_time()

# Run precedence checker
smsg_check = "smsg -check" + link + calname
print smsg_check
spss_sys_util.command(smsg_check, 1)
print "Current time =", time_util.spss_time()

# Update sms_catalog for continuity SMS
if link_sms:
print "Update sms_catalog for continuity SMS."
cal.update_continuity_sms()
print "Current time =", time_util.spss_time()

# Generate the eps merge SMS.
if not test_sms:
print "Generate EPS merge SMS."
eps_merge_command = ('smsg -eps_merge '
+ eps_override + eps_offset + init_sa_angle + calname)
spss_sys_util.command(eps_merge_command, 1)
print "Current time =", time_util.spss_time()

# Generate the dms merge SMS.
print "Generate DMS merge SMS."
cal.create_dms_sms()
print "Current time =", time_util.spss_time()

# Copy the support schedule to the tree directory
shutil.copy(os.path.join(cal.sms_directory_path, "%s.psc_%i" % (calname, cal.sms_version)),
cal.sms_tree_path)

# Create the .aters and .trers files
print "Create the .aters and .trers files"
cal.make_ers_files()

if not test_sms:
# Create the pointing profile
# Do it here because a cclist -get is done and don't want to mess up smsg
print "Create the pointing profile report"
pp_report = "%s_pp.rpt" % calname
pointing_profile.run(calname, pp_report)


print "Current time = ", time_util.spss_time()

return spss_sys_util.SUCCESS