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

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

**PURPOSE** --

Checks the contents of a pickle file.

python dump_pickle_file.py

**DEVELOPER** --
K. Clark

**MODIFICATION HISTORY** --

o Initial implementation 7/17/03 KWC
o Modified 11/25/03 KWC - Use new configure_util methods.
o modified for mag field object. drc 3/14/06
"""
#***********************************************************************

__version__ = "3/14/06"

import os, sys
import configure_util, ephem_util, spss_sys_util

class dump_pickle_file:

def __init__(self, file_name):
""" Dumps the contents of a pickle file and verifies the location of
the configured files belonging to the pickle.
"""

# Try to resolve the file name.
full_file_name = self.find_file(file_name)

if (full_file_name == None):
print " *** Error - Unable to find pickle file:", file_name
else:
pickle_object = configure_util.get_pickled_object(full_file_name)
if (pickle_object == None):
print " *** Error - Unable to read pickle file:", full_file_name
else:
# Generate a report on the requested pickle file.
pickle_object.report()
pickle_type = pickle_object.get_type()

if (pickle_type == "mscl"):

# Display MS setup parameters.
self.dump_MS_setup(pickle_object)

# Display CL setup parameters.
self.dump_CL_setup(pickle_object)

# Display the Configured files used.
self.dump_MSCL_config_files(pickle_object)

# Check to see if the configured files exist.
self.validate_MSCL_config_files(pickle_object)
else:
# Check to see if the configured files exist.
self.validate(pickle_object)

def dump_MS_setup (self, pickle_object):
""" Dumps selected MS setup parameters.
"""
ms_obj = pickle_object.get_ms()

print " SMS Name = ", ms_obj.sms.get_path()

merge_sms_list = ms_obj.get_merge_sms_list()
if (len(merge_sms_list) > 0):
print " Merge SMS name(s): ", merge_sms_list

MS_namelist_obj = ms_obj.get_basefile()
print "\n MS Basefile Settings: "
print " " + MS_namelist_obj.get_template_path()
print " " + MS_namelist_obj.get_comment()
print " Initial pointing parameters:"
print " RA: ", MS_namelist_obj.get_value('MINPCSHIS','RA')
print " DEC: ", MS_namelist_obj.get_value('MINPCSHIS','DEC')
print " ROLL: ", MS_namelist_obj.get_value('MINPCSHIS','ROLL')
print " SAA: ", MS_namelist_obj.get_value('MINPCSHIS','SA1ANGLE')

MS_namelist_obj = ms_obj.get_cin_file()
print "\n MS Command Input File Settings: "
print " " + MS_namelist_obj.get_template_path()
print " " + MS_namelist_obj.get_comment()

def dump_CL_setup (self, pickle_object):
""" Dumps selected CL setup parameters.
"""
for cl_obj in pickle_object.get_cls():

# Display selected CL Startup file parameters.
CL_namelist_obj = cl_obj.get_clstart()
print "\n CL Startup Settings: "
print " " + CL_namelist_obj.get_template_path()
print " " + CL_namelist_obj.get_comment()

Forced_NSSC_BRK = CL_namelist_obj.get_value('CLNINPUT','NSLDBRK')
if (len(Forced_NSSC_BRK) > 0):
print " CL Forced NSSC1 Load Break times = ", Forced_NSSC_BRK

Auto_Breaks = CL_namelist_obj.get_value('CLNINPUT','AUTOFLB')
print " CL Auto Load breaks = ", Auto_Breaks

Run_OPC = CL_namelist_obj.get_value('CLNINPUT','OPC_GEN')
print " Generate Output Catalog = ", Run_OPC

Catalog_Partials = CL_namelist_obj.get_value('CLNINPUT','OPC_PARTIALS')
print " CL Catalog partial loads = ", Catalog_Partials

# Display selected CL Basefile file parameters.
CL_namelist_obj = cl_obj.get_basefile()
print "\n CL Basefile Settings: "
print " " + CL_namelist_obj.get_template_path()
print " " + CL_namelist_obj.get_comment()

# Display the CL MOC Command input files used.
moc_inputs = cl_obj.get_moc_cmd_input_file()
if (len (moc_inputs) > 0):
print " CL MOC Command input files = ", moc_inputs

# Display the CL MOC Text input files used.
moc_txt_inputs = cl_obj.get_moc_txt_input_file()
if (len (moc_txt_inputs) > 0):
print " CL MOC Text input files = ", moc_txt_inputs


def dump_MSCL_config_files (self, pickle_object, Full_details=None):
""" Dumps MS/CL config files.
"""
mscl_config = pickle_object.get_config()
for product in mscl_config.values():
print "\n" + configure_util.PICKLE_TYPE_DICTIONARY[product.get_type()] + " Pickle:"

if (Full_details == None):
if product.get_type() == 'mag_field':
print " IGRF Location: ", product.get_directory()
print " IGRF Version: ", product.get_version()
print " Comment: ", product.get_comment()
print " Time Span: ", product
else:
# Just display a summary of the pickle file.
print " Location: ", product.get_pickle_path()
print " Comment: ", product.get_comment()
print " Time Span: ", product
else:
# Display the full contents of the pickle.
product.report()

def validate_MSCL_config_files (self, pickle_object):
""" Validates MS/CL config files.
"""
mscl_config = pickle_object.get_config()
keys = mscl_config.keys()
keys.sort()

# Check to see if the configured files exist.
for key in keys:
a_config = mscl_config[key]
if (a_config != None):
self.validate(a_config)

def find_file(self, file_name):
""" Looks for a pickle file. Handles full file specification as
well as just the file name without an extension.
"""
# Check to see if the file extension was left off.
if (os.path.splitext(file_name)[1] == ''):
file_name += '.pickle'

full_file_name = None

# Check to see if the file can be found.
if (os.path.isfile (file_name)):
full_file_name = os.path.abspath(file_name)
else:

# Get the default PASS pickle directory name(s).
pickle_directory = spss_sys_util.resolver("PASS_INPUT_PICKLES")
if (type(pickle_directory) == type([])):
# Handle a list of directories.
for dir in pickle_directory:
pickle_name = os.path.join(dir,file_name)
if (os.path.isfile(pickle_name)):
full_file_name = os.path.abspath(pickle_name)
break
else:
# Check for the file in just a single directory.
pickle_name = os.path.join(pickle_directory,file_name)
if (os.path.isfile(pickle_name)):
full_file_name = os.path.abspath(pickle_name)

return full_file_name

def validate (self, pickle_object):
""" Check to see if the configured files exist.
"""
# Get the configured file object dictionary.
config_file_dict = pickle_object.get_configured_file_dictionary()
valid_count = 0

keys = config_file_dict.keys()
keys.sort()

# Check if each file exists.
for file in keys:
if not(os.path.isfile(config_file_dict[file].get_configured_path())):
print "\n *** Error Unable to find %s file: %s" \
%(file, config_file_dict[file].get_configured_path())
else:
valid_count += 1

# Determine the type of this pickled object.
pickle_type = pickle_object.get_type()
file_type = pickle_type
if configure_util.PICKLE_TYPE_DICTIONARY.has_key(pickle_type):
file_type = configure_util.PICKLE_TYPE_DICTIONARY[pickle_type]

print "\n Found %i configured %s files out of %i." %(valid_count, file_type, len(keys))

# -------------- Run time interface ------------------------------------

def run(file_name=None):
""" Dump a pickle file and check to see if the configured files exist.

Usage:
do dump_pickle_file
where:
file name = pickle file name.

Searches the current directory and then PASS_INPUT_PICKLES
for the pickle file. Will append .pickle to the file name
if this extension is not given.
"""

dump_pickle_file (file_name)

if __name__ == '__main__':

if (len(sys.argv) <= 1):
print run.__doc__
sys.exit(1)

file_name = sys.argv[1]
dump_pickle_file (file_name)