Skip to content

Commit

Permalink
add lesson debug mode and fix validation
Browse files Browse the repository at this point in the history
  • Loading branch information
brownsarahm committed Mar 20, 2024
1 parent e9462c5 commit fb9e13b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
6 changes: 4 additions & 2 deletions cspt/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,19 +262,21 @@ def earlybonus(json_output):

@cspt_cli.command()
@click.argument('lesson-file',type=click.File('r'))
@click.option('-v','--debug',is_flag=True)

def exportprismia(lesson_file):
def exportprismia(lesson_file,debug):
'''
export prismia version of the content
'''
lesson = Lesson(lesson_file.read())
lesson = Lesson(lesson_file.read(),debug)

if lesson.valid():

prismia_text = lesson.get_prismia()
click.echo(prismia_text)
else:
click.echo(lesson.print_bad())
click.echo(lesson.debug)



Expand Down
26 changes: 20 additions & 6 deletions cspt/lesson.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,41 @@ def wrap(s,marker,newline=False):

class Lesson():
# TODO add processing
def __init__(self,text):
def __init__(self,text, debug=False):
# pull out header marked by ---
_,header,body = text.split('---')
self.metadata = yaml.safe_load(header)
if debug:
self.debug = []
else:
self.debug = False

# split at +++
blocks_in = body.split('+++')
blocks_in = body.strip().split('+++')
blocks_full = [b for b in blocks_in if b]

# check the blocks
self.block_res ={}

for i,block_text in enumerate(blocks_in):
for i,block_text in enumerate(blocks_full):
first_linebreak = block_text.find('\n')
meta_candidate = block_text[:first_linebreak].strip()
if meta_candidate:
if meta_candidate[0] =='{' and meta_candidate[-1] == '}':
self.block_res[i] = 'block'
if debug:
self.debug.append(('good',block_text))
else:
self.block_res[i] = meta_candidate
if debug:
self.debug.append(('bad',block_text))
else:
self.block_res[i] = 'no meta'
if debug:
self.debug.append(('missing',block_text))

# make a collection of blocks
self.blocks = [Block(b) for b in blocks_in]
self.blocks = [Block(b) for b in blocks_full]
# activate
self.activities = [b for b in self.blocks if b.labels['lesson_part'] == 'activity']

Expand All @@ -63,8 +74,11 @@ def valid(self):
check if any errors
'''
good_res = ['block','no meta']
validation_list = [v in good_res for v in self.block_res]

validation_list = [v in good_res for v in self.block_res.values()]
if self.debug:
# val_msg = ' '.join([str(n) for n in [len(validation_list),len(self.block_res)]])
val_msg = validation_list
self.debug.insert(0,val_msg)
# if num true == len then all good
return sum(validation_list)==len(self.block_res)

Expand Down

0 comments on commit fb9e13b

Please sign in to comment.