Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.stsci.edu/spst/UnixTransition/doc/pdbman.py
Дата изменения: Fri Feb 28 14:46:11 2014
Дата индексирования: Sat Mar 1 12:23:09 2014
Кодировка:
#MODULE pdbman
#
#***********************************************************************
"""

**PURPOSE** --
A module for the pdbman class.

**DEVELOPER** --
Don Chance

**MODIFICATION HISTORY** --

o Initial implementation 4/12/04
o Modfied 5/13/04 KWC - Change from pdbman to prd product type.
o Modfied 5/18/04 KWC - Add New_PRD_Dir to store PRD input directory.
"""
#***********************************************************************

__version__ = " 5/19/04 v1"

import cPickle
import os
import re
import string
import time

from boolean import *
from pass_environ_setup import *
import pass_product
import pass_util
import spss_sys_util
import time_util

# regular expression for finding out whether an element is an rcs file, or not
re_rcs = re.compile("^.+,v$")

class pdbman(pass_product.pass_product):
def __init__(self, verbose=0):
self.verbose = verbose

pass_product.pass_product.__init__(self, "prd")

self.SI = None
self.SOIF = None
self.New_PRD_Dir = None
self.New_PRD_Files = None
self.ODB_pickle = None
self.pickle_file = None
self.run_name = "PDBMAN"

def __repr__(self):
return "PDBMAN run of " + str(self.run_time)

def set_SI(self, si):
self.SI = si

def get_SI(self):
return self.SI

def set_SOIF(self, soif):
self.SOIF = soif

def get_SOIF(self):
return self.SOIF

def set_New_PRD_Dir(self, dir):
self.New_PRD_Dir = dir

def get_New_PRD_Dir(self):
if not self.__dict__.has_key('New_PRD_Dir'):
# Guard against old pickles which may not have the New_PRD_Dir attribute
self.New_PRD_Dir = ''
if (self.New_PRD_Files
and type(self.New_PRD_Files) == type({})
and self.New_PRD_Files.values()
and self.New_PRD_Files.values()[0]
and os.path.isfile(self.New_PRD_Files.values()[0][0])):
# Try to set New_PRD_Dir based on New_PRD_Files
self.New_PRD_Dir = os.path.abspath(os.path.dirname(self.New_PRD_Files.values()[0][0]))
elif USER_PRD_DIRS:
self.New_PRD_Dir = USER_PRD_DIRS[0]
return self.New_PRD_Dir

def set_New_PRD_Files(self, files):
self.New_PRD_Files = files

def get_New_PRD_Files(self):
return self.New_PRD_Files

def set_ODB_pickle(self, odb_pickle):
self.ODB_pickle = odb_pickle

def get_ODB_pickle(self):
return self.ODB_pickle

def get_pickle_file(self):
return self.pickle_file

def __set_default_run_directories(self):
"""Set up the default output directories.
"""
#make test directory name like current test system
test_dir_time = self.run_time.get_localtime().strftime('%B_%d_%Y_%H-%M%S').lower()
self.input_directory = string.lower(os.path.join(
PDBMAN_DISK,
test_dir_time,'pdbman'))
if not os.path.isdir(self.input_directory):
os.makedirs(self.input_directory)
self.output_area = self.input_directory
self.output_directory = self.input_directory

def run_prep(self):
""" Generates a file list pickle from the user selections.
"""
self.pickle_file = None

# Create run directories
self.__set_default_run_directories()

# Check to see if there is a file list GUI widget.
if self.New_PRD_Files:
# Create the file name with a unique time string.
time_string = self.run_time.get_localtime().strftime('%B_%d_%Y_%H-%M%S').lower()
self.pickle_file = os.path.join(self.input_directory,
'PRD_input_file_list_' + time_string + '.pickle')

# Determine the data type of the elements in the dictionary
# (whether they are rcs elements, or not).
# Set the value of data_type in the dictionary.
keys = self.New_PRD_Files.keys()
keys.sort()
for key in keys:
rcs_element = 0
file_element = 0
element_list = self.New_PRD_Files[key]
for element in element_list:
if re_rcs.search(element):
rcs_element = 1
else:
file_element = 1
if rcs_element and file_element:
line = " Error: input files can not be a mixture of \n"
line += "regular file and rcs elements (,v files) \n"
line += "Please clean up your input %s directory" % key
raise ValueError(line)

elif rcs_element:
self.New_PRD_Files['data_type'] = "rcs_element"
elif file_element:
self.New_PRD_Files['data_type'] = "file"
else:
line = "No rcs elements or PRD file elements are in your"
line += "\ninput %s file directory" % key
raise ValueError(line)

# Store the file list into the pickle.
fp = open(self.pickle_file, "w")
cPickle.dump(self.New_PRD_Files, fp)
fp.close()

# Create the script object
self.create_script()

def create_script(self):
self.script_obj = prd_script(self, self.verbose)
self.script_created = 1


class prd_script(pass_util.abstract_script):
def __init__(self, pdbman_obj, verbose=0):
pass_util.abstract_script.__init__(self, vms=false)
self.verbose = verbose
self.pdbman = pdbman_obj
scriptdir = os.path.join(os.path.dirname(self.pdbman.output_area),
"scripts")
logdir = os.path.join(os.path.dirname(self.pdbman.output_area),
"logs")
if not os.path.isdir(scriptdir):
os.makedirs(scriptdir)
self.script_path = os.path.join(scriptdir, "pdbman_script.%s" %
self.file_type)
if not os.path.isdir(logdir):
os.makedirs(logdir)
self.logpath = os.path.join(logdir, "pdbman_script.log")

# Limit jobname to 9 characters
self.jobname = string.split(spss_sys_util.basename(self.script_path),
".")[0][:9]


def write_script(self, script_dir="", script_name=""):
""" Gets all the parameters from the PDBMAN menu and uses them
as inputs for the regen_prd.csh script.
"""
if script_dir or script_name:
self.set_script_path(script_dir, script_name)
# Check if the pickle menu was enabled.
if self.pdbman.get_ODB_pickle():
PDBMAN_pickle_name = self.pdbman.get_ODB_pickle().get_pickle_path()
else:
PDBMAN_pickle_name = 'None'

lib_ver = self.pdbman.get_SI()

script = "#!/usr/bin/tcsh -f\n\n"

# The PRD_update_dict has keys for the data type (rcs element, or
# not) and the PRD file types (e.g., PRD_update_dict['data_type'],
# PRD_update_dict['PLCP']). The values for the data_type must be
# a one-element list containng 'rcs_element' or 'file'.
# Each PRD_file_type value is a list of files where the full
# path name is specified.
PRD_update_dict = self.pdbman.get_New_PRD_Files()
PRD_update_pickle = self.pdbman.get_pickle_file()

# Make sure that at least one file chosen for PDBMAN.
if (PRD_update_pickle == None):
line = "No PRD file updates found. \n"
line += "Please select a file before running PDBMAN."
raise ValueError(line)

script += spss_sys_util.resolver("COM", "gen_prd.csh") + ' '

if self.verbose:
print "Selected list:"
print " PASS SW Version = ", self.pdbman.get_software_version()
print " ODB = ", PDBMAN_pickle_name
print " SI = ", lib_ver
print " PRD = ", PRD_update_dict
print " PRD Update Pickle = ", PRD_update_pickle
print " Working directory = ", self.pdbman.output_directory
print " MSCL config file = ", self.pdbman.config_file

script += self.pdbman.get_software_version() + ' '
script += PDBMAN_pickle_name + ' '
script += lib_ver + ' '
script += PRD_update_pickle + ' '
script += self.pdbman.output_directory + ' '
script += self.pdbman.config_file
script += '\n'

script_file =open(self.script_path, 'w')
script_file.write(script)
script_file.close()
try:
os.chmod(self.script_path,0777)
except:
pass
return self.script_path