Skip to content

Commit

Permalink
limit cancel to submit methods
Browse files Browse the repository at this point in the history
  • Loading branch information
tomweber-sas committed Mar 19, 2024
1 parent 403d153 commit 9d6dd7d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
14 changes: 10 additions & 4 deletions saspy/sasiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,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)

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 @@ -1172,10 +1173,15 @@ def submit(self, code: str, results: str ="html", prompt: dict = None, **kwargs)
except (KeyboardInterrupt, SystemExit):
conn.close()
print('Exception caught!')
response = self.sascfg._prompt(
"Please enter (C) to Cancel submitted code or (Q) to Quit waiting for results or (W) continue to Wait.")
if cancel:
msg = "Please enter (C) to Cancel submitted code or (Q) to Quit waiting for results or (W) continue to Wait."
else:
msg = "CANCEL is only supported for the submit*() methods. Please enter (Q) to Quit waiting for results or (W) to continue to Wait."

response = self.sascfg._prompt(msg)

while True:
if response is None or response.upper() == 'C':
if cancel and response is None or response.upper() == 'C':
# GET Status for JOB
canheaders = {"Accept":"text/plain", "Authorization":"Bearer "+self.sascfg._token, "If-Match":Etag}
conn.connect()
Expand All @@ -1188,7 +1194,7 @@ def submit(self, code: str, results: str ="html", prompt: dict = None, **kwargs)
return dict(LOG='', LST='')
if response.upper() == 'W':
break
response = self.sascfg._prompt("Please enter (Q) to Quit waiting for results or (C) to continue waiting.")
response = self.sascfg._prompt(msg)

except hc.RemoteDisconnected as Dis:
conn.close()
Expand Down
26 changes: 17 additions & 9 deletions saspy/sasioiom.py
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,7 @@ def _asubmit(self, code, results="html"):
odsopen = b"ods listing close;ods "+self.sascfg.output.encode()+ \
b" (id=saspy_internal) file="+self._tomods1+b" options(bitmap_mode='inline') device=svg style="+self._sb.HTML_Style.encode()+ \
b"; ods graphics on / outputfmt=png;\n"

odsclose = b"ods "+self.sascfg.output.encode()+b" (id=saspy_internal) close;ods listing;\n"
ods = True
pgm = b""
Expand Down Expand Up @@ -857,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)

#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 @@ -1029,7 +1031,7 @@ def submit(self, code: str, results: str ="html", prompt: dict = None, **kwargs)

except (KeyboardInterrupt, SystemExit):
print('Exception caught!')
ll = self._breakprompt(logcodeo)
ll = self._breakprompt(logcodeo, cancel)

if ll.get('ABORT', False):
return ll
Expand Down Expand Up @@ -1075,7 +1077,7 @@ def submit(self, code: str, results: str ="html", prompt: dict = None, **kwargs)
self._sb._lastlog = logd
return dict(LOG=logd, LST=lstd)

def _breakprompt(self, eos):
def _breakprompt(self, eos, cancel):
found = False
logf = b''
lstf = b''
Expand All @@ -1086,18 +1088,25 @@ def _breakprompt(self, eos):
return dict(LOG=b"No SAS process attached. SAS process has terminated unexpectedly.", LST=b'', ABORT=True)

if True:
response = self.sascfg._prompt(
"Please enter (T) to Terminate SAS or (C) to Cancel submitted code or (W) continue to Wait.")
if cancel:
msg = "Please enter (T) to Terminate SAS or (C) to Cancel submitted code or (W) continue to Wait."
else:
msg = "CANCEL is only supported for the submit*() methods. Please enter (T) to Terminate SAS or (W) to continue to Wait."

response = self.sascfg._prompt(msg)
while True:
if response is None or response.upper() == 'C':
if cancel and response is None or response.upper() == 'C':
self.stdcan[0].send(b'C')
return dict(LOG=b'', LST=b'', BC=False)
if response is None or response.upper() == 'W':
return dict(LOG=b'', LST=b'', BC=True)
if response.upper() == 'T':
break
response = self.sascfg._prompt("Please enter (T) to Terminate SAS or (C) to Cancel or (W) to Wait.")
response = self.sascfg._prompt(msg)

self._endsas()

'''
if os.name == 'nt':
self.pid.kill()
else:
Expand All @@ -1107,10 +1116,9 @@ def _breakprompt(self, eos):
self.pid = None
self._sb.SASpid = None
return dict(LOG=b"SAS process terminated", LST=b'', ABORT=True)


'''

return dict(LOG="SAS process terminated", LST='', ABORT=True)

"""
while True:
Expand Down

0 comments on commit 9d6dd7d

Please sign in to comment.