Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.stsci.edu/spst/UnixTransition/doc/checklist.py
Дата изменения: Fri Apr 8 12:46:10 2016
Дата индексирования: Sun Apr 10 21:30:53 2016
Кодировка:
#
#MODULE checklist
#
#***********************************************************************
"""

**PURPOSE** --
This module calls a series of tools used in calendar/SMS checklisting.

**DEVELOPER** --
Don Chance

**MODIFICATION HISTORY** --

o Initial implementation 3/17/00
o Modified for python 2.2 compatibility. dc 5/28/03
o Make -i=gui the default. dc 10/29/03
o Add an option to not load the pickle file. drc 10/14/09
o Updated for PASS checklist. drc 6/18/14
o fix pickle naming. drc 7/2/15
"""
#***********************************************************************
from checklist_init import *
import spst_getopt

__version__ = '15.07.02'


def run(*args):
"""Run the calendar/SMS/PASS checklist.

Usage:
do checklist calendar_or_sms_name [-p=previous_calendar] [-i=cl|gui] [-t=cal|sms|pass] [-nopickle]

The previous calendar defaults to the continuity calendar from the global
baseline or None if there is no continuity calendar. The previous calendar
can be forced to be None by entering '-p=none'.

The -i option tells the script whether to run in command line mode (cl) or
to in graphical mode (gui). The default is gui.

The -t option tells the script whether you want to run an PASS, SMS or calendar (cal)
checklist. The default is calendar.

The -nopickle option causes the pickle file which stores the results of previous runs of the
checklist on the input calendar or sms to not be loaded.

WARNING: This script will overwrite your map files.
"""

if not args:
# Spew out the usage and quit when no calendar is given
print run.__doc__
return spss_sys_util.SUCCESS

allowed_options = ['previous_calendar=',
'interface=',
'type=',
'nopickle',
'pickle']

# Set up defaults
previous_calendar = None
interface = "gui"
Type = "cal"
use_pickle = True

# Parse the optional arguments
options, parms = spst_getopt.spst_getopt(args, allowed_options)

if parms:
calendar_or_sms_name = parms[0]
else:
raise ValueError('No calendar or sms name specified.')

if '-previous_calendar' in options.keys():
previous_calendar = options['-previous_calendar']

if '-interface' in options.keys():
interface = options['-interface']
if interface not in ("cl", "gui"):
raise ValueError("The -i option must equal cl or gui.")

if '-type' in options.keys():
Type = options['-type'].lower()
if Type not in ("cal", "sms", "pass"):
raise ValueError("The -t option must equal cal, sms or pass.")
if Type == 'cal':
from calchecklist import cal
elif Type == 'sms':
from smschecklist import sms
else:
from passchecklist import Pass
use_pickle = False

if '-pickle' in options.keys():
use_pickle = True

if '-nopickle' in options.keys():
use_pickle = False

# Constructed the name of the pickle file
pickled_name = os.path.join(spss_sys_util.resolver(Type.upper() + 'CHECK_DIR'),
calendar_or_sms_name.lower().replace(":", "_")
+ "_" + Type + "_checklist.pickled")

# Check to see if a pickled version already exists...
if use_pickle and os.path.isfile(pickled_name):
try:
checklist_obj = cPickle.Unpickler(open(pickled_name)).load()
if Type == "cal":
checklist_obj.set_previous_calendar(previous_calendar)
except:
print "Could not load %s. Continuing...." % pickled_name
if Type == "cal":
checklist_obj = cal(calendar_or_sms_name, previous_calendar)
elif Type == "sms":
checklist_obj = sms(calendar_or_sms_name)
else:
checklist_obj = Pass(calendar_or_sms_name)
else:
if Type == "cal":
checklist_obj = cal(calendar_or_sms_name, previous_calendar)
elif Type == "sms":
checklist_obj = sms(calendar_or_sms_name)
else:
checklist_obj = Pass(calendar_or_sms_name)

try:
if interface == "cl":
checklist_obj.run_checks_cl()
else:
checklist_obj.run_checks_gui()
finally:
try:
pickled_name = os.path.join(spss_sys_util.resolver(Type.upper() + 'CHECK_DIR'),
checklist_obj.get_name().lower().replace(":", "_")
+ "_" + Type + "_checklist.pickled")
except:
pass

# On the way out, pickle the checklist so that we can come back to it later
cPickle.Pickler(open(pickled_name, 'w')).dump(checklist_obj)

return spss_sys_util.SUCCESS


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