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

Поисковые слова: arp 220
#
#MODULE send_pnm.py
#
#***********************************************************************
"""

**PURPOSE** --
Send a pre-existing PNM to CCS strings or to an Internet or IP address.

**DEVELOPER** --
Don Chance

**MODIFICATION HISTORY** --

o initial implementation DC 11/22/04
o modified to allow SFTP connections. drc 9/28/11
o default to SFTP. drc 11/30/11
"""
#***********************************************************************
import spst_getopt
import spss_sys_util
import string
import transfer_util

__version__ = "11/30/11"

def run(*args):
"""Send a pre-existing PNM to CCS strings or to an Internet or IP address.

Usage:
do send_pnm [, ,...]
[-ccs_strings= ]
[-internet_address= [-ftp]
[-sftp]

is the path to a PNM file.

"""
#default input values
ccs_string_list = []
internet_address = ''

if not args:
print run.__doc__
return spss_sys_util.SUCCESS

#get input options.
allowed_options = ['ccs_strings=', 'internet_address=', 'ftp', 'sftp']
try:
options, parms = spst_getopt.spst_getopt(args, allowed_options)
except Exception,e:
e = '%s\n%s' %(e,run.__doc__)
raise IOError(e)

if '-ftp' in options.keys() and '-sftp' in options.keys():
raise ValueError('options -ftp and -sftp are mutually exclusive')

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

if '-ccs_strings' in options.keys():
ccs_string_list = string.split(
string.upper(options['-ccs_strings']),',')
if ccs_string_list == ['']:
ccs_string_list = []

for ccs_string in ccs_string_list:
user = spss_sys_util.get_environ_variable(
'SPST_CCS%s_FTP_USER' %ccs_string)[0]
node = spss_sys_util.get_environ_variable(
'SPST_CCS%s_FTP_NODE' %ccs_string)[0]
sftp = True
if '-ftp' in options.keys():
sftp = False
ftp(user, node, parms, sftp)

if internet_address:
user = 'sccspns'
sftp = True
if '-ftp' in options.keys():
user = 'ccspns'
sftp = False
ftp(user, internet_address, parms, sftp)

return spss_sys_util.SUCCESS


def ftp(user, node, files, sftp):
userfile = spss_sys_util.resolver('PE_DAT', '%s.dat'
% user)
usertemp = string.strip(open(userfile, 'r').readline())
ftp_dest_dir = spss_sys_util.get_environ_variable('SPST_CCS_FTP_DIR')[0]
if sftp:
ftp = transfer_util.secure_spstftp(node, user, usertemp)
else:
ftp = transfer_util.spstftp(node, user, usertemp)
ftp.cwd(ftp_dest_dir)
for ccs_file_path in files:
ccs_dest_name = string.upper(spss_sys_util.basename(ccs_file_path))
print '\nFTPing %s to %s\n' %(ccs_file_path, node)
ftp.put(ccs_file_path, ccs_dest_name)
ftp.quit()
print 'FTP %s to %s complete\n' %(ccs_file_path, node)