Commit bade350e authored by Alan Marchiori's avatar Alan Marchiori
Browse files

added does_not_contain

parent 1ebd3a80
...@@ -25,29 +25,7 @@ def show_report(hist, partstr, info): ...@@ -25,29 +25,7 @@ def show_report(hist, partstr, info):
width = min(120, shutil.get_terminal_size().columns) width = min(120, shutil.get_terminal_size().columns)
#if 'grade' in info: if partstr == 'TOTAL':
newline()
xlen = 47 # length of everything without name
echo("Part {:3}: {}".format(
info['index'],
info['name'][:max(10,width-xlen)].ljust(width-xlen)
))
echo(info['prompt'])
if partstr in hist['grade']:
echo('\tGrade: {} of {}'.format(
hist['grade'][partstr]['grade'],
hist['grade'][partstr]['total']))
if hist['grade'][partstr]['comment'] != '':
echo('\tComment: {}'.format(
hist['grade'][partstr]['comment']))
else:
warn("Part {:3} is ungraded ({})!".format(
info['index'], partstr
))
if 'TOTAL' in hist['grade']:
newline() newline()
echo("-"*width) echo("-"*width)
newline() newline()
...@@ -58,6 +36,39 @@ def show_report(hist, partstr, info): ...@@ -58,6 +36,39 @@ def show_report(hist, partstr, info):
echo("Graded by {}".format( echo("Graded by {}".format(
hist['grade']['TOTAL']['who'] hist['grade']['TOTAL']['who']
)) ))
else:
newline()
xlen = 47 # length of everything without name
echo("Part {:3}: {}".format(
info['index'],
info['name'][:max(10,width-xlen)].ljust(width-xlen)
))
echo(info['prompt'])
if partstr in hist['grade']:
echo('\tGrade: {} of {}'.format(
hist['grade'][partstr]['grade'],
hist['grade'][partstr]['total']))
if hist['grade'][partstr]['comment'] != '':
echo('\tComment: {}'.format(
hist['grade'][partstr]['comment']))
else:
warn("Part {:3} is ungraded ({})!".format(
info['index'], partstr
))
#
# if 'TOTAL' in hist['grade']:
# newline()
# echo("-"*width)
# newline()
# echo("Total: {} of {}".format(
# hist['grade']['TOTAL']['grade'],
# hist['grade']['TOTAL']['total']
# ))
# echo("Graded by {}".format(
# hist['grade']['TOTAL']['who']
# ))
@click.command(short_help="Check LAB") @click.command(short_help="Check LAB")
@click.option('--lab', type=int, default=None) @click.option('--lab', type=int, default=None)
...@@ -150,6 +161,10 @@ def check(lab, part): ...@@ -150,6 +161,10 @@ def check(lab, part):
# stop checking on first part failure # stop checking on first part failure
break break
# show total grade at the end, if it's graded.
if 'grade' in hist and 'TOTAL' in hist['grade']:
show_report(hist, 'TOTAL', None)
# only check gitlab if all tests pass # only check gitlab if all tests pass
if all(presults): if all(presults):
newline() newline()
......
...@@ -105,6 +105,10 @@ class Checker: ...@@ -105,6 +105,10 @@ class Checker:
else: else:
error("{}: failed!".format(msg)) error("{}: failed!".format(msg))
error(t) error(t)
if 'on_error' in check:
error(check['on_error'])
# stop on first error # stop on first error
return False return False
if 'stdout' in check: if 'stdout' in check:
...@@ -198,16 +202,41 @@ class Checker: ...@@ -198,16 +202,41 @@ class Checker:
result = [] result = []
for test in args: for test in args:
for fname, check in test.items(): for fname, check in test.items():
text = Path(fname).read_text() if os.path.exists(fname):
for c in check: text = Path(fname).read_text()
a = c in text for c in check:
result += [a] a = c in text
if not a: result += [a]
warn("The file {} does not contain \"{}\"".format( if not a:
fname, c warn("The file {} does not contain \"{}\"".format(
)) fname, c
))
else:
warn("The file {} does not exist!".format(fname))
result += [False]
return all(result) return all(result)
def does_not_contain(self, args):
"list of file: words to check for... returns true if all words are not found"
dbg('.does_not_contain({})'.format(args))
result = []
for test in args:
for fname, check in test.items():
if os.path.exists(fname):
text = Path(fname).read_text()
for c in check:
a = c in text
result += [a]
if a:
warn("The file {} contains \"{}\"".format(
fname, c
))
else:
warn("The file {} does not exist!".format(fname))
result += [False]
return not any(result)
def cd_labroot(self): def cd_labroot(self):
if os.path.exists(self.cwd): if os.path.exists(self.cwd):
debug("{}: {}".format(__name__, debug("{}: {}".format(__name__,
...@@ -245,7 +274,7 @@ class Checker: ...@@ -245,7 +274,7 @@ class Checker:
# 'show']: # show is used for grading # 'show']: # show is used for grading
# continue # continue
for i,subpart in enumerate(self.info[check_type]): for i,subpart in enumerate(self.info[check_type]):
for k, args in subpart.items(): for k, args in subpart.items():
debug(k, args) debug(k, args)
if hasattr(self, k): if hasattr(self, k):
......
...@@ -211,9 +211,14 @@ def init(course, semester, section, prefix, ta): ...@@ -211,9 +211,14 @@ def init(course, semester, section, prefix, ta):
# success(src) # success(src)
if '.gitignore' in coursedef: if '.gitignore' in coursedef:
if os.path.exists(os.expanduser(coursedef['.gitignore'])): if os.path.exists(os.path.expanduser(coursedef['.gitignore'])):
shutil.copyfile(os.expanduser(coursedef['.gitignore']), src = os.path.expanduser(coursedef['.gitignore'])
lp) dst = os.path.join(lp, '.gitignore')
debug("COPY {} --> {}".format(
src,
dst
))
shutil.copyfile(src, dst)
git.do_push(addfiles=['.gitignore'], git.do_push(addfiles=['.gitignore'],
cwd=lp, message='Added by labtool') cwd=lp, message='Added by labtool')
else: else:
......
...@@ -35,7 +35,7 @@ smtp_handler = logging.handlers.SMTPHandler( ...@@ -35,7 +35,7 @@ smtp_handler = logging.handlers.SMTPHandler(
subject=u"labtool crash report!") subject=u"labtool crash report!")
__version__ = '1.0.3' __version__ = '1.0.3'
__date__ = '2020-01-20T12:25:27.481510' __date__ = '2020-01-23T15:22:20.641522'
__user__ = 'cs206' __user__ = 'cs206'
__host__ = 'linuxremote3.bucknell.edu' __host__ = 'linuxremote3.bucknell.edu'
@click.group() @click.group()
......
Supports Markdown
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