Commit 69a2a6d3 authored by Saikiran Srirangapalli's avatar Saikiran Srirangapalli

Merge branch 'master' of gitlab.com:saikiran1096/gradaudit into reqstring

parents 50effd5d 5f8c28d7
......@@ -25,7 +25,19 @@ import os.path as path
Transcript = namedtuple(
'Transcript', ['name', 'degree', 'major', 'year', 'spec', 'courses'])
class CourseNotFoundError(Exception):
"""
Error raised an invalid course is encountered when
generating main.lp
"""
msg = "Course {} was not found in the database."
def __init__(self, course):
self.msg = CourseNotFoundError.msg.format("'{}'".format(course))
def __str__(self):
return self.msg
def get_package_dir():
"""
Returns the directory that this package is located.
......@@ -56,7 +68,8 @@ def get_courses():
"""
Returns a list of all valid courses
"""
with open('course.lp', 'r') as fil:
path = get_package_dir() + '/' + 'course.lp'
with open(path, 'r') as fil:
valid_courses = re.findall('[a-z]+[0-9][0-9V][0-9]{2}', fil.read())
return valid_courses
......@@ -96,14 +109,21 @@ def gen_main(transcript):
# the _taken(<name>,[c1,c2...cn]). atom
taken_list = '_taken({},['.format(transcript.name)
has_taken = str() # series of _hasTaken/2 atoms
try:
req = get_required_courses(
transcript.degree, transcript.major, transcript.year)
except IOError as err:
raise err
valid_courses = get_courses()
for course in transcript.courses:
# course not found in databse
if not course in valid_courses:
raise CourseNotFoundError(course)
# include only those courses that could possibly
# counted as electives i.e. those that are not required.
# in the 'taken list' (improves performance)
......@@ -112,8 +132,9 @@ def gen_main(transcript):
has_taken += '_hasTaken({0},{1}).\n'.format(transcript.name, course)
# strip trailing comma
taken_list = taken_list[:-1]
# strip trailisng comma
if transcript.courses != []:
taken_list = taken_list[:-1]
taken_list += ']).\n'
directory = get_package_dir()
......
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