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

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

**PURPOSE** --

Provides a Gridware batch interface..


**DEVELOPER** --
K. Clark

**MODIFICATION HISTORY** --

o Initial implementation 1/ 6/03
o Use new data model. 8/25/03 KWC
o Modified 1/26/04 KWC - Add support for a list of files in a pickle.
o Modified 3/31/04 KWC - Fix missing PRD_update_dict assignment.
o Modified 4/ 6/04 KWC - Add check for PRD_update_dict data type.
"""
#***********************************************************************
__version__ = " 4/ 6/04"

import cPickle, re, os, string, time
from Tkinter import *
import Pmw

import data_model

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

class Submit_menu:

def __init__(self, aframe, input_values):
""" Constructor
"""

# Create a new frame for the Submit Menu.
self.frame = Frame (aframe)

self.Select_val = input_values

#Create the Batch que checkbutton menu.
self.que_list (self.frame)

# Create the job submission button
self.su_button = Button(self.frame, text="Submit",
command=self.submit)
self.su_button.pack()


#Create a scrolling text block for submit job messages.
que_group = Pmw.Group(self.frame, tag_text = 'Gridware Job List')

self.submit_text = Text (que_group.interior(), height=5, width=50)
self.submit_scroll = Scrollbar (que_group.interior(), \
command=self.submit_text.yview)
self.submit_text.configure(yscrollcommand=self.submit_scroll.set)
self.submit_text.pack(side=LEFT)
self.submit_scroll.pack(side=LEFT, fill=Y)
que_group.pack()

def que_list (self, aframe):
""" Creates a widget to select which gridware que(s) are to be
used.
"""

group = Pmw.Group(aframe, tag_text = 'Gridware Que')
self.gridware_que_list = ['aladdin.instruct', 'eno.instruct', \
'slalom.instruct', 'tigger2.instruct', \
'palpatine.instruct', 'menace.q', 'vader.q']
self.que_select = {}
for que in self.gridware_que_list:
self.que_select[que] = IntVar()
c = Checkbutton(group.interior(), text = que,
variable = self.que_select[que])
c.pack({"side": LEFT, "padx": 10, "pady": 10})

group.pack (padx=20, pady=20)

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

# Check to see if there is a file list GUI widget.
if self.Select_val['PDBMAN'].has_key('New_PRD_Files'):
# Create the file name with a unique time string.
time_string = time.strftime("%Y%m%d_%H%M%S",time.localtime(time.time()))
pickle_file = os.path.join(os.environ["BATCH_LOG"], \
'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 = PRD_update_dict.keys()
keys.sort()
for key in keys:
rcs_element = 0
file_element = 0
element_list = PRD_update_dict[key]
for element in element_list:
if re_rcs.search(element):
rcs_element = 1
else:
file_element = 1
if rcs_element and file_element:
print " Error: input files can not be a mixture of regular file and rcs elements (,v files)"
line = "Please clean up your input %s directory" % key
print line
sys.exit()
elif rcs_element:
PRD_update_dict['data_type'] = "rcs_element"
elif file_element:
PRD_update_dict['data_type'] = "file"
else:
print "No rcs elements or PRD file elements are in your"
line = "input %s file directory" % key
print line
sys.exit()

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

return pickle_file

def prd_gen_script(self):
""" Gets all the parameters from the PDBMAN menu and uses them
as inputs for the regen_prd.csh script.
"""

PASS_sw_ver = string.lower(self.Select_val['PDBMAN']['PASS_SW_Ver'].get())
# Check if the pickle menu was enabled.
if self.Select_val['PDBMAN'].has_key('ODB_pickle'):
PDBMAN_pickle_name = self.Select_val['PDBMAN']['ODB_pickle'].get()
else:
PDBMAN_pickle_name = 'None'

lib_ver = self.Select_val['PDBMAN']['SI'].get()

# regen_pdb gui has SOIF version, Test SMS version has new file list.
if self.Select_val['PDBMAN'].has_key('New_PRD_Files'):

# 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.Select_val['PDBMAN']['New_PRD_Files'].get()
PRD_update_pickle = self.prd_gen_file_pickle(PRD_update_dict)
soif_ver = ''
script = ' $PASSCOMLIB/gen_prd.csh '
else:
soif_ver = string.lower(self.Select_val['PDBMAN']['SOIF'].get())
PRD_update_dict = None
PRD_update_pickle = ''
script = ' $PASSCOMLIB/regen_prd.csh '

print "Selected list:"
print " PASS SW Version = ", PASS_sw_ver
print " ODB = ", PDBMAN_pickle_name
print " SI = ", lib_ver
print " SOIF = ", soif_ver
print " PRD = ", PRD_update_dict
print " PRD Update Pickle = ", PRD_update_pickle

script += PASS_sw_ver + ' '
script += PDBMAN_pickle_name + ' '
script += lib_ver + ' '
script += soif_ver
script += PRD_update_pickle

return script

def gridware_cmd(self):
""" Creates a gridware submit command for generating a new PDBMAN
run.
"""

merge_logs = ' -j y' #Combine error log and journal log into 1 file.
mail_notify = ' -m n' #Don't notify by mail when job done.

que_list = ' -q ' #List of Gridware que to run on.
for que in self.gridware_que_list:
if self.que_select[que].get() == 1:
que_list += que + ','

# Define the default Gridware que name.
if que_list == ' -q ':
que_list += 'tigger2.instruct'
else:
# Trim off the last trailing comma.
que_list = que_list[0:len(que_list) - 1]

job_name = ' -N prd_batch_'
time_string = time.strftime("%Y%m%d_%H%M",time.localtime(time.time()))
log_name = ' -o $BATCH_LOG/regen_prd_batch_' + time_string + \
'_\$JOB_ID.log'

script = self.prd_gen_script()

submit_command = 'qsub' + merge_logs + mail_notify + que_list + \
job_name + log_name + script

return submit_command


def submit(self):
""" Opens a Unix shell to submit the job to gridware.
"""

status = None
return_string = "Test job 253 "

# Fire off a pipe with the command and capture its return status.
cmd = self.gridware_cmd()
shell = os.popen(cmd, "r")
return_string = shell.read()
status = shell.close()

# Check for error messages.
if status != None:
print "\nError submitting job"
print "shell command = " + cmd
print "Status = %d", status
print "Error message = " + return_string
else:
print "submit command = ", cmd
a = string.split(return_string)
job_id = a[2]
job_list = " PRD generation has job " + job_id + "\n"
print job_list

#Update submit box with a list of submitted jobs.
self.submit_text.insert(END, job_list)