Updated to raise ExcecutionError if s(ASP) excecution does not succeed

parent 123bacc0
from tempfile import NamedTemporaryFile
from subprocess import check_output
from subprocess import Popen, PIPE
import re
import gradaudit.util as util
class ExecutionError(Exception):
""" Thrown when there is an error executing main.lp under s(ASP) """
def __init__(self, msg, main, err):
self.msg = msg
self.main = main
self.err = err
self.strepr = '{}\n'\
'Main contents:\n{}\n'\
'Error:\n{}'.format(msg, main, err)
def __str__(self):
return self.strepr
class GASResponse(object):
""" GAS advising information """
_missing_class_re = r'hasNotTaken\({},([a-z]+[1-4][0-9V][0-9][0-9])\)'
......@@ -29,17 +44,27 @@ class GASResponse(object):
with NamedTemporaryFile() as fil:
answer_set = check_output(['sasp', fil.name])
# Command to run audit
audit = ['sasp', fil.name]
# Execute the audit, capture stdout, stderr
run = Popen(audit, stdout=PIPE, stderr=PIPE)
(answer_set, audit_err) = run.communicate()
if run.returncode != 0:
msg = 'Error executing audit'
raise ExecutionError(msg, main_contents, audit_err)
return answer_set
def _extract_advice(cls, answer_set, name):
""" Parses answer set for advising information """
class_re = GASResponse._missing_class_re.format(name)
hours_re = GASResponse._missing_hours_re.format(name)
electives_re = GASResponse._missing_electives_re.format(name)
grad = GASResponse._grad.format(name)
class_re = cls._missing_class_re.format(name)
hours_re = cls._missing_hours_re.format(name)
electives_re = cls._missing_electives_re.format(name)
grad = cls._grad.format(name)
classes = re.findall(class_re, answer_set)
hours = re.findall(hours_re, answer_set)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment