Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.stsci.edu/spst/UnixTransition/doc/start_end_times_check.py
Дата изменения: Fri Apr 8 12:46:13 2016
Дата индексирования: Mon Apr 11 05:42:29 2016
Кодировка:

Поисковые слова: п п п п п п п п п п п п п п п п п р п р п р п р п р п р п р п р п р п р п р п р п р п р п р п р п п п п п п
#
#MODULE start_end_times_check
#
#***********************************************************************
"""

**PURPOSE** --
This module contains a class that checks the calendar start and end
times for consistency with SPST standard practices.

**DEVELOPER** --
Don Chance

**MODIFICATION HISTORY** --

o Initial implementation 9/21/00

o Changed calendar lead time to 2 weeks. drc 2/27/01

o Modified for T-11 scheduling. drc 9/10/01

o code cleanup drc 12/7/15
"""
#***********************************************************************
from abstract_check import abstract_check, PASS, UNKNOWN
from checklist_init import CAL_LEAD_TIME
import time_util


class start_end_times_check(abstract_check):
"""Verify calendar start and end times
"""
def run(self):
abstract_check.run(self)

file_pointer = open(self.outfile, "w")

start = self.my_checklist.calendar.get_begin_time()
end = self.my_checklist.calendar.get_end_time()

file_pointer.write("Calendar start time = %s\n" % start)
file_pointer.write("Calendar end time = %s\n" % end)

standard = 1

# Check that the calendar begins on a Monday
if start.strftime('%w') == '1':
file_pointer.write("The calendar begins on a Monday. This is standard.\n")
else:
file_pointer.write("The calendar begins on a %s. This is non-standard.\n"
% start.strftime('%A'))
standard = 0

# Check that the calendar begins exactly on a day boundary
if time_util.spss_time(start.strftime("%Y.%j")) == start:
file_pointer.write("The calendar begins exactly on a day boundary. This is standard.\n")
else:
file_pointer.write("The calendar does not begin on a day boundary. This is non-standard.\n")
standard = 0

# Check that the calendar is exactly one week long
if end == start + 7*24*60*60:
file_pointer.write("The calendar is exactly one week long. This is standard.\n")
else:
file_pointer.write("This calendar has a length of %s. This is non-standard.\n" %
str(end-start))
standard = 0

# Check that the calendar start time is in the future,
# but no more than 11 days in the future.
if (time_util.spss_time() + CAL_LEAD_TIME > start > time_util.spss_time()):
file_pointer.write("""The calendar begins sometime between now and 11 days from now.
This is standard.\n""")
else:
file_pointer.write("""The calendar does not begin sometime between now and 11 days from now.
This is non-standard.\n""")
standard = 0

# Check that the first five characters of the calendar name match
# the begin year and day
if start.strftime('%y%j') == self.my_checklist.calendar.get_name()[:5]:
file_pointer.write("""The first five characters of the calendar name match the start time (yyddd).
This is standard.\n""")
else:
file_pointer.write("""The first five characters of the calendar name do not match the start time
(yyddd). This is non-standard.\n""")
standard = 0

# If everything was standard, the check passes.
if standard:
self.pf_status = PASS
else:
self.pf_status = UNKNOWN
return self.pf_status


def run(calendar):
"""Run the check stand alone.
"""
import calchecklist
clist = calchecklist.cal(calendar, 'none', 1)
check = start_end_times_check(clist)
print "\n Output sent to file " + check.outfile
check.run()