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

Поисковые слова: barnard 68
#
#MODULE gstdn.py
#
#***********************************************************************
"""

**PURPOSE** --
A module for generating the pass tdrs schedules

**DEVELOPER** --
Greg Wenzel

**MODIFICATION HISTORY** --
o initial implementation GWW 04/17/02
o modified for new pickle format. GWW 10/29/03
o updated comment; code cleanup drc 4/8/15
o fix bug when verbose is used. drc 10/14/15
"""
#***********************************************************************
import sched_util
import spst_getopt
import sys
import spss_sys_util
import os
import configure_util
import copy
import time_util
import shutil
import pass_util

__version__ = '15.10.14'


def run(*args):
"""Ground Station schedule generation tool.

Usage:
do gstdn [-software_version= ]
[-batch]
[-verbose]

-software_version= defaults to 'ops' , others are 'old','new'
-batch make all file and cms/pickle selections automatically.
-verbose write debuging info to screen
"""
#default input values
sw_version = 'ops'
verbose = False
batch = False

#get input options.
allowed_options = ['software_version=',
'verbose',
'batch']

try:
options, parms = spst_getopt.spst_getopt(args, allowed_options)
except Exception, e:
e = '%s\n%s' % (e, run.__doc__)
raise IOError(e)

if '-software_version' in options.keys():
sw_version = options['-software_version'].lower()

if '-verbose' in options.keys():
verbose = True

if '-batch' in options.keys():
batch = True

#set root output directory. Output will be in sched directory under the
#root defined here.
root_dir = spss_sys_util.resolver("PASSOUT")

# get the input line summary file from fdf area
linesumm_path = get_linesumm_path(batch)
if batch and not linesumm_path:
return

#manage the input area so Linesumm files are not reprocessed and
#any test or non operational data is not automatically processed.
current_time = time_util.spss_time()
span = sched_util.get_times_from_linesumm(linesumm_path)
date_start = span.starttime()
new_file_name = date_start.strftime('processed_hst_linesumm_%y%j.txt')
fdf_dir = os.path.normpath(spss_sys_util.get_environ_variable("SPST_FDF_FTP_DIR")[0])
new_linesumm_path = os.path.join(fdf_dir, new_file_name)

#if in batch check file selected.
if batch:
if not (date_start > current_time-60*60*24*2 and date_start < current_time+60*60*24*2):
new_file_name = date_start.strftime('test_hst_linesumm_%y%j.txt')
new_linesumm_path = os.path.normpath(os.path.join(fdf_dir, new_file_name))
shutil.copy(linesumm_path, new_linesumm_path)
os.remove(linesumm_path)
error_text = '\n\nLine summary file NOT correct start date!'
error_text += '\nLine summary file renamed to: %s' % new_linesumm_path
raise IOError(error_text)

#copy linesumm to processed name
#shutil.copy will traceback if it failes so linesumm_path will
#not be deleted if an error occurs.
os.chmod(linesumm_path, 0777)
shutil.copy(linesumm_path, new_linesumm_path)
os.remove(linesumm_path)
linesumm_path = new_linesumm_path
ground_station_schedule = sched_util.gstdn_schedule(linesumm_path, root_dir)

if verbose:
ground_station_schedule.report()

#create gstdn file
status = ground_station_schedule.run(sw_version, False, verbose)

if verbose:
ground_station_schedule.report()

#check for errors
if not os.path.exists(ground_station_schedule.new_gstdn_file_path):
error_text = '\n\nScript Status: %s' % status
error_text += '\n\nScript status error!\nFiles were NOT configured!'
error_text += '\nSee output directory: %s' % ground_station_schedule.output_directory
max_error = pass_util.get_max_error_severity(ground_station_schedule.new_gstdn_log_path)
if max_error > 3:
error_text = '\n\nError severity of %s' % max_error
error_text += '\nSee output directory: %s' % ground_station_schedule.output_directory
raise IOError(error_text)
raise IOError(error_text)
else:
#define pickle lib.
pickle_directory = spss_sys_util.get_environ_variable(
"PASS_OUTPUT_PICKLES")[0]
pickle_in_directory_list = spss_sys_util.get_environ_variable(
"PASS_INPUT_PICKLES")
pickle_lib_list = configure_util.pickle_library_list(pickle_in_directory_list)
sched_pickle_list = pickle_lib_list.get_pickle_list().filter(pickle_type="sch")
sched_pickle_list.sort(configure_util.cmp_pickle_by_start)
old_pickle_path = sched_pickle_list[-1]
old_product = configure_util.get_pickled_object(old_pickle_path)

#create new product
new_product = configure_util.configured_product('sch')

#put tdrs schedule in product if one exists in configured area.
if old_product:
#copy old configured files to new_product
old_tdrssched_dict = old_product.get_configured_file_dictionary()
for configured_file in old_tdrssched_dict.values():
new_product.add_configured_file(configured_file)

#put new ground station file in new product. It overwrites the old
#file placed in above.
new_product.add_configured_file(ground_station_schedule)
if verbose and old_product:
print 'OLD PRODUCT'
old_product.report()
print 'NEW PRODUCT'
new_product.report()

#set comment field
comment = "TDRS spans: %s; GSTDN spans: %s - updated for gstdn file" % (new_product.get_configured_file_dictionary()['CFG_TDRSSCHD'].get_span(),
new_product.get_configured_file_dictionary()['CFG_GSTDNCON'].get_span())
if verbose:
print "New product comment:", comment
new_product.set_comment(comment)

#update configured areas
if not batch:
yesorno = raw_input(
'\nConfigure New ground station file (Y)es or = N(o)? >')
if yesorno.strip().lower() in ['y', 'ye', 'yes']:
configure = True
else:
configure = False
else:
configure = True

if configure:
new_pickle_path = new_product.configure_pickle(pickle_directory, verbose=verbose)

print '\n\nGround Station File:', \
ground_station_schedule.new_gstdn_file_path
print '\nConfigured!'
print 'New pickle:', new_pickle_path
stat = os.stat(ground_station_schedule.new_gstdn_file_path)
out_mode = stat[0] | 0444 | 0111
os.chmod(ground_station_schedule.new_gstdn_file_path, out_mode)
os.chmod(ground_station_schedule.new_gstdn_sum_path, out_mode)
os.chmod(ground_station_schedule.new_gstdn_log_path, out_mode)
else:
print '\n\nGround Station File:', \
ground_station_schedule.new_gstdn_file_path
print '\nNot configured!'


def get_linesumm_path(batch=False):
"""Get the latest Line Summary file.
"""
fdf_dir = spss_sys_util.get_environ_variable("SPST_FDF_FTP_DIR")[0]
linesumm_test_path = os.path.normpath(
os.path.join(fdf_dir, 'hst_linesumm*.txt'))
linesumm_list = spss_sys_util.glob(linesumm_test_path)
linesumm_test_path = os.path.normpath(
os.path.join(fdf_dir, 'HST_LineSumm*.txt'))
linesumm_list.extend(spss_sys_util.glob(linesumm_test_path))
linesumm_list.sort()
linesumm_path = None
if linesumm_list:
#if in batch pick the latest one, else prompt for input.
if batch:
linesumm_path = os.path.normpath(linesumm_list[-1])
else:
print '\n\nList of Line Summary files:'
for file in linesumm_list:
print os.path.normpath(file)
test_list = copy.deepcopy(linesumm_list)
test_list.append('')
while linesumm_path not in test_list:
linesumm_path = raw_input('Enter LineSumm file or =%s >' % linesumm_list[-1])
if not linesumm_path:
linesumm_path = os.path.normpath(linesumm_list[-1])
elif not batch:
raise IOError('\n\nNo linesumm files found in %s!' % fdf_dir)
return linesumm_path


# to run on commandline
if __name__ == '__main__':
input1 = None
if len(sys.argv) > 1:
run(*sys.argv[1:])
else:
run()