Commit 691ee0979b808ebfa535a5f42d06d3349f028a93
1 parent
b9094cfb
Exists in
master
and in
1 other branch
fixed: now logs an error when topic/questions.yaml is not found
Showing
4 changed files
with
10 additions
and
11 deletions
Show diff stats
BUGS.md
| 1 | 1 | ||
| 2 | BUGS: | 2 | BUGS: |
| 3 | 3 | ||
| 4 | -- se refs de um topic estao invalidos, nao carrega esse topico. devia haver um error nos logs a indicar qual o ref invalido. | ||
| 5 | - forçar reload das perguntas sem ter de deitar abaixo o servidor. | 4 | - forçar reload das perguntas sem ter de deitar abaixo o servidor. |
| 6 | - topicos virtuais nao deveriam aparecer. na construção da árvore os sucessores seriam ligados directamente aos predecessores. | 5 | - topicos virtuais nao deveriam aparecer. na construção da árvore os sucessores seriam ligados directamente aos predecessores. |
| 7 | - Criar outra estrutura organizada em capítulos (conjuntos de tópicos). Permitir capítulos de capítulos, etc. talvez usar grafos de grafos... | 6 | - Criar outra estrutura organizada em capítulos (conjuntos de tópicos). Permitir capítulos de capítulos, etc. talvez usar grafos de grafos... |
| @@ -34,6 +33,7 @@ TODO: | @@ -34,6 +33,7 @@ TODO: | ||
| 34 | 33 | ||
| 35 | FIXED: | 34 | FIXED: |
| 36 | 35 | ||
| 36 | +- se refs de um topic estao invalidos, nao carrega esse topico. devia haver um error nos logs a indicar qual o ref invalido. | ||
| 37 | - link directo para topico nao valida se topico esta unlocked. | 37 | - link directo para topico nao valida se topico esta unlocked. |
| 38 | - templates not working: quesntion-information, question-warning (remove all informative panels??) | 38 | - templates not working: quesntion-information, question-warning (remove all informative panels??) |
| 39 | - enderecos errados dao internal error. | 39 | - enderecos errados dao internal error. |
demo/demo.yaml
learnapp.py
| @@ -297,7 +297,7 @@ def build_dependency_graph(config={}): | @@ -297,7 +297,7 @@ def build_dependency_graph(config={}): | ||
| 297 | # if questions not in configuration then load all, preserving order | 297 | # if questions not in configuration then load all, preserving order |
| 298 | if not tnode['questions']: | 298 | if not tnode['questions']: |
| 299 | tnode['questions'] = [q['ref'] for q in loaded_questions] | 299 | tnode['questions'] = [q['ref'] for q in loaded_questions] |
| 300 | - | 300 | + |
| 301 | # make questions factory (without repeating same question) | 301 | # make questions factory (without repeating same question) |
| 302 | tnode['factory'] = {} | 302 | tnode['factory'] = {} |
| 303 | for q in loaded_questions: | 303 | for q in loaded_questions: |
tools.py
| @@ -133,25 +133,24 @@ def md_to_html(text, q=None): | @@ -133,25 +133,24 @@ def md_to_html(text, q=None): | ||
| 133 | # load data from yaml file | 133 | # load data from yaml file |
| 134 | # --------------------------------------------------------------------------- | 134 | # --------------------------------------------------------------------------- |
| 135 | def load_yaml(filename, default=None): | 135 | def load_yaml(filename, default=None): |
| 136 | + filename = path.expanduser(filename) | ||
| 136 | try: | 137 | try: |
| 137 | - f = open(path.expanduser(filename), 'r', encoding='utf-8') | 138 | + f = open(filename, 'r', encoding='utf-8') |
| 138 | except FileNotFoundError: | 139 | except FileNotFoundError: |
| 139 | - logger.error(f'Can\'t open "{script}": not found.') | ||
| 140 | - return default | 140 | + logger.error(f'Can\'t open "{filename}": not found.') |
| 141 | except PermissionError: | 141 | except PermissionError: |
| 142 | - logger.error(f'Can\'t open "{script}": no permission.') | ||
| 143 | - return default | 142 | + logger.error(f'Can\'t open "{filename}": no permission.') |
| 144 | except IOError: | 143 | except IOError: |
| 145 | logger.error(f'Can\'t open file "{filename}".') | 144 | logger.error(f'Can\'t open file "{filename}".') |
| 146 | - return default | ||
| 147 | else: | 145 | else: |
| 148 | with f: | 146 | with f: |
| 149 | try: | 147 | try: |
| 150 | - return yaml.load(f) | 148 | + default = yaml.load(f) |
| 151 | except yaml.YAMLError as e: | 149 | except yaml.YAMLError as e: |
| 152 | mark = e.problem_mark | 150 | mark = e.problem_mark |
| 153 | logger.error(f'In YAML file "{filename}" near line {mark.line}, column {mark.column+1}.') | 151 | logger.error(f'In YAML file "{filename}" near line {mark.line}, column {mark.column+1}.') |
| 154 | - return default | 152 | + finally: |
| 153 | + return default | ||
| 155 | 154 | ||
| 156 | # --------------------------------------------------------------------------- | 155 | # --------------------------------------------------------------------------- |
| 157 | # Runs a script and returns its stdout parsed as yaml, or None on error. | 156 | # Runs a script and returns its stdout parsed as yaml, or None on error. |