Commit df2edbf29ce8710625dd2656da1880f57676f04c
1 parent
db04e658
Exists in
master
and in
1 other branch
- removed commented code
Showing
2 changed files
with
15 additions
and
24 deletions
Show diff stats
knowledge.py
@@ -62,7 +62,6 @@ class Knowledge(object): | @@ -62,7 +62,6 @@ class Knowledge(object): | ||
62 | 62 | ||
63 | # ------------------------------------------------------------------------ | 63 | # ------------------------------------------------------------------------ |
64 | def get_knowledge_state(self): | 64 | def get_knowledge_state(self): |
65 | - # logger.debug('-> Knowledge.get_knowledge_state()') | ||
66 | ts = [] | 65 | ts = [] |
67 | for t in self.topic_sequence: | 66 | for t in self.topic_sequence: |
68 | if t in self.state: | 67 | if t in self.state: |
@@ -73,7 +72,6 @@ class Knowledge(object): | @@ -73,7 +72,6 @@ class Knowledge(object): | ||
73 | 72 | ||
74 | # ------------------------------------------------------------------------ | 73 | # ------------------------------------------------------------------------ |
75 | def get_topic_progress(self): | 74 | def get_topic_progress(self): |
76 | - # logger.debug('-> Knowledge.get_topic_progress()') | ||
77 | return len(self.finished_questions) / (len(self.finished_questions) + len(self.questions)) | 75 | return len(self.finished_questions) / (len(self.finished_questions) + len(self.questions)) |
78 | 76 | ||
79 | # ------------------------------------------------------------------------ | 77 | # ------------------------------------------------------------------------ |
serve.py
@@ -33,7 +33,7 @@ from tools import load_yaml, md | @@ -33,7 +33,7 @@ from tools import load_yaml, md | ||
33 | # WebApplication - Tornado Web Server | 33 | # WebApplication - Tornado Web Server |
34 | # ============================================================================ | 34 | # ============================================================================ |
35 | class WebApplication(tornado.web.Application): | 35 | class WebApplication(tornado.web.Application): |
36 | - def __init__(self, learnapp): | 36 | + def __init__(self, learnapp, debug=False): |
37 | handlers = [ | 37 | handlers = [ |
38 | (r'/login', LoginHandler), | 38 | (r'/login', LoginHandler), |
39 | (r'/logout', LogoutHandler), | 39 | (r'/logout', LogoutHandler), |
@@ -140,6 +140,7 @@ class FileHandler(BaseHandler): | @@ -140,6 +140,7 @@ class FileHandler(BaseHandler): | ||
140 | 140 | ||
141 | # ---------------------------------------------------------------------------- | 141 | # ---------------------------------------------------------------------------- |
142 | # respond to AJAX to get a JSON question | 142 | # respond to AJAX to get a JSON question |
143 | +# ---------------------------------------------------------------------------- | ||
143 | class QuestionHandler(BaseHandler): | 144 | class QuestionHandler(BaseHandler): |
144 | templates = { | 145 | templates = { |
145 | 'checkbox': 'question-checkbox.html', | 146 | 'checkbox': 'question-checkbox.html', |
@@ -153,13 +154,8 @@ class QuestionHandler(BaseHandler): | @@ -153,13 +154,8 @@ class QuestionHandler(BaseHandler): | ||
153 | 'success': 'question-success.html', | 154 | 'success': 'question-success.html', |
154 | } | 155 | } |
155 | 156 | ||
156 | - # @tornado.web.authenticated | ||
157 | - # def get(self): # FIXME unused | ||
158 | - # self.redirect('/') | ||
159 | - | ||
160 | @tornado.web.authenticated | 157 | @tornado.web.authenticated |
161 | def post(self): | 158 | def post(self): |
162 | - # ref = self.get_body_arguments('question_ref') | ||
163 | user = self.current_user | 159 | user = self.current_user |
164 | answer = self.get_body_arguments('answer') | 160 | answer = self.get_body_arguments('answer') |
165 | next_question = self.learn.check_answer(user, answer) | 161 | next_question = self.learn.check_answer(user, answer) |
@@ -201,38 +197,33 @@ def main(): | @@ -201,38 +197,33 @@ def main(): | ||
201 | 197 | ||
202 | # --- Commandline argument parsing | 198 | # --- Commandline argument parsing |
203 | argparser = argparse.ArgumentParser(description='Server for online learning. Enrolled students and topics have to be previously configured. Please read the documentation included with this software before running the server.') | 199 | argparser = argparse.ArgumentParser(description='Server for online learning. Enrolled students and topics have to be previously configured. Please read the documentation included with this software before running the server.') |
204 | - # FIXME: | ||
205 | - # serverconf_file = path.normpath(path.join(SERVER_PATH, 'config', 'server.conf')) | ||
206 | - # argparser.add_argument('--conf', default=serverconf_file, type=str, help='server configuration file') | ||
207 | - # argparser.add_argument('--debug', action='store_true', help='Enable debug logging.') | ||
208 | - # argparser.add_argument('--allow-all', action='store_true', | ||
209 | - # help='Students are initially allowed to login (can be denied later)') | ||
210 | - argparser.add_argument('conffile', type=str, nargs='+', help='Topics configuration file in YAML format.') # FIXME only one supported at the moment | 200 | + argparser.add_argument('conffile', type=str, nargs='+', |
201 | + help='Topics configuration file in YAML format.') # FIXME only one | ||
202 | + argparser.add_argument('--debug', action='store_true', | ||
203 | + help='Enable debug logging.') # FIXME not implemented | ||
211 | arg = argparser.parse_args() | 204 | arg = argparser.parse_args() |
212 | 205 | ||
213 | # --- Setup logging | 206 | # --- Setup logging |
214 | try: | 207 | try: |
215 | logging.config.dictConfig(load_yaml(LOGGER_CONF)) | 208 | logging.config.dictConfig(load_yaml(LOGGER_CONF)) |
216 | - except: # FIXME should this be done in a different way? | 209 | + except: |
217 | print('An error ocurred while setting up the logging system.') | 210 | print('An error ocurred while setting up the logging system.') |
218 | - print('Common causes:\n - inexistent directory "logs"?\n - write permission to "logs" directory?') | ||
219 | sys.exit(1) | 211 | sys.exit(1) |
220 | - | ||
221 | logging.info('===========================================================') | 212 | logging.info('===========================================================') |
222 | 213 | ||
223 | # --- start application | 214 | # --- start application |
224 | learnapp = LearnApp(arg.conffile[0]) | 215 | learnapp = LearnApp(arg.conffile[0]) |
225 | try: | 216 | try: |
226 | - webapp = WebApplication(learnapp) | 217 | + webapp = WebApplication(learnapp, debug=argparser.debug) |
227 | except Exception as e: | 218 | except Exception as e: |
228 | logging.critical('Can\'t start application.') | 219 | logging.critical('Can\'t start application.') |
229 | - # sys.exit(1) | ||
230 | - raise e # FIXME | 220 | + raise e |
231 | 221 | ||
232 | # --- create webserver | 222 | # --- create webserver |
233 | - http_server = tornado.httpserver.HTTPServer(webapp, ssl_options={ | ||
234 | - "certfile": "certs/cert.pem", | ||
235 | - "keyfile": "certs/key.pem" | 223 | + http_server = tornado.httpserver.HTTPServer(webapp, |
224 | + ssl_options={ | ||
225 | + "certfile": "certs/cert.pem", | ||
226 | + "keyfile": "certs/key.pem" | ||
236 | }) | 227 | }) |
237 | http_server.listen(8443) | 228 | http_server.listen(8443) |
238 | 229 | ||
@@ -240,7 +231,9 @@ def main(): | @@ -240,7 +231,9 @@ def main(): | ||
240 | try: | 231 | try: |
241 | logging.info('Webserver running...') | 232 | logging.info('Webserver running...') |
242 | tornado.ioloop.IOLoop.current().start() | 233 | tornado.ioloop.IOLoop.current().start() |
234 | + | ||
243 | # running... | 235 | # running... |
236 | + | ||
244 | except KeyboardInterrupt: | 237 | except KeyboardInterrupt: |
245 | tornado.ioloop.IOLoop.current().stop() | 238 | tornado.ioloop.IOLoop.current().stop() |
246 | logging.info('Webserver stopped.') | 239 | logging.info('Webserver stopped.') |