Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.stsci.edu/spst/UnixTransition/doc/make_primary_apar_com.py
Дата изменения: Fri Feb 28 14:46:10 2014
Дата индексирования: Sat Mar 1 22:31:08 2014
Кодировка:
#
# MODULE make_primary_apar_com
#
#******************************************************************
"""

**PURPOSE** --
This tool reads the standard {weekid}_add_apar_sus.com file
ignores the lines for those apar proposals in the BACKUP apar run
and writes output to primary_{weekid}_add_apar_sus.com

**DEVELOPER** --
Alan Patterson

**MODIFICATION HISTORY** --
Initial implementation 02/18/99
Brought to coding standards 04/24/00
Mods to refer static-info file 08/29/00
Include primary apar proposal in static-info file 11/15/00
Change enviroment varialbe poms_static_info_backup_dir to
POMS_STATIC_INFO_BACKUP_DIR per Tony Roman's request. DRC
8/27/02

**USAGE** --
do make_primary_apar_com [file]
o file contains the list of all calendar -add commands for the
attached parallels. By convention the name is
yyddd_add_apar_sus.com and it is produced by 'do attach'

"""
#******************************************************************
import sys,string,time_util,spss_sys_util

def run(infile=None):
"""

Usage:
do make_primary_apar_com file

where file is the name of a file containing the calendar -add
commands for the attached parallels. By convention its name
is _add_apar_sus.com
"""

if infile is None:
print run.__doc__
sys.exit(spss_sys_util.SUCCESS)

# Attempt to open file
f = open(infile,'r')

# Define static-info file
if spss_sys_util.on_vms():
staticfile = spss_sys_util.resolver('OPERATIONAL1', \
'poms/2/static-info.lisp')
else:
staticfile = spss_sys_util.resolver('POMS_STATIC_INFO_BACKUP_DIR', \
'static-info.lisp')

# Attempt to open static info file
# Unix staticfile = '/data/operational1/poms/2/static-info.lisp'
# VMS staticfile = 'operational1:[poms.2]static-info.lisp'

fs = open(staticfile,'r')

lines = fs.readlines()
fs.close()
s = ""

# get programs from the static info file; save in space separated string
for line in lines:
n1 = string.find(line,":proposal-id")
if n1 != -1:
n2 = string.find(line,":priority")
s = s + line[n1+12:n2] + " "
n1 = string.find(line,"'(")
if n1 != -1:
n2 = string.find(line,")")
s = s + line[n1+2:n2] + " "
# ensure each prop has 5 characters; i.e. leading '0' if necessary
proplist = string.split(s)
for i in range(len(proplist)):
z = "00"+proplist[i]
proplist[i] = z[len(z)-5:]
s = string.join(proplist," ")

# define output file
outfile = 'primary_' + infile
f2 = open(outfile,'w')

# Read each line of input and check for the existence of the backup
# programs in the list. The field after the field that contains 'ctyp'
# is expected to be the attached parallel visit id. Write the full line
# to the output only if none of the backup programs appear.

line = f.readline()
while line:
fields = string.split(line)
for i in range(len(fields)):
if string.find(fields[i],"ctyp") != -1:
prop = fields[i+1][0:5]
if string.find(s,prop) == -1:
f2.write(line)
line = f.readline()
f.close()
f2.close()
print 'Output written to ',outfile

# to run on commandline
if __name__ == '__main__':
input1 = None
if len(sys.argv) > 1:
input1 = sys.argv[1]
run(input1)