essbasepy
essbasepy copied to clipboard
Output errors and warning to stderr
Hi there, I amended execute and msgs functions to output errors and warnings to stderr pipe. It's easier to isolate exceptions when running a script that generates a lot of output.
msgno, level, msg = self.pop_msg()
stderr = False
while msgno:
# Decode message level
if level == MAXL_MSGLVL_SUCCESS:
msglvl = "OK/INFO"
elif level == MAXL_MSGLVL_WARNING:
msglvl = "WARNING"
stderr = True
elif level == MAXL_MSGLVL_ERROR:
msglvl = "ERROR"
stderr = True
elif level == MAXL_MSGLVL_FATAL:
msglvl = "FATAL"
stderr = True
else:
msglvl = str(level)
if stderr:
print ("%8s - %7d - %s." % (msglvl, msgno, msg.decode()), file=sys.stderr)
else:
print ("%8s - %7d - %s." % (msglvl, msgno, msg.decode()))
msgno, level, msg = self.pop_msg()
print ('')
"""------------------------------- 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 (timestamp)
print ("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 ("Execution of [%s] failed with status %d" % (stmt, sts), file=sys.stderr)
elif self.numFlds:
print (self.tdf())
# dump status messages
self.msgs(output)
return sts
Thanks,
Regis
Hi Regis, thanks for this. Did you want to issue a pull request that I can merge in? If not I can try and do it myself, although not sure exactly when I'll be able to get around to it. Thanks – Jason
Hi Jason,
Yes, I wanted to issue a pull request but I can’t.
Thanks
<-- Regis Cabaret
On August 17, 2016 at 21:58:50, Jason Jones ([email protected]) wrote:
Hi Regis, thanks for this. Did you want to issue a pull request that I can merge in? If not I can try and do it myself, although not sure exactly when I'll be able to get around to it. Thanks – Jason
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jasonwjones/essbasepy/issues/5#issuecomment-240419485, or mute the thread https://github.com/notifications/unsubscribe-auth/ADP5ue-CO6YYxdrzishUeL55iCCzePfXks5qgxOYgaJpZM4JmImN .