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

Поисковые слова: http astrokuban.info astrokuban
#MODULE send_shift
#
#*******************************************************************
"""

**PURPOSE** --
Create combined shift report,allow for exclusive user editing and
mail report to PE_DAT:shift.dis

**DEFINITIONS** --

**DEVELOPER** --
Greg Wenzel

**MODIFICATION HISTORY** --
initial implimentation gww 04/17/2000
code review updates gww 05/22/2000
remove _d and _s reports after combined. gww 06/21/2000
remove _d and _s reports after sent. gww 10/10/2000
set skip_rpt = true for swing shift gab 10/11/2005

**USAGE** --
do send_shift []
- (optional) must be a string in
spss time format YYYY.JJJ(:HH:MM:SS) OR spss week_id format YYJJJ.
Note: if no (:HH:MM:SS) are entered the time is assumed
to be day shift and it does not look back an additional day.

"""
#*******************************************************************
HOUR_SWING = 8 # hour at which to ignore look back for the day on swing shift.

import spss_sys_util,ccl_util,string,os,sys,time_util,exceptions,re
import file_util
from boolean import *

def run(time_of_report_spss=None):
"""Edits shift report

**USAGE** --
do send_shift []
- (optional) must be a string in
spss time format YYYY.JJJ(:HH:MM:SS) OR spss week_id format YYJJJ.
Note: if no (:HH:MM:SS) are entered the time is assumed
to be day shift and it does not look back an additional day.

"""
shift_report_directory = os.path.join(
spss_sys_util.resolver('SPSS_DATA_DK3',0), 'planinst/shift')

shift_distribution = spss_sys_util.resolver("PE_DAT","shift.dis")
mail_flag = true # true for dis list, false for address

if time_of_report_spss is not None:
try:
# default to day shift time for a more understandable behavior
# - no swing shift look back.
if re.search(r'\d\d\d\d\d$',time_of_report_spss):
time_of_report_spss = time_util.weekid(
time_of_report_spss).guess_starttime()
add = HOUR_SWING*60*60 + 1*60*60
elif re.search(r'\d\d\d\d.\d\d\d$',time_of_report_spss):
add = HOUR_SWING*60*60 + 1*60*60
else:
add = 0
time_of_report_spss = time_util.spss_time(time_of_report_spss) + add
except Exception,e:
print run.__doc__
raise Exception,e
else:
time_of_report_spss = time_util.spss_time()

#look back one day for reports if in early hours of the day.
if string.atoi(time_of_report_spss.strftime("%H")) < HOUR_SWING:
time_of_report_spss = time_of_report_spss - 24*60*60

report_file_time = time_of_report_spss.strftime("%y%j")

send_shift_report_file_path = os.path.join(shift_report_directory,
report_file_time + ".rpt")

day_shift_report_file_path = os.path.join(shift_report_directory,
report_file_time + "_d.rpt")

swing_shift_report_file_path = os.path.join(shift_report_directory,
report_file_time + "_s.rpt")

skip_rpt = false
while not os.path.exists(day_shift_report_file_path) and not skip_rpt:
print ""
print "Day shift report file not found: %s_d" \
% report_file_time
print "Enter day shift report file name"
prompt = " >> "
report_file_name = raw_input("%s" % prompt)
if string.strip(string.lower(report_file_name))[0] == "c":
skip_rpt = true
elif string.strip(string.lower(report_file_name))[0] == "q":
return spss_sys_util.SUCCESS
day_shift_report_file_path = os.path.join(shift_report_directory,
report_file_name + ".rpt")

skip_rpt = true
while not os.path.exists(swing_shift_report_file_path) and not skip_rpt:
print ""
print "Swing shift report file not found: %s_s" \
% report_file_time
print ""
print "Enter swing shift report file name"
prompt = " >> "
report_file_name = raw_input("%s" % prompt)
if string.strip(string.lower(report_file_name))[0] == "c":
skip_rpt = true
elif string.strip(string.lower(report_file_name))[0] == "q":
return spss_sys_util.SUCCESS
swing_shift_report_file_path = os.path.join(shift_report_directory,
report_file_name + ".rpt")


send_shift_report_file_path = \
string.lower(send_shift_report_file_path)
try:
send_shift_report_file = open(send_shift_report_file_path, 'w')
except IOError:
error_string = 'Could not open file for write:' +\
send_shift_report_file_path
raise IOError,error_string

#copy day shift report to send shift report.
day_shift_report_file_path = \
string.lower(day_shift_report_file_path)
if os.path.exists(day_shift_report_file_path):
try:
day_shift_report_file = open(day_shift_report_file_path, 'r')
except IOError:
error_string = 'Could not open file for read:\n' +\
day_shift_report_file_path
raise IOError,error_string
send_shift_report_file.writelines(day_shift_report_file.readlines())
day_shift_report_file.close()

#copy swing shift report to send shift report.
swing_shift_report_file_path = \
string.lower(swing_shift_report_file_path)
if os.path.exists(swing_shift_report_file_path):
try:
swing_shift_report_file = open(swing_shift_report_file_path, 'r')
except IOError:
error_string = 'Could not open file for read:\n' +\
swing_shift_report_file_path
raise IOError,error_string
send_shift_report_file.write("\n\n")
send_shift_report_file.write("%s" % (80*"*"))
send_shift_report_file.write("\n\n")
send_shift_report_file.writelines(swing_shift_report_file.readlines())
swing_shift_report_file.close()
else:
send_shift_report_file.write("%s" % (80*"*"))
send_shift_report_file.write(\
string.center("\nNO swing shift report!",80))
send_shift_report_file.close()

#edit send shift report file
try:
send_shift_report_file_path = string.lower(send_shift_report_file_path)
file_util.exclusive_file_edit(send_shift_report_file_path)
except file_util.FileInUseError:
print ""
print "Try again later!"
return spss_sys_util.SUCCESS

#mail shift report
subject = "SPST Shift Summary for %s" % \
time_of_report_spss.strftime("%d-%b-%Y Day %j")
print ""
print "The Shift Report is ready to be distributed NOW."
print "If you are satisfied with the content of the Report"
print "you may continue."
print ""

prompt = "(s)end the report, or (q)uit? >> "
q_send_shift = 'c'
while string.strip(string.lower(q_send_shift))[0] != 's' and\
string.strip(string.lower(q_send_shift))[0] != 'q':

q_send_shift = raw_input("%s" % prompt)

if string.strip(string.lower(q_send_shift))[0] == "s":
try:
print "Mailing report!"
spss_sys_util.mail(shift_distribution,subject,\
send_shift_report_file_path,mail_flag)
while os.path.exists(day_shift_report_file_path):
os.remove(day_shift_report_file_path)
day_shift_report_file_path = os.path.join(day_shift_report_file_path,
"~")
while os.path.exists(day_shift_report_file_path):
os.remove(day_shift_report_file_path)
while os.path.exists(swing_shift_report_file_path):
os.remove(swing_shift_report_file_path)
swing_shift_report_file_path = os.path.join(swing_shift_report_file_path,
"~")
while os.path.exists(swing_shift_report_file_path):
os.remove(swing_shift_report_file_path)
except:
print ""
print "Error Mailing shift report!"
print ""
return not spss_sys_util.SUCCESS
return spss_sys_util.SUCCESS

if __name__ == '__main__':
if len(sys.argv) > 1:
input_data = sys.argv[1]
else:
input_data = None
run(input_data)