Skip to content

Commit

Permalink
Loglines (#605)
Browse files Browse the repository at this point in the history
* HTTP loglines

* add IOM am for loglines

* add IOM am for loglines

* add IOM am for loglines
  • Loading branch information
tomweber-sas authored Jun 14, 2024
1 parent 8b48627 commit 17c4179
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 24 deletions.
Binary file modified saspy/java/pyiom/saspy2j.class
Binary file not shown.
59 changes: 54 additions & 5 deletions saspy/java/pyiom/saspy2j.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
import com.sas.iom.SASIOMDefs.*;
import com.sas.iom.orb.SASURI;

import com.sas.iom.SAS.ILanguageServicePackage.CarriageControlSeqHolder;
import com.sas.iom.SAS.ILanguageServicePackage.LineTypeSeqHolder;


import com.sas.services.connection.BridgeServer;
import com.sas.services.connection.ConnectionFactoryConfiguration;
import com.sas.services.connection.ConnectionFactoryException;
Expand Down Expand Up @@ -105,7 +109,9 @@ public saspy2j() {}
static String[] iomhosts;
static int lrecl = 32767;
static int logsz = 32767;
static Thread t1;
static Thread t1;



public static void main(String[] args) throws
InterruptedException, IOException, ConnectionFactoryException, GenericError
Expand All @@ -123,6 +129,7 @@ public static void main(String[] args) throws

String addr = "";
String log = "";
String types= "";
String plog = "";
String lst = "";
String pgm = "";
Expand All @@ -132,13 +139,18 @@ public static void main(String[] args) throws
boolean zero = false;
boolean ods = false;
boolean undo = false;
boolean llines = false;

OctetSeqHolder odsdata = new OctetSeqHolder();
char[] in = new char[4097];
byte[] out = new byte[32768];

CarriageControlSeqHolder logCarriageControlHldr = new CarriageControlSeqHolder();
LineTypeSeqHolder logLineTypeHldr = new LineTypeSeqHolder();
StringSeqHolder logHldr = new StringSeqHolder();

Runnable cancel = new cancel(scan, lang);

for (int x = 0; x < nargs; x++)
{
if (args[x].equalsIgnoreCase("-host"))
Expand Down Expand Up @@ -233,7 +245,7 @@ else if (args[x].equalsIgnoreCase("-uri"))
t1 = new Thread(cancel);
t1.setName("cancel");
t1.start();

while (true)
{
try
Expand Down Expand Up @@ -482,6 +494,11 @@ else if (eol.contains("PRINTTO"))
undo = true;
pgm = pgm.substring(idx + 13 + 33);
}
else if (eol.contains("LOGLINES"))
{
llines = true;
pgm = pgm.substring(idx + 13 + 33);
}
else /* SUBMIT */
{
pgm = pgm.substring(0, idx);
Expand Down Expand Up @@ -626,6 +643,7 @@ else if (eol.contains("PRINTTO"))
}
}

types = "";
fndeol = false;
while (true)
{
Expand Down Expand Up @@ -685,8 +703,26 @@ else if (eol.contains("PRINTTO"))
{
try
{
log = lang.FlushLog(logsz);
slen = log.length();
if (! llines)
{
log = lang.FlushLog(logsz);
slen = log.length();
}
else
{
int x;
lang.FlushLogLines(Integer.MAX_VALUE,logCarriageControlHldr,logLineTypeHldr,logHldr);
log = "";
slen = logHldr.value.length;

for(x = 0; x < slen; x ++)
{
log += logHldr.value[x]+'\n';
types += logLineTypeHldr.value[x].value();
}
slen = log.length();
}

if (slen > 0)
{
errp.write(log);
Expand Down Expand Up @@ -727,6 +763,7 @@ else if (eol.contains("PRINTTO"))
}
catch (IOException e)
{
llines = false;
String msg = "We failed in reading the Log\n"+e.getMessage();
errp.write(msg);
errp.flush();
Expand All @@ -741,6 +778,7 @@ else if (eol.contains("PRINTTO"))
}
catch (org.omg.CORBA.DATA_CONVERSION e)
{
llines = false;
String msg = "We failed in reading the Log\n"+e.getMessage();
errp.write(msg);
errp.flush();
Expand All @@ -750,6 +788,17 @@ else if (eol.contains("PRINTTO"))
}
}
}

if (llines)
{
llines = false;
slen = types.length();
if (slen > 0)
{
errp.write("TomSaysTypes="+types+"\n"+eol.substring(1));
errp.flush();
}
}
}
catch (GenericError e)
{
Expand Down
Binary file modified saspy/java/saspyiom.jar
Binary file not shown.
44 changes: 31 additions & 13 deletions saspy/sasiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ def _startsas(self):

self.pid = self._session.get('id')

self._log = self._getlog()
self._log = self._getlog().replace(chr(12), chr(10))

# POST Job - Lets see if the server really came up, cuz you can't tell from what happend so far
conn = self.sascfg.HTTPConn; conn.connect()
Expand Down Expand Up @@ -903,9 +903,10 @@ def _refresh_token(self):
self.sascfg._refresh = js.get('refresh_token')
return

def _getlog(self, jobid=None):
def _getlog(self, jobid=None, loglines=False):
start = 0
logr = ''
logl = []

# GET Log
if jobid:
Expand Down Expand Up @@ -937,17 +938,24 @@ def _getlog(self, jobid=None):
break
start += lines

for line in log:
logr += line.get('line')+'\n'
logl += log

for line in logl:
logr += line.get('line')+'\n'

if jobid != None:
self._log += logr.replace(chr(12), chr(10))
logr = logr.replace(chr(12), chr(10))
self._log += logr

if logr.count('\nERROR:') > 0:
warnings.warn("Noticed 'ERROR:' in LOG, you ought to take a look and see if there was a problem")
self._sb.check_error_log = True

return logr
if not loglines:
del(logl)
return logr
else:
return (logr, logl)

def _getlst(self, jobid=None):
htm = ''
Expand Down Expand Up @@ -1034,7 +1042,7 @@ def _getlsttxt(self, jobid=None):
for line in lst:
lstr += line.get('line')+'\n'

return lstr
return lstr.replace(chr(12), chr(10))

def _asubmit(self, code, results="html"):
odsopen = json.dumps("ods listing close;ods "+self.sascfg.output+" (id=saspy_internal) options(bitmap_mode='inline') device=svg style="+self._sb.HTML_Style+"; ods graphics on / outputfmt=png;\n")
Expand Down Expand Up @@ -1109,6 +1117,7 @@ def submit(self, code: str, results: str ="html", prompt: dict = None, **kwargs)
prompt = prompt if prompt is not None else {}
printto = kwargs.pop('undo', False)
cancel = kwargs.pop('cancel', False)
lines = kwargs.pop('loglines', False)

odsopen = json.dumps("ods listing close;ods "+self.sascfg.output+" (id=saspy_internal) options(bitmap_mode='inline') device=svg style="+self._sb.HTML_Style+"; ods graphics on / outputfmt=png;\n")
odsclose = json.dumps("ods "+self.sascfg.output+" (id=saspy_internal) close;ods listing;\n")
Expand Down Expand Up @@ -1237,12 +1246,17 @@ def submit(self, code: str, results: str ="html", prompt: dict = None, **kwargs)
if excpcnt < 0:
raise

logd = self._getlog(jobid).replace(chr(12), chr(10))
logs = self._getlog(jobid, lines)

if not lines:
logd = logs
else:
logd, logl = logs

if ods:
lstd = self._getlst(jobid).replace(chr(12), chr(10))
lstd = self._getlst(jobid)
else:
lstd = self._getlsttxt(jobid).replace(chr(12), chr(10))
lstd = self._getlsttxt(jobid)

trip = lstd.rpartition("/*]]>*/")
if len(trip[1]) > 0 and len(trip[2]) < 200:
Expand All @@ -1263,6 +1277,10 @@ def submit(self, code: str, results: str ="html", prompt: dict = None, **kwargs)
resp = req.read()
conn.close()

if lines:
logd = list(logl)
del(logl)

return dict(LOG=logd, LST=lstd)

def saslog(self):
Expand Down Expand Up @@ -1696,7 +1714,7 @@ def dataframe2sasdata(self, df: '<Pandas Data Frame object>', table: str ='a',
code += "end;\n"
code += "datalines4;"
jobid = self._asubmit(code, "text")
self._log += self._getlog(jobid).replace(chr(12), chr(10))
self._log += self._getlog(jobid)

blksz = int(kwargs.get('blocksize', 1000000))
noencode = self._sb.sascei == 'utf-8' or encode_errors == 'ignore'
Expand Down Expand Up @@ -1751,7 +1769,7 @@ def dataframe2sasdata(self, df: '<Pandas Data Frame object>', table: str ='a',
code = code.encode(self.sascfg.encoding, errors='replace').decode(self.sascfg.encoding)

jobid = self._asubmit(code, "text")
self._log += self._getlog(jobid).replace(chr(12), chr(10))
self._log += self._getlog(jobid)
code = ""

if not noencode and len(code) > 0:
Expand All @@ -1769,7 +1787,7 @@ def dataframe2sasdata(self, df: '<Pandas Data Frame object>', table: str ='a',
code = code.encode(self.sascfg.encoding, errors='replace').decode(self.sascfg.encoding)

jobid = self._asubmit(code+";;;;\n;;;;", "text")
self._log += self._getlog(jobid).replace(chr(12), chr(10))
self._log += self._getlog(jobid)
ll = self.submit("quit;", 'text')
return None

Expand Down
49 changes: 43 additions & 6 deletions saspy/sasioiom.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,7 @@ def submit(self, code: str, results: str ="html", prompt: dict = None, **kwargs)
prompt = prompt if prompt is not None else {}
printto = kwargs.pop('undo', False)
cancel = kwargs.pop('cancel', False)
lines = kwargs.pop('loglines', False)

#odsopen = b"ods listing close;ods html5 (id=saspy_internal) file=STDOUT options(bitmap_mode='inline') device=svg; ods graphics on / outputfmt=png;\n"
odsopen = b"ods listing close;ods "+self.sascfg.output.encode()+ \
Expand Down Expand Up @@ -952,6 +953,8 @@ def submit(self, code: str, results: str ="html", prompt: dict = None, **kwargs)

if printto:
self.stdin[0].send(b'\ntom says EOL=PRINTTO \n')
if lines:
self.stdin[0].send(b'\ntom says EOL=LOGLINES \n')
self.stdin[0].send(pgm+b'tom says EOL='+logcodeo+b'\n')

while not done:
Expand Down Expand Up @@ -1053,27 +1056,46 @@ def submit(self, code: str, results: str ="html", prompt: dict = None, **kwargs)
except UnicodeDecodeError:
lstf = lstf.decode(errors='replace')

logf = logf.decode(errors='replace').replace(chr(12), chr(10))

trip = lstf.rpartition("/*]]>*/")
if len(trip[1]) > 0 and len(trip[2]) < 200:
lstf = ''

lstd = lstf.replace(chr(12), chr(10)).replace('<body class="c body">',
'<body class="l body">').replace("font-size: x-small;",
"font-size: normal;")
logf = logf.decode(errors='replace').replace(chr(12), chr(20))
self._log += logf
final = logf.partition(logcodei)
types = final[2].encode()
z = final[0].rpartition(chr(10))
prev = '%08d' % (self._log_cnt - 1)
zz = z[0].rpartition("\nE3969440A681A24088859985" + prev +'\n')
logd = zz[2].replace(mj.decode(), '').replace(chr(12), chr(10))
logd = zz[2].replace(mj.decode(), '')

lstd = lstf.replace(chr(12), chr(10)).replace('<body class="c body">',
'<body class="l body">').replace("font-size: x-small;",
"font-size: normal;")
if logd.count('\nERROR:') > 0:
warnings.warn("Noticed 'ERROR:' in LOG, you ought to take a look and see if there was a problem")
self._sb.check_error_log = True

self._sb._lastlog = logd

if lines:
while True:
try:
types += self.stderr[0].recv(4096000)
except (BlockingIOError):
pass
if types.count(logcodeo) >= 1:
break
sas_linetype_mapping
types = types.partition(b"TomSaysTypes=")[2]
types = list(types.rpartition(logcodeo)[0].decode(errors='replace'))

logl = []
logs = logd.split('\n')
for i in range(len(logs)):
logl.append({'line':logs[i], 'type':sas_linetype_mapping[int(types[i])]})
logd = logl

return dict(LOG=logd, LST=lstd)

def _breakprompt(self, eos, cancel):
Expand Down Expand Up @@ -2299,3 +2321,18 @@ def read(self, size=4096):
else:
return datap.decode(self._io.sascfg.encoding, errors=self.errs)

sas_linetype_mapping = {
0 : "Normal",
1 : "Hilighted",
2 : "Source",
3 : "Title",
4 : "Byline",
5 : "Footnote",
6 : "Error",
7 : "Warning",
8 : "Note",
9 : "Message"
}



0 comments on commit 17c4179

Please sign in to comment.