diff --git a/app.py b/app.py index 71da579..7ffe13d 100644 --- a/app.py +++ b/app.py @@ -51,17 +51,13 @@ class App(object): # ------------------------------------------------------------------------ def __init__(self, conf={}): - logger.info('Starting application') + logger.info('Starting application.') self.online = dict() # {uid: {'student':{...}, 'test': {...}}, ...} self.allowed = set([]) # '0' is hardcoded to allowed elsewhere - # build test configuration dictionary - testconf = {} - if conf['filename']: - logger.info(f'Loading test configuration "{conf["filename"]}".') - testconf.update(load_yaml(conf['filename'])) - - testconf.update(conf) # configuration overrides + logger.info(f'Loading test configuration "{conf["filename"]}".') + testconf = load_yaml(conf['filename'], default={}) + testconf.update(conf) # configuration overrides from command line # start test factory try: diff --git a/serve.py b/serve.py index 6e86bb0..6921ed1 100755 --- a/serve.py +++ b/serve.py @@ -17,7 +17,7 @@ import json import tornado.ioloop import tornado.web import tornado.httpserver -from tornado import template, gen +from tornado import template, gen, websocket import yaml # this project @@ -48,6 +48,7 @@ class WebApplication(tornado.web.Application): (r'/review', ReviewHandler), (r'/admin', AdminHandler), (r'/file', FileHandler), + # (r'/ws', SocketHandler), (r'/', RootHandler), # TODO multiple tests ] @@ -138,6 +139,7 @@ class FileHandler(BaseHandler): uid = self.current_user ref = self.get_query_argument('ref', None) image = self.get_query_argument('image', None) + content_type, encoding = mimetypes.guess_type(image) if uid != '0': t = self.testapp.get_student_test(uid) @@ -149,6 +151,7 @@ class FileHandler(BaseHandler): raise tornado.web.HTTPError(404) # Not Found for q in t['questions']: + # search for the question that contains the image if q['ref'] == ref: filepath = path.join(q['path'], 'public', image) @@ -159,11 +162,11 @@ class FileHandler(BaseHandler): except PermissionError: logging.error(f'No permission: {filepath}') else: - content_type = mimetypes.guess_type(image) - self.set_header("Content-Type", content_type[0]) - with f: - self.write(f.read()) - await self.flush() + data = f.read() + f.close() + self.set_header("Content-Type", content_type) + self.write(data) + await self.flush() @@ -416,6 +419,8 @@ def main(): except: print('An error ocurred while setting up the logging system.') sys.exit(1) + + # start logging logging.info('===============================================') # --- start application diff --git a/test.py b/test.py index 08930ab..0a8ab6f 100644 --- a/test.py +++ b/test.py @@ -44,21 +44,21 @@ class TestFactory(dict): self.question_factory.load_files(files=self['files'], questions_dir=self['questions_dir']) # check if all questions exist ('ref' keys are correct?) - errors_found = False + errors_found = [] for q in self['questions']: for r in q['ref']: - logger.info(f'Checking question "{r}".') + logger.info(f' Checking "{r}".') try: self.question_factory.generate(r) except: logger.critical(f'Can\'t generate question "{r}".') - errors_found = True + errors_found.append(r) if errors_found: - logger.critical('Errors found while generating questions.') + logger.critical(f'{errors_found} errors found generating questions.') raise TestFactoryException() - - logger.info(f'Test factory ready for "{self["ref"]}".') + else: + logger.info(f'No errors found. Test factory ready for "{self["ref"]}".') # ----------------------------------------------------------------------- -- libgit2 0.21.2