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

Поисковые слова: туманность андромеды
#!/usr/bin/env python
#
#***********************************************************************
"""

**PURPOSE** --

This is the main script for building PRD files from a list of
changes.

python gen_prd_batch.py -change_dir=
-pickle_name=
-PDBMAN=
-diff=

**DEVELOPER** --
K. Clark

**MODIFICATION HISTORY** --

o Initial implementation 8/ 8/03
o Modified 1/26/04 KWC - Allow directory or pickle file input.
o Modified 3/31/04 KWC - Add support for rcs elements.
o Modified 4/ 7/04 RSK - Added PDBMAN and diff options.
o Modified 4/15/04 KWC - Clean up code.

"""

__version__ = " 4/15/04"

import os, string, sys
import spst_getopt
import build_PRD_dataset

class gen_new_prd (build_PRD_dataset.build_PRD_dataset):

def __init__(self, si_ver, new_file_dir, user_pickle_file, out_dir=None,
PDBMAN_run="Yes", diff_flag="No"):
""" Create a set of PRD files which have the latest changes in
pdb_change.
si_ver is the PRD library branch - OPS or SM4 data.
new_file_dir is a directory where the new PRD elements may be
found.
user_pickle_file is a pickle file containing a list of the
new PRD elements or RCS,v files to be included.
out_dir is where the new files will be written.
"""

# Check to see if there are any new PRD elements to be found in
# directory.
if ((new_file_dir != None) and (not os.path.exists(new_file_dir))):
print "***Error - gen_new_prd: PRD input file directory not found"
print " ", new_file_dir
return

# Check to see if there is a pickle containing the new PRD elements or
# RCS,v files.
if ((user_pickle_file != None) and
(not os.path.isfile(user_pickle_file))):
print "***Error - gen_new_prd: PRD input file pickle not found"
print " ", user_pickle_file
return

# Change default to the output directory.
if (out_dir != None):
if (not os.path.exists(out_dir)):
os.mkdir(out_dir)
os.chdir(out_dir)

# Make sure the library SI branch name is lower case.
si_ver = string.lower(si_ver)

# Call the base class constructor.
build_PRD_dataset.build_PRD_dataset.__init__(self)

# If a directory was given, generate a list of the new elements to
# be used.
if (new_file_dir != None):
self.find_new_user_files(new_file_dir)

# If a pickle was given, unpack it.
if (user_pickle_file != None):
self.unpack_user_pickle(user_pickle_file)

# Create a new PRD dataset for each PRD directory that has changes.
# Use the value of the data_type key to determine whether the pickle
# file contained RCS,v files or flat PRD element files.
if self.new_user_file_dict['data_type'] == "file":

# Remove the data_type key to process the flat PRD element files.
del self.new_user_file_dict['data_type']

# Build a new PRD dataset from the configured PRD elements and
# a list of flat PRD element files.
new_PRD_file_dict = self.build_from_user_file_list (si_ver)

elif self.new_user_file_dict['data_type'] == "rcs_element":

# Remove the data_type key and process the rcs elements.
del self.new_user_file_dict['data_type']

# Move the RCS,v files into the work directory.
change_root = self.copy_rcs_files ()

# Build a new PRD dataset from the RCS,v files in the change
# directory tree.
new_PRD_file_dict = self.build_from_change_tree (si_ver, change_root)

else:
print "Data type of elements not determined."
sys.exit()

# Write out the PRD dataset to disk.
self.gen_PRD(new_PRD_file_dict, PDBMAN_run, diff_flag)

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

def run (si_ver=None, out_dir=None, in_dir=None, pickle_name=None,
PDBMAN_run="Yes", diff_flag="No", *args):
"""Build a new set of PRD files from the latest version of the
PRDUVM libraries.

Usage:
do gen_prd_batch -change_dir=
-pickle_name=
-PDBMAN=
-diff=

where:
SI Version = Science Instrument Compliment Version
(OPS or SM4).
Out dir = Output directory.

input file options (Choose just 1):
-change_dir = Directory to find change PRD
files.
-pickle_name = Pickle containing dictionary
of change PRD files.
run options:
-PDBMAN = Setup output directory for
PDBMAN run.
-diff = Difference new file against
reference file.

"""

if ((not si_ver) or (not out_dir)):
# Spew out the usage and quit when no initial directory
# is provided.
print run.__doc__
return

allowed_options = ['change_dir=', 'pickle_name=', 'PDBMAN=', 'diff=' ]
try:
options, parms = spst_getopt.spst_getopt(sys.argv, allowed_options)
except Exception,e:
e = '%s\n%s' %(e,run.__doc__)
raise IOError(e)

in_dir = None
if '-change_dir' in options.keys():
in_dir = options['-change_dir']

pickle_name = None
if '-pickle_name' in options.keys():
pickle_name = options['-pickle_name']

# Must have at least one option but not both.
if (((in_dir == None) and (pickle_name == None)) or
((in_dir != None) and (pickle_name != None))):
print "*** Error - must pick input directory OR pickle."
print run.__doc__
sys.exit(1)

if '-PDBMAN' in options.keys():
PDBMAN_run = options['-PDBMAN']

if '-diff' in options.keys():
diff_flag = options['-diff']

gen_new_prd(si_ver, in_dir, pickle_name, out_dir, PDBMAN_run, diff_flag)

if __name__ == '__main__':

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

si_ver = sys.argv[1]

out_dir = None
if (len(sys.argv) >= 3):
out_dir = sys.argv[2]

allowed_options = ['change_dir=', 'pickle_name=', 'PDBMAN=', 'diff=' ]
try:
options, parms = spst_getopt.spst_getopt(sys.argv, allowed_options)
except Exception,e:
e = '%s\n%s' %(e,run.__doc__)
raise IOError(e)

in_dir = None
if '-change_dir' in options.keys():
in_dir = options['-change_dir']

pickle_name = None
if '-pickle_name' in options.keys():
pickle_name = options['-pickle_name']

# Must have at least one option but not both.
if (((in_dir == None) and (pickle_name == None)) or
((in_dir != None) and (pickle_name != None))):
print "*** Error - must pick input directory OR pickle."
print run.__doc__
sys.exit(1)

PDBMAN_run = "Yes"
if '-PDBMAN' in options.keys():
PDBMAN_run = options['-PDBMAN']

diff_flag = "No"
if '-diff' in options.keys():
diff_flag = options['-diff']

gen_new_prd(si_ver, in_dir, pickle_name, out_dir, PDBMAN_run, diff_flag)