(LOGO.JPG) Python for OpenVMS

This example reverses the entries (not the lines) of file OPERATOR.LOG. It is dependent on the output format and may not work on any version of OpenVMS. You need to make a copy of SYS$MANAGER:OPERATOR.LOG or open a new one before, because the default file locking of the C RTL in incompatible with the active log.


#$% OPC_REVERSE.PY
# -----

# reverse entries in OPERATOR.LOG
# 03-DEC-1999 Uwe Zessin

op_file    = open ("OPERATOR.LOG", "r")
empty_list = []
op_entries = empty_list[:]       # list of LOG entries

while 1:                         # find first entry
  op_line = op_file.readline()
  if ((op_line == "") or                     \
      (op_line[0:18] == "%%%%%%%%%%%  OPCOM")):
    break

if (op_line == ""):
  print "input file empty or does not contain valid entries"
  import sys
  sys.exit()

while 1:                         # go over entire file
  op_entry = empty_list[:]       # lines of a LOG entry
  op_entry.append (op_line)
  while 1:                       # loop over single entry
    op_line = op_file.readline()
    if ((op_line == "") or                     \
        (op_line[0:18] == "%%%%%%%%%%%  OPCOM")):
      break
    op_entry.append (op_line)
  # new entry or EOF
  op_entries.append (op_entry)   # add single entry to list
  if (op_line == ""):
    break                        # EOF

op_file.close()                  # close input file

# write out entries in reverse order
rev_file = open ("OP_REVERSE.LOG", "w")

# the list of entries (op_entries) is not reversed in-memory
# she is just written out in reverse order
while (1):
  if (op_entries == []):
    break                        # list is empty, done
  op_entry = op_entries[-1]      # last log entry
  for op_line in op_entry:
    rev_file.write (op_line)     # write lines of entry
  del (op_entries[-1])           # delete last entry

rev_file.close()                 # close output file

# -----
#%$


Example run:

$ python OPC_REVERSE.PY

%%%%%%%%%%%  OPCOM   3-DEC-1999 08:13:24.20  %%%%%%%%%%%
Logfile time stamp
%%%%%%%%%%%  OPCOM   3-DEC-1999 07:13:24.15  %%%%%%%%%%%
Logfile time stamp

%%%%%%%%%%%  OPCOM   3-DEC-1999 06:13:24.11  %%%%%%%%%%%
Logfile time stamp

[...]

%%%%%%%%%%%  OPCOM   6-JUL-1999 11:06:41.46  %%%%%%%%%%%
Message from user SYSTEM on NODE
%SECSRV-I-PROXYSTARTINGUP, proxy processing now starting up

%%%%%%%%%%%  OPCOM   6-JUL-1999 11:06:37.34  %%%%%%%%%%%
Operator status for operator NODE::SYS$SYSROOT:[SYSMGR]OPERATOR.LOG;90
CENTRAL, PRINTER, TAPES, DISKS, DEVICES, CARDS, NETWORK, CLUSTER,
SECURITY, LICENSE, OPER1, OPER2, OPER3, OPER4, OPER5, OPER6, OPER7,
OPER8, OPER9, OPER10, OPER11, OPER12

%%%%%%%%%%%  OPCOM   6-JUL-1999 11:06:37.29  %%%%%%%%%%%
Logfile has been initialized by operator _NODE$OPA0:
Logfile is NODE::SYS$SYSROOT:[SYSMGR]OPERATOR.LOG;90

$
----

Yes, the system has almost 150 days of uptime.


(go to: table of contents, index)

20-FEB-2000 ZE.