forked from jasonwjones/essbasepy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEssbase.py
638 lines (558 loc) · 23.2 KB
/
Essbase.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
from ctypes import *
from ctypes.util import find_library
import time
import sys
import platform
BIT64 = platform.architecture()[0] == '64bit'
# Essbase constants
ESS_BYTES_PER_CHARACTER = 4
ESS_BYTES_FOR_TRAILING_NULL = 5
ESS_TRUE = 1
# Change this to to True for Unicode enablement
ESS_UTF = False
#MaxL constants
MAXL_OPMODE_DEFAULT = 0
MAXL_OPMODE_UTF = 2
MAXL_MSGTEXT_LEN_NATIVE = 256
MAXL_MSGTEXT_LEN = ((MAXL_MSGTEXT_LEN_NATIVE * ESS_BYTES_PER_CHARACTER) + ESS_BYTES_FOR_TRAILING_NULL)
MAXL_COLUMN_NAME_LEN_NATIVE = 64
MAXL_COLUMN_NAME_LEN = ((MAXL_COLUMN_NAME_LEN_NATIVE * ESS_BYTES_PER_CHARACTER) + ESS_BYTES_FOR_TRAILING_NULL)
MAXL_MSGNO_COL_PREP_NUM = 1241045
MAXL_MDXCELLSTRSZ = 1024
# Return codes as defined in maxldefs.h
MAXL_MSGLVL_SUCCESS = 0
MAXL_MSGLVL_WARNING = 1
MAXL_MSGLVL_ERROR = 2
MAXL_MSGLVL_SESSION = 5
MAXL_MSGLVL_FATAL = 6
MAXL_MSGLVL_END_OF_DATA = 108
# MaxL's internal data types (maxldefs.h)
MAXL_DTINT_BOOL = 1
MAXL_DTINT_NUMBER = 2
MAXL_DTINT_CHAR = 3
MAXL_DTINT_DOUBLE = 4
MAXL_DTINT_ULONG64 = 5 # added for 11.1.2.2+
# External data types supported by MaxL (maxldefs.h)
MAXL_DTEXT_UCHAR = 2
MAXL_DTEXT_DOUBLE = 10
MAXL_DTEXT_STRING = 11
MAXL_DTEXT_ULONG64 = 12 # added for 11.1.2.2+
# MDX column types supported by MaxL (maxldefs.h)
MAXL_MDXINTTYPE = 0
MAXL_MDXLONGTYPE = 1
MAXL_MDXULONGTYPE = 2
MAXL_MDXSHORTTYPE = 3
MAXL_MDXUSHORTTYPE = 4
MAXL_MDXFLOATTYPE = 5
MAXL_MDXSTRTYPE = 6
MAXL_MDXMEMTYPE = 7
MAXL_MDXDATASTRTYPE = 8
#Other constants
MAX_REC = 1 # we are going to retrieve one record at a time
MAX_COL = 1024 # maximum column size
ESS_PVOID_T = c_void_p
ESS_PPVOID_T = POINTER(ESS_PVOID_T)
class maxl_instinit_t(Structure):
_fields_ = [('MsgText', (c_char * MAXL_MSGTEXT_LEN)),
('MsgTextFill', (c_char * 3)),
('bUTFInput', c_ubyte),
('bTempFillerArray', (c_ubyte * 7)),
('CtxListLen', c_ushort)]
if BIT64:
class maxl_ssninit_t(Structure):
_fields_ = [('MsgText', (c_char * MAXL_MSGTEXT_LEN)),
('MsgTextFill', (c_char * 3)),
('MsgLevel', c_ulong),
('ulTempFiller1', c_ulong),
('MsgNumber', c_long),
('ulTempFiller2', c_ulong),
('ExecElapsedTime', c_ulong),
('ulTempFiller3', c_ulong),
('ExecArity', c_ulong),
('ulTempFiller4', c_ulong),
('RowCount', c_ulong),
('ulTempFiller5', c_ulong),
('Card', c_ulong),
('ulTempFiller6', c_ulong),
('bMdxQuery', c_ulong),
('ulTempFiller7', c_ulong),
('pNewPassword', c_char_p),
('pReserved1', c_void_p),
('pReserved2', c_void_p),
('pReserved3', c_void_p),
('pReserved4', c_void_p),
('ExecVerb', c_ulong),
('ulTempFiller8', c_ulong)]
else:
class maxl_ssninit_t(Structure):
_fields_ = [('MsgText', (c_char * MAXL_MSGTEXT_LEN)),
('MsgTextFill', (c_char * 3)),
('MsgLevel', c_ulong),
('MsgNumber', c_long),
('ExecElapsedTime', c_ulong),
('ExecArity', c_ulong),
('RowCount', c_ulong),
('Card', c_ulong),
('bMdxQuery', c_ulong),
('pNewPassword', c_char_p),
('pReserved1', c_void_p),
('pReserved2', c_void_p),
('pReserved3', c_void_p),
('pReserved4', c_void_p),
('ExecVerb', c_ulong)]
if BIT64:
class maxl_column_descr_t(Structure):
_fields_ = [('Name', (c_char * MAXL_COLUMN_NAME_LEN)),
('NameFill', (c_char * 3)),
('IntTyp', c_ulong),
('ulTempFiller1', c_ulong),
('IntLen', c_long),
('ulTempFiller2', c_ulong),
('IntRealLen', c_ulong),
('ulTempFiller3', c_ulong)]
else:
class maxl_column_descr_t(Structure):
_fields_ = [('Name', (c_char * MAXL_COLUMN_NAME_LEN)),
('NameFill', (c_char * 3)),
('IntTyp', c_ulong),
('IntLen', c_long),
('IntRealLen', c_ulong)]
MAXL_MDXCOLUMNTYPE_T = c_ulong
class maxl_mdxoutputheader_t(Structure):
_fields_ = [('Type', MAXL_MDXCOLUMNTYPE_T),
('sName', (c_char * MAXL_MDXCELLSTRSZ))]
__maxldll = find_library('essmaxlu')
maxl = cdll.LoadLibrary(__maxldll)
class Essbase:
isInitialized = False
def __init__(self):
self.user = None
self.sid = None
self.ssnInit = None
self.numRows = None
self.numFlds = None
self.sts = None
self.bMdxQuery = None
if not Essbase.isInitialized:
print ("Initializing!")
# Initialize MaxL API
inst = maxl_instinit_t()
# memset(InstInit, 0, sizeof(MAXL_INSTINIT_T))
#pinst = (c_char * sizeof(inst)).from_address(addressof(inst))
#pinst.value = b'\0' * sizeof(inst)
if ESS_UTF:
inst.bUTFInput = ESS_TRUE
sts = maxl.MaxLInit(byref(inst))
print ("STS:")
print (sts)
print (dir(inst))
print ("Inst")
Essbase.isInitialized = (sts == MAXL_MSGLVL_SUCCESS)
print ("Essbase initialized: %s" % Essbase.isInitialized)
def __del__(self):
if Essbase.isInitialized:
# Terminate MaxL API
sts = maxl.MaxLTerm()
Essbase.isInitialized = False
#---------------------------- connect -----------------------------------#
#
# Creates new Essbase Session.
#
# Arguments:
# User name. Required. Character string containing valid Essbase
# user name in whose security domain the new
# session is to be established.
# Password. Required. Password for the user.
# Host name. Optional. The computer name hosting the Essbase instance
# of interest.
#
def connect(self, user, password, host='localhost'):
sid = c_ushort(0)
ssnInit = maxl_ssninit_t()
sts = maxl.MaxLSessionCreate(c_char_p(host), c_char_p(user), c_char_p(password), byref(ssnInit), byref(sid))
self.user = user
self.sid = sid
self.ssnInit = ssnInit
self.numFlds = 0
self.sts = sts
self.bMdxQuery = 0
#-------------------------------- do ------------------------------------#
#
# Performs a MaxL statement.
#
# Arguments:
# Statement. Required. A string containing a MaxL statement to be
# passed to the server.
#
# Returns (and sets Essbase{STATUS} to):
#
# $MAXL_STATUS {NOERR} if execution was successful. There are likely
# to be informational and feedback massages on the message stack,
# which may be obtained with the pop_msg() method below.
#
# $MAXL_STATUS {ERROR} if there was a user error. The numbers of
# the encountered errors, their levels and texts may be obtained
# with the pop_msg method below. Note, that there's likely to
# be informational messages on the message stack even in if
# execution was successful. These also may be obtained via the
# pop_msg call below.
#
def do(self, statement):
sid, ssnInit = self.sid, self.ssnInit
if not (sid and ssnInit):
return MAXL_MSGLVL_SESSION
# execute the statement command
if ESS_UTF:
sts = maxl.MaxLExec(sid, c_char_p(statement), c_ulong(MAXL_OPMODE_UTF))
else:
sts = maxl.MaxLExec(sid, c_char_p(statement), c_ulong(MAXL_OPMODE_DEFAULT))
self.sts = sts
self.bMdxQuery = self.is_mdx()
if self.bMdxQuery:
numFlds = c_long(0)
numRows = c_long(0)
sts = maxl.MaxlMDXOutputSize(sid, byref(numFlds), byref(numRows))
self.sts = sts
if sts > MAXL_MSGLVL_ERROR:
self.numFlds = None
self.numRows = None
else:
self.numFlds = int(numFlds.value)
self.numRows = int(numRows.value)
else:
if sts > MAXL_MSGLVL_ERROR:
self.numFlds = None
else:
self.numFlds = self.ssnInit.ExecArity
return sts
#---------------------------- pop_msg -----------------------------------#
#
# Pops next Essbase or MaxL status message from MaxL message stack.
#
# Each invocation of the "do" method above results in a stack of status
# messages. This stack is unwound by repeatedly calling this function
# until it returns nothing. It's okay for a program to ignore the
# message stack, or only unwind it partially. The next call to "do" will
# clear left-over messages.
#
# There is likely to be a number of messages on the stack even after a
# successful execution. In most cases, a program will only need
# to know if the execution of the last "do" was successful, which is
# indicated by the return value from "do".
#
# When the message stack is empty the return list elements are undefined
# and Essbase{STATUS} is set to $MAXL_STATUS{END_OF_DATA}.
#
# Arguments: None
#
# Returns: List of form:
# (<message_number>, <message_level>, <message_text>)
#
def pop_msg(self):
sid, ssnInit, sts = self.sid, self.ssnInit, self.sts
if not (sid and ssnInit):
return None, None, None
msgno = msglevel = arity = 0
oldSts = self.sts
done = False
getAnotherMessage = True
while getAnotherMessage:
msgstr = ''
if oldSts <= MAXL_MSGLVL_ERROR:
msgno, msglevel, msgstr, arity = self.ssnInit.MsgNumber, self.ssnInit.MsgLevel, self.ssnInit.MsgText, self.ssnInit.ExecArity
if not (not arity and msgno == MAXL_MSGNO_COL_PREP_NUM):
getAnotherMessage = False
else:
getAnotherMessage = True
elif oldSts == MAXL_MSGLVL_END_OF_DATA:
done = True
getAnotherMessage = False
if not done:
sts = maxl.MaxLMessageFetch(sid)
if getAnotherMessage:
msgno = msglevel = arity = 0
oldSts = sts
self.sts = sts
if sts > MAXL_MSGLVL_ERROR and sts != MAXL_MSGLVL_END_OF_DATA:
msgno, msglevel, msgstr = None, None, None
return msgno, msglevel, msgstr
#------------------------- fetch_desc ------------------------------#
#
# Returns reference to list of column names in the output table
# and a reference to the list of column types in the output table.
#
def fetch_desc(self):
col_names = []
col_types = []
sid, numFlds, numRows, bMdxQuery = self.sid, self.numFlds, self.numRows, self.bMdxQuery
if not sid:
return MAXL_MSGLVL_SESSION
if not numFlds:
return tuple(col_names), tuple(col_types)
if bMdxQuery:
pHeader_t = POINTER(maxl_mdxoutputheader_t)
pHeader = pHeader_t()
sts = maxl.MaxlMDXOutputDescribe(sid, byref(pHeader))
if sts < MAXL_MSGLVL_ERROR:
for index in range(numFlds):
col_names.append(pHeader[index].sName)
col_types.append(pHeader[index].Type)
else:
col_array = maxl_column_descr_t * numFlds
cols = col_array()
sts = maxl.MaxLOutputDescribe(sid, c_ulong(1), c_ulong(numFlds), byref(cols))
if sts < MAXL_MSGLVL_ERROR:
for index in range(numFlds):
col_names.append(cols[index].Name)
col_types.append(cols[index].IntTyp)
return tuple(col_names), tuple(col_types)
#------------------------- fetch_row ------------------------------#
#
# Returns a reference to a row of query results in output table as a
# list and a reference to the data types of the query result values
# as a list.
# Essbase->{STATUS} is set to either $MAXL_STATUS{NOERR}, on
# success, or $MAXL_STATUS{END_OF_DATA}, if there were no rows to
# fetch, or $MAXL_STATUS{ERROR} if a user error has occured.
#
# A row of record is defined as
# { val[0], val[1], ... , val[NUM_OF_FIELDS-1] } }
# Row numbers are counted cardinally from 0:
#
def fetch_row(self):
row = []
sid, ssnInit, numFlds, bMdxQuery = self.sid, self.ssnInit, self.numFlds, self.bMdxQuery
if not (sid and ssnInit):
return MAXL_MSGLVL_SESSION
if not numFlds:
return row
if bMdxQuery:
sts, row = self._MaxlMDXOutputNextRecord(sid, numFlds)
else:
sts, row = self._MaxlOutputNextRecord(sid, ssnInit, numFlds)
if sts == MAXL_MSGLVL_END_OF_DATA:
sts = MAXL_MSGLVL_SUCCESS
self.sts = sts
return row
#----------------------- _MaxlOutputNextRecord --------------------#
def _MaxlOutputNextRecord(self, sid, ssnInit, numFlds):
row = []
pDescr = maxl_column_descr_t()
descr_array = maxl_column_descr_t * numFlds
pOutputDescrs = descr_array()
col_t = c_char * (MAX_COL + 1)
class output_buffer(Union):
_fields_ = [('pdVal', c_double * MAX_REC),
('pbVal', c_ubyte * MAX_REC),
('pszVal', col_t * MAX_REC),
('puVal', c_ulonglong * MAX_REC)]
sts = maxl.MaxLOutputDescribe(sid, c_ulong(1), c_ulong(numFlds), byref(pOutputDescrs))
if sts < MAXL_MSGLVL_ERROR:
buffer_array = output_buffer * numFlds
pOutputArray = buffer_array()
# memset(pOutputArray, 0, sizeof(pOutputArray))
ppOutputArray = (c_char * sizeof(pOutputArray)).from_address(addressof(pOutputArray))
ppOutputArray.value = '\0' * sizeof(pOutputArray)
for index in range(numFlds):
pBuffer = pOutputArray[index]
pDescr = pOutputDescrs[index]
if pDescr.IntTyp in (MAXL_DTINT_DOUBLE, MAXL_DTINT_NUMBER):
pInBuff = pBuffer.pdVal
Type = MAXL_DTEXT_DOUBLE
Size = 0
elif pDescr.IntTyp == MAXL_DTINT_BOOL:
pInBuff = pBuffer.pbVal
Type = MAXL_DTEXT_UCHAR
Size = 0
elif pDescr.IntTyp == MAXL_DTINT_CHAR:
pInBuff = pBuffer.pszVal
Type = MAXL_DTEXT_STRING
Size = MAX_COL+1
elif pDescr.IntTyp == MAXL_DTINT_ULONG64:
pInBuff = pBuffer.puVal
Type = MAXL_DTEXT_ULONG64
Size = 0
sts = maxl.MaxLColumnDefine(sid, c_ulong(index + 1), pInBuff, c_ushort(Size), c_ulong(Type), c_ushort(MAX_REC), None, None)
if sts >= MAXL_MSGLVL_ERROR:
pOutputDescrs = pOutputArray = None
return sts, None
sts = maxl.MaxLOutputFetch(sid, c_ulong(MAXL_OPMODE_DEFAULT))
if sts == MAXL_MSGLVL_ERROR or sts == MAXL_MSGLVL_END_OF_DATA:
return sts, None
elif sts > MAXL_MSGLVL_ERROR:
pOutputDescrs = pOutputArray = None
return sts, None
for index in range(numFlds):
pDescr = pOutputDescrs[index]
pBuffer = pOutputArray[index]
if pDescr.IntTyp in (MAXL_DTINT_DOUBLE, MAXL_DTINT_NUMBER):
row.append(pBuffer.pdVal[0])
elif pDescr.IntTyp == MAXL_DTINT_BOOL:
row.append(pBuffer.pbVal[0])
elif pDescr.IntTyp == MAXL_DTINT_CHAR:
row.append(pBuffer.pszVal[0].value)
elif pDescr.IntTyp == MAXL_DTINT_ULONG64:
row.append(pBuffer.puVal[0])
pOutputDescrs = None
pOutputArray = None
return sts, row
#-------------------- _MaxlMDXOutputNextRecord --------------------#
#
# Description
# Returns pOutput->ulCurRow'th row of output data.
#
# Parameters
# SessionId- in - MaxL Session id.
# ppRecord - out - Pointer to the buffer which receives the record
# values.
#
# Returns
# MAXL_NOERR, MAXL_END_OF_DATA, MAXL_ERROR.
def _MaxlMDXOutputNextRecord(self, sid, numFlds):
row = []
pHeader_t = POINTER(maxl_mdxoutputheader_t)
pHeader = pHeader_t()
#ESS_PPVOID_T ppRecord;
#ppRecord = malloc(sizeof(ESS_PVOID_T) * ulNumCols)
ppRecordAry = ESS_PVOID_T * numFlds
ppRecord = ppRecordAry()
sts = maxl.MaxlMDXOutputNextRecord(sid, ppRecord)
if sts == MAXL_MSGLVL_SUCCESS:
sts = maxl.MaxlMDXOutputDescribe(sid, byref(pHeader))
if sts == MAXL_MSGLVL_SUCCESS:
for index in range(numFlds):
fldType = pHeader[index].Type
if fldType in (MAXL_MDXINTTYPE, MAXL_MDXLONGTYPE):
row.append(cast(ppRecord[index], POINTER(c_long))[0])
elif fldType == MAXL_MDXULONGTYPE:
row.append(cast(ppRecord[index], POINTER(c_ulong))[0])
elif fldType == MAXL_MDXSHORTTYPE:
row.append(cast(ppRecord[index], POINTER(c_short))[0])
elif fldType == MAXL_MDXUSHORTTYPE:
row.append(cast(ppRecord[index], POINTER(c_ushort))[0])
elif fldType in (MAXL_MDXFLOATTYPE, MAXL_MDXMEMTYPE):
row.append(cast(ppRecord[index], POINTER(c_double))[0])
elif fldType in (MAXL_MDXDATASTRTYPE, MAXL_MDXSTRTYPE):
row.append(cast(ppRecord[index], POINTER(c_char_p))[0])
else:
row.append("")
return sts, row
#----------------------------- is_mdx -------------------------------#
#
# This function can be called after a call to do() in case different
# output processing is desired for mdx query output than from
# MaxL command output
#
def is_mdx(self):
sid, ssnInit, sts = self.sid, self.ssnInit, self.sts
if not (sid and ssnInit):
return None
return ssnInit.bMdxQuery
#----------------------------- disconnect -------------------------------#
#
# Terminates a MaxL session and the associated Essbase session.
#
def disconnect(self):
sid = self.sid
if not sid:
return MAXL_MSGLVL_SESSION
sts = maxl.MaxLSessionDestroy(sid)
if sts < MAXL_MSGLVL_ERROR:
self.user = None
self.sid = None
self.ssnInit = None
self.numFlds = None
self.sts = None
return sts
# -------------------------------- rows ----------------------------------#
#
# Generator that loops through output returned by Essbase
#
def rows(self, value=None):
if not self.numFlds:
raise StopIteration
else:
try:
row = self.fetch_row()
while row:
value = (yield row)
row = self.fetch_row()
except GeneratorExit:
raise
except Exception as e:
value = e
# --------------------------------- tdf ---------------------------------#
#
# Returns a result set in the form of a tab-delimited file.
#
def tdf(self):
# setup the header
name, dt = self.fetch_desc()
tbl = "\t".join(name) + "\n"
line = ['-' * len(column) for column in name]
tbl = tbl + "\t".join(line) + "\n"
# now populate the tab-delimited file with data
for row in self.rows():
record = []
idx = 0
for column in row:
if dt[idx] == MAXL_DTINT_BOOL:
if column == 0:
record.append('FALSE')
else:
record.append('TRUE')
else:
record.append(str(column))
idx += 1
tbl = tbl + "\t".join(record) + "\n"
tbl = tbl + "\n"
return tbl
# -------------------------------- msgs ----------------------------------#
#
# Returns a message list that resulted from executing a MaxL statement.
#
def msgs(self, output=sys.stdout):
msgno, level, msg = self.pop_msg()
while msgno:
# Decode message level
if level == MAXL_MSGLVL_SUCCESS:
msglvl = "OK/INFO"
elif level == MAXL_MSGLVL_WARNING:
msglvl = "WARNING"
elif level == MAXL_MSGLVL_ERROR:
msglvl = "ERROR"
elif level == MAXL_MSGLVL_FATAL:
msglvl = "FATAL"
else:
msglvl = str(level)
print >> output, "%8s - %7d - %s." % (msglvl, msgno, msg)
msgno, level, msg = self.pop_msg()
print >> output,''
# ------------------------------- execute -------------------------------#
#
# Execute a MaxL statement and print resulting output.
#
def execute(self, stmt, output=sys.stdout, timefmt=None):
# format MaxL statement for output
stmt = stmt.replace("\t", "")
out = stmt.split("\n")
for i in range(1, len(out)):
out[i] = "%4d> %s" % (i, out[i])
if timefmt:
timestamp = time.strftime(timefmt)
else:
timestamp = time.asctime()
print >> output, timestamp
print >> output, "MAXL> %s;\n" % "\n".join(out)
# execute MaxL statement
sts = self.do(stmt)
# exit if the execution failed
if sts:
# dump status messages
self.msgs(output)
print >> output, "Execution of [%s] failed with status %d" % (stmt, sts)
elif self.numFlds:
print >> output, self.tdf()
# dump status messages
self.msgs(output)
return sts