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

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

**PURPOSE** --
Delete an SMS, CCL, and associated files.

**DEVELOPER** --
Don Chance

**MODIFICATION HISTORY** --

o Initial implementation 12/14/00
o In pre-SPSS 44.2, smsg -delete always returns a failed status.
Catch error and continue. drc 6/13/01
o Remove pre-SPSS 44.2 code. drc 6/26/01
o Make user query more robust. drc 6/26/01
o Add sms/ccl version support and overall robustness. mdr 6/28/01
o Clean up some of the error messages. mdr 10/15/09
"""
#***********************************************************************
import spss_sys_util, sms_util, string

def run(smsname=None, *args):
"""Delete an SMS, CCL and associated files.

Usage:
do sms_cleanup [-ccl]
[-tree]
[-srt]
[-sms]
[-all]

The '-sms' qualifier will cause a smsg -delete to
be executed.

The '-tree' qualifier will cause the TREE files
and directories to be deleted.

The '-srt' qualifier will cause the SRT and checklist
files and directories to be deleted.

The '-ccl' qualifier will cause a cclist -delete to be
run.

The '-all' qualifier will cause all of the above three
options (sms, tree, and ccl) to be executed.

When no qualifiers are given, the user will be prompted
for each area to be deleted.
"""

if not smsname:
# Spew out the usage and quit when no SMS name
# is provided.
print run.__doc__
return spss_sys_util.SUCCESS

smsparts = string.split(smsname, ':')
if (len(smsparts) == 1):
smsname = smsparts[0]
smsvers = 1
else:
smsname = smsparts[0]
smsvers = int(smsparts[1])
sms = sms_util.sms(sms_name=smsname,sms_version=smsvers,ccl_version=smsvers)
tree = spss_sys_util.resolver('SMS_TREE_DIR')
args = map(string.lower, list(args))

# Prompt for what to delete if no qualifiers were passed in.
if not args:
yn = yn_query("Do you want to delete the SMS (y|n)? ")
if yn == 'y':
args.append("-sms")
yn = yn_query("Should %s output be cleaned up (y|n)? " % tree)
if yn == 'y':
args.append("-tree")
yn = yn_query("Should the SRT and checklist output be cleaned up (y|n)? ")
if yn == 'y':
args.append("-srt")
yn = yn_query("Should the C&C list %s be deleted (y|n)? " % sms.get_name())
if yn == 'y':
args.append("-ccl")

print "\n\nsms_cleanup will attempt the following functions:\n"
if "-sms" in args or "-all" in args:
print " smsg -delete\n"
if "-tree" in args or "-all" in args:
print " %s area cleanup\n" % tree
if "-srt" in args or "-all" in args:
print " SRT and checklist cleanup\n"
if "-ccl" in args or "-all" in args:
print " cclist -delete\n"

print "\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!! WARNING WARNING WARNING !!!!!!!!!!!!!!!!!!!!!!!!!!!"
print "WARNING: THIS ROUTINE WILL DELETE SMS AND CCL FILES FOR SMS %s" % sms.get_name()
yn = yn_query("Are you SURE you want to continue (y|n)? ")
if yn != 'y':
print "No cleanup done."
return spss_sys_util.SUCCESS


print "\nBeginning cleanup processing for SMS %s..." % sms.get_name()

if "-sms" in args or "-all" in args:
print "DELETING SMS %s" % sms.get_name()
try:
sms.delete_spss_sms()
except:
print "...no SMS deleted\n"

if "-tree" in args or "-all" in args:
print "Cleaning up the TREE area for sms %s" % sms.get_name()
try:
sms.delete_tree()
except:
print "...no TREE area deleted\n"

if "-srt" in args or "-all" in args:
print "Cleaning up the SRT area for sms %s" % sms.get_name()
try:
sms.delete_srt()
except:
print "...no SRT products deleted\n"
print "Cleaning up the SMS checklist area for sms %s" % sms.get_name()
try:
sms.delete_sms_checklist()
except:
print "...no SMS checklist products deleted\n"

if "-ccl" in args or "-all" in args:
print "Deleting the C&C list for calendar %s:%i" % (sms.get_name(), sms.version)
try:
sms.delete()
except:
print "...no CCL deleted\n"
print "Cleaning up the calendar checklist area for calendar %s:%i" % (
sms.get_name(), sms.version)
try:
sms.delete_cal_checklist()
except:
print "...no CAL checklist products deleted\n"

return spss_sys_util.SUCCESS


def yn_query(text):
user_response = ''
while not user_response:
user_response = raw_input(text)
return string.lower(user_response)[0]