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

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

**PURPOSE** --
This module contains the abstract checklist class. Methods and
attributes common to both calendar and SMS checklists go here.

**DEVELOPER** --
Don Chance

**MODIFICATION HISTORY** --

o Initial implementation 9/21/00
o Modified for python 2.2 compatibility. dc 5/27/03
o break the checklist up into pages so that it more easily fits on
a small screen. drc 1/26/10
o add get_name function; cleanup and modernize. drc 7/1/15
"""
#***********************************************************************
from checklist_init import *
import spss_tk_util
if spss_tk_util.GUI_AVAILABLE:
from Tkinter import *
import Pmw

CHECKS_PER_PAGE = 15

__version__ = '15.07.01'


class abstract_checklist(object):
"""An abstract class for checklists.

Methods common to both calendar and SMS checklists go here.
"""
def __init__(self, calendar):
self.calendar = calendar
self.list_of_checks = []
self.type = ''
self.outdir = '.'

def __getstate__(self):
"""Special method used when pickling this object.

Copies __dict__, but excludes all unpicklable values.
"""
state_dict = {}
for key in self.__dict__.keys():
# root is a Tkinter object and cannot be pickled
if key != 'root' and key != 'notebook':
state_dict[key] = self.__dict__[key]
return state_dict

def __setstate__(self, state_dict):
"""Special method used to restore this object from a pickle.
"""
for key in state_dict.keys():
self.__dict__[key] = state_dict[key]

self.__restore__()
return

def __restore__(self):
pass

def get_name(self):
return self.calendar.get_name()

def run_checks_cl(self):
"""Run the command-line version of the checklist.
"""
check_no = 1
print " ",
for check in self.list_of_checks:
print "%i. %s" % (check_no, check.__doc__),
check_no = check_no + 1

print "\n Output will be sent to directory %s" % self.outdir

while 1:

user_checks = raw_input(
"\n Enter comma-separated list of checks to run, for all, q to quit >>> ")

if string.lower(user_checks) == 'q':
break
elif user_checks:
check_nos = []
str_checks = string.split(user_checks, ",")
for str_check in str_checks:
# Expand a range of checks....
if string.find(str_check, '-') != -1:
start, end = string.split(str_check, '-')
check_nos.extend(range(int(start), int(end)+1))
else:
check_nos.append(int(str_check))
else:
check_nos = range(1, len(self.list_of_checks)+1)

for check_no in check_nos:
check = self.list_of_checks[check_no-1]
print "***********************************"
print "Running check #%i, %s" % (check_no, check.__class__.__name__)
print check.__doc__

# Get the output file name from the check object
print "Output will be written to", check.outfile
result = check.run()
if result == PASS:
print "Check passes\n"
elif result == FAIL:
print ">>> Check FAILED <<<\n"
else:
print "Review output of this check to determine if it passed or failed.\n"

while 1:
end_prompt = raw_input(
"\n Enter t to type output file to screen, q to quit, anything else to continue >>> ")
if string.lower(end_prompt) == 't':
sys.stdout.writelines(open(check.outfile, 'r').readlines())
else:
break

if string.lower(end_prompt) == 'q':
break

# On the way out, write an Ascii version of the checklist
self.make_ascii_checklist()

def make_ascii_checklist(self):
"""Write an Ascii version of the checklist to a file.
"""
cfile_name = string.lower(self.calendar.get_name() + '_' + self.type) + ".checklist"
cfile = open(cfile_name,'w')

cfile.write(string.center("Checklist for %s" % str(self.calendar), 90) + "\n\n")

cfile.write("Start time: %s End time: %s\n" %
(str(self.calendar.get_begin_time()),
str(self.calendar.get_end_time())))

cfile.write("Date: %s Reviewer: %s\n" %
(time_util.spss_time().strftime('%c'),
spss_sys_util.get_environ_variable('MYNAME')[0]))

cfile.write("Pass/Fail Check Output File\n")

for i in range(1, len(self.list_of_checks)+1):
check = self.list_of_checks[i-1]
if check.pf_status == PASS:
cfile.write(" PASS ")
elif check.pf_status == FAIL:
cfile.write(" FAIL ")
elif check.has_been_run:
cfile.write(" UNKNOWN ")
else:
cfile.write(" ")
ltext = "%2i. %s" % (i, string.ljust(string.strip(str(check)), 75))
if check.has_been_run:
cfile.write("%s %s\n" % (ltext, check.outfile))
else:
cfile.write("%s\n" % ltext)

print "Checklist written to %s" % cfile_name

def run_checks_gui(self):
if not spss_tk_util.GUI_AVAILABLE:
raise NotImplementedError("Tkinter in unavailable. Use the -i=cl option instead")
self.root = Tk()

self.root.title(self.type + " Checklist for " + str(self.calendar))

# Initialize all the frames we'll use
frameHeaderinfo = Frame(self.root)
frameHeadercol1 = Frame(frameHeaderinfo)
frameHeadercol2 = Frame(frameHeaderinfo)
frameHeadercol3 = Frame(frameHeaderinfo)
frameHeadercol4 = Frame(frameHeaderinfo)
frameHeadercol5 = Frame(frameHeaderinfo)

# Setup all the buttons/labels we'll use in the header
labelStartTime = Label(frameHeadercol1, text="Start Time:")
entryStartTime = Entry(frameHeadercol2)
entryStartTime.insert(0, str(self.calendar.get_begin_time()))
entryStartTime["state"] = DISABLED

labelEndTime = Label(frameHeadercol3, text="End Time:")
entryEndTime = Entry(frameHeadercol4)
entryEndTime.insert(0, str(self.calendar.get_end_time()))
entryEndTime["state"] = DISABLED

labelDate = Label(frameHeadercol1, text="Date:")
entryDate = Entry(frameHeadercol2)
entryDate.insert(0, time_util.spss_time().strftime('%x'))
entryDate["state"] = DISABLED

labelReviewer = Label(frameHeadercol3, text="Reviewer:")
entryReviewer = Entry(frameHeadercol4)
entryReviewer.insert(0, spss_sys_util.get_environ_variable('MYNAME')[0])
entryReviewer["state"] = DISABLED

labelPassFail = Label(frameHeadercol1, text="Pass Fail")

buttonRunAll = Button(frameHeadercol5,
command=self.run_all_gui,
anchor=E,
width=13,
disabledforeground='gray',
text="Run all checks")

goodbye = Button(frameHeadercol5,
text="Quit",
anchor=E,
width=4,
command=self.quit_gui)
labelBogus = Label(frameHeadercol5, width=27)

#
# Checklist header is divided into 5 columns.
# Pack rightmost column first. The first thing that is packed into the
# rightmost column is a blank label that is nearly the same size as the
# check buttons. This will make the right side of the first 4 columns
# line up with the start of the check buttons. Put the 2 buttons:
# "run all checks" and "quit" in the 5th column.
#
frameHeaderinfo.pack(side=TOP, anchor=NW, expand=YES, fill=BOTH)
frameHeadercol5.pack(side=RIGHT)
labelBogus.pack(side=BOTTOM)
goodbye.pack(side=BOTTOM)
buttonRunAll.pack(side=BOTTOM)

# Pack the other 4 columns.
frameHeadercol1.pack(side=LEFT, expand=YES, fill=BOTH)
frameHeadercol2.pack(side=LEFT, expand=YES, fill=BOTH)
frameHeadercol3.pack(side=LEFT, expand=YES, fill=BOTH)
frameHeadercol4.pack(side=LEFT, expand=YES, fill=BOTH)

# First line of header -- names left justified; entries right justified
labelStartTime.pack(anchor=NW)
entryStartTime.pack(anchor=NE)
labelEndTime.pack(anchor=NW)
entryEndTime.pack(anchor=NE)

# Second line of header
labelDate.pack(anchor=NW)
entryDate.pack(anchor=NE)
labelReviewer.pack(anchor=NW)
entryReviewer.pack(anchor=NE)

# Third line of header
labelPassFail.pack(anchor=SW, side=BOTTOM)

self.notebook = Pmw.NoteBook(self.root)
npages = len(self.list_of_checks)/CHECKS_PER_PAGE
nchecks_list = npages * [CHECKS_PER_PAGE] + [len(self.list_of_checks) % CHECKS_PER_PAGE]
# The rest of the GUI is for all the checks
for i in range(len(nchecks_list)):
if nchecks_list[i]:
page = self.notebook.add('page%i' % (i+1), tab_text="Page %i" % (i+1))
for j in range(nchecks_list[i]):
checkno = i*CHECKS_PER_PAGE + j + 1
check = self.list_of_checks[checkno - 1]
check.pack(Frame(page), checkno)

self.notebook.pack(fill='both', expand=1, padx=10, pady=10)
self.notebook.setnaturalsize()

self.root.bind("", self.gui_update)
self.root.bind("", self.gui_update)
self.root.bind("", self.gui_update)

self.root.mainloop()

def gui_update(self, event):
self.root.update()

def quit_gui(self):
self.make_ascii_checklist()
self.root.destroy()
self.root.quit()

def run_all_gui(self):
check_nos = range(1, len(self.list_of_checks)+1)
for check_no in check_nos:
check = self.list_of_checks[check_no-1]
check.gui_run()