From e02d725b49e852f3aa8a5a944a1b726b651ca665 Mon Sep 17 00:00:00 2001 From: Miguel BarĂ£o Date: Tue, 26 Mar 2019 18:10:59 +0000 Subject: [PATCH] Check if dependencies exist as nodes. --- aprendizations/learnapp.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/aprendizations/learnapp.py b/aprendizations/learnapp.py index c3be9b7..0a8a66f 100644 --- a/aprendizations/learnapp.py +++ b/aprendizations/learnapp.py @@ -40,6 +40,11 @@ async def bcrypt_hash_gen(new_pw): # ============================================================================ +class LearnException(Exception): + pass + + +# ============================================================================ # LearnApp - application logic # ============================================================================ class LearnApp(object): @@ -256,8 +261,8 @@ class LearnApp(object): # # Edges are obtained from the deps defined in the YAML file for each topic. # ------------------------------------------------------------------------ - def populate_graph(self, conffile): - logger.info(f'Populating graph from: {conffile}') + def populate_graph(self, conffile: str): + logger.info(f'Populating graph from: {conffile}...') config = load_yaml(conffile) # course configuration # default attributes that apply to the topics @@ -275,7 +280,13 @@ class LearnApp(object): g.add_nodes_from(topics.keys()) for tref, attr in topics.items(): - g.add_edges_from((d, tref) for d in attr.get('deps', [])) + for d in attr.get('deps', []): + if d not in g.nodes(): + logger.error(f'Topic "{tref}" depends on "{d}" but the ' + f'latter does not exist') + raise LearnException() + else: + g.add_edge(d, tref) t = g.node[tref] # get current topic node t['type'] = attr.get('type', 'topic') @@ -302,7 +313,7 @@ class LearnApp(object): # Buils dictionary of question factories # ------------------------------------------------------------------------ def make_factory(self): - logger.info('Building questions factory') + logger.info('Building questions factory...') factory = {} # {'qref': QFactory()} g = self.deps for tref in g.nodes(): -- libgit2 0.21.2