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

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

**PURPOSE** --

Gets all the environmental variables from a pickle containing
configured file objects and writes them out to a .csh shell script.

python build_config_script.py

**DEVELOPER** --
K. Clark

**MODIFICATION HISTORY** --

o Initial implementation 8/28/03 KWC
o Modified 11/25/03 KWC - Use new configure_util methods.
"""
#***********************************************************************

__version__ = "11/25/03"

import os, string, sys
import configure_util, spss_sys_util

class build_config_script:

def __init__(self, input_file, output_file='config_logicals'):
""" Create a new .csh shell configure script.
"""

# Locate the pickle file.
pickle_file = self.find_file(input_file)
if (pickle_file == None):
print " *** Error - Unable to find pickle file:", input_name
return

# Read in the pickle file.
try:
sel_pickle = configure_util.get_pickled_object(pickle_file)
except Exception, e:
print (" Error reading PDBMAN pickle file: " + pickle_file + str(e))

if (sel_pickle == None):
print " Error finding PDBMAN pickle file: " + pickle_file
return

# Check for valid output file name.
if ((output_file == None) or (output_file == "")):
output_file = 'config_logicals'

PASS_config = os.path.abspath(output_file)

try:
config_file = open(PASS_config, 'w')
except Exception, e:
print (' Error creating config file:' + PASS_config \
+ str(e))
return

# Write out the environment variables in .csh shell format.
config_file.writelines(sel_pickle.get_environment_definition_list())

try:
config_file.close()
except Exception, e:
print (' Error closing config file:' + PASS_config \
+ str(e))
return

# Set the proper file protection to allow the script to be executed.
os.chmod(PASS_config, (0777 & ~0022))

print '\n Created config file:', PASS_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


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

def run (pickle_file=None, output_file='config_logicals', *args):
""" Gets all the environmental variables from a pickle containing
configured file objects and writes them out to a .csh shell script.


Usage:
do build_config_script

where:
Pickle File = Name name of pickle file.
Output File = Name of .csh shell script.
(default = config_logicals)

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.
"""

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

build_config_script(pickle_file, output_file)

if __name__ == '__main__':

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

pickle_file = sys.argv[1]

output_file = 'config_logicals'
if (len(sys.argv) >= 3):
output_file = sys.argv[2]

build_config_script(pickle_file, output_file)