diff --git a/BUGS.md b/BUGS.md index 56a1a4a..08a5727 100644 --- a/BUGS.md +++ b/BUGS.md @@ -27,6 +27,7 @@ # FIXED +- Quando grava JSON do teste deve usar 'path' tal como definido na configuração e não expandido. Isto porque em OSX /home é /Users e quando se muda de um sistema para outro não encontra os testes. Assim, usando ~ na configuração deveria funcionar sempre. - configuração do teste não joga bem com o do aprendizations. Em particular os scripts não ficam com o mesmo path!!! - configurar pf em freebsd, port forward 80 -> 8080. documentacao - barras com notas em grade estão desalinhadas. diff --git a/app.py b/app.py index e12ded6..0e3c39c 100644 --- a/app.py +++ b/app.py @@ -34,7 +34,8 @@ class App(object): self.testfactory = test.TestFactory(filename, conf=conf) # connect to database and check registered students - engine = create_engine('sqlite:///{}'.format(self.testfactory['database']), echo=False) + dbfile = path.expanduser(self.testfactory['database']) + engine = create_engine('sqlite:///{}'.format(dbfile), echo=False) self.Session = scoped_session(sessionmaker(bind=engine)) try: @@ -133,7 +134,7 @@ class App(object): # save test in JSON format fname = ' -- '.join((t['student']['number'], t['ref'], str(t['finish_time']))) + '.json' - fpath = path.abspath(path.join(t['answers_dir'], fname)) + fpath = path.join(t['answers_dir'], fname) t.save_json(fpath) # insert test and questions into database diff --git a/questions.py b/questions.py index 58bf28e..2470392 100644 --- a/questions.py +++ b/questions.py @@ -447,7 +447,7 @@ class QuestionTextArea(Question): 'correct': '' # trying to execute this will fail => grade 0.0 }) - self['correct'] = path.abspath(path.normpath(path.join(self['path'], self['correct']))) + self['correct'] = path.join(self['path'], self['correct']) #------------------------------------------------------------------------ # can return negative values for wrong answers diff --git a/serve.py b/serve.py index a5814be..e8565ab 100755 --- a/serve.py +++ b/serve.py @@ -281,12 +281,19 @@ class Root(object): @require(name_is('0')) def review(self, test_id): fname = self.app.get_json_filename_of_test(test_id) - with open(fname) as f: - t = json.load(f) - r = self.template['review'].render(t=t) - # import pdfkit - # pdfkit.from_string(r, 'out.pdf') # FIXME fails getting css, images, etc - return r + try: + f = open(path.expanduser(fname)) + except FileNotFoundError: + logging.error('Cannot find "{}" for review.'.format(fname)) + except Exception as e: + raise e + else: + with f: + t = json.load(f) + return self.template['review'].render(t=t) + # FIXME + # import pdfkit + # pdfkit.from_string(r, 'out.pdf') # FIXME fails getting css, images, etc @cherrypy.expose @require(name_is('0')) diff --git a/templates/review.html b/templates/review.html index 56706ee..eb52930 100644 --- a/templates/review.html +++ b/templates/review.html @@ -226,7 +226,7 @@ % if t['show_points']:

- (Cotação: ${round(q['points'] / total_points * 20.0, 1)} pontos) + (Cotação: ${round(q['points'] / total_points * 20.0, 2)} pontos)

% endif diff --git a/test.py b/test.py index bd7578d..2a74e7d 100644 --- a/test.py +++ b/test.py @@ -74,7 +74,7 @@ class TestFactory(dict): if 'ref' not in self: logger.warning('Missing "ref". Will use current date/time.') if 'answers_dir' not in self: - logger.warning('Missing "answers_dir". Will use current directory!') + logger.warning('Missing "answers_dir". Will save to current directory {}'.format(path.abspath(path.curdir))) if 'questions_dir' not in self: logger.warning('Missing "questions_dir". Using {}'.format(path.abspath(path.curdir))) if 'files' not in self: @@ -89,15 +89,15 @@ class TestFactory(dict): self.setdefault('show_ref', False) self.setdefault('questions_dir', path.curdir) self.setdefault('answers_dir', path.curdir) - self['database'] = path.abspath(path.expanduser(self['database'])) - self['questions_dir'] = path.abspath(path.expanduser(self['questions_dir'])) - self['answers_dir'] = path.abspath(path.expanduser(self['answers_dir'])) + # self['database'] = path.abspath(path.expanduser(self['database'])) + # self['questions_dir'] = path.abspath(path.expanduser(self['questions_dir'])) + # self['answers_dir'] = path.abspath(path.expanduser(self['answers_dir'])) - if not path.isfile(self['database']): + if not path.isfile(path.expanduser(self['database'])): logger.critical('Can\'t find database "{}"'.format(self['database'])) raise TestFactoryException() - if not path.isdir(self['questions_dir']): + if not path.isdir(path.expanduser(self['questions_dir'])): logger.critical('Can\'t find questions directory "{}"'.format(self['questions_dir'])) raise TestFactoryException() @@ -117,7 +117,7 @@ class TestFactory(dict): try: - f = open(path.join(self['answers_dir'],'REMOVE-ME'), 'w') + f = open(path.join(path.expanduser(self['answers_dir']),'REMOVE-ME'), 'w') except EnvironmentError: logger.critical('Cannot write answers to "{0}".'.format(self['answers_dir'])) raise TestFactoryException() @@ -175,7 +175,7 @@ class TestFactory(dict): 'show_hints': self['show_hints'], 'show_points': self['show_points'], 'show_ref': self['show_ref'], - 'debug': self['debug'], + 'debug': self['debug'], # required by template test.html 'database': self['database'], 'questions_dir': self['questions_dir'], 'files': self['files'], @@ -249,7 +249,7 @@ class Test(dict): # ----------------------------------------------------------------------- def save_json(self, filepath): - with open(filepath, 'w') as f: + with open(path.expanduser(filepath), 'w') as f: json.dump(self, f, indent=2, default=str) # HACK default=str is required for datetime objects logger.info('Student {}: saved JSON file.'.format(self['student']['number'])) diff --git a/tools.py b/tools.py index ccccec2..3060793 100644 --- a/tools.py +++ b/tools.py @@ -1,6 +1,8 @@ +from os import path import subprocess import logging + import yaml import markdown @@ -12,7 +14,7 @@ logger = logging.getLogger(__name__) # --------------------------------------------------------------------------- def load_yaml(filename, default=None): try: - f = open(filename, 'r', encoding='utf-8') + f = open(path.expanduser(filename), 'r', encoding='utf-8') except IOError: logger.error('Can\'t open file "{}"'.format(filename)) return default @@ -30,6 +32,7 @@ def load_yaml(filename, default=None): # Note: requires python 3.5+ # --------------------------------------------------------------------------- def run_script(script, stdin='', timeout=5): + script = path.expanduser(script) try: p = subprocess.run([script], input=stdin, -- libgit2 0.21.2