Commit df2edbf29ce8710625dd2656da1880f57676f04c

Authored by Miguel Barão
1 parent db04e658
Exists in master and in 1 other branch dev

- 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 62  
63 63 # ------------------------------------------------------------------------
64 64 def get_knowledge_state(self):
65   - # logger.debug('-> Knowledge.get_knowledge_state()')
66 65 ts = []
67 66 for t in self.topic_sequence:
68 67 if t in self.state:
... ... @@ -73,7 +72,6 @@ class Knowledge(object):
73 72  
74 73 # ------------------------------------------------------------------------
75 74 def get_topic_progress(self):
76   - # logger.debug('-> Knowledge.get_topic_progress()')
77 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 33 # WebApplication - Tornado Web Server
34 34 # ============================================================================
35 35 class WebApplication(tornado.web.Application):
36   - def __init__(self, learnapp):
  36 + def __init__(self, learnapp, debug=False):
37 37 handlers = [
38 38 (r'/login', LoginHandler),
39 39 (r'/logout', LogoutHandler),
... ... @@ -140,6 +140,7 @@ class FileHandler(BaseHandler):
140 140  
141 141 # ----------------------------------------------------------------------------
142 142 # respond to AJAX to get a JSON question
  143 +# ----------------------------------------------------------------------------
143 144 class QuestionHandler(BaseHandler):
144 145 templates = {
145 146 'checkbox': 'question-checkbox.html',
... ... @@ -153,13 +154,8 @@ class QuestionHandler(BaseHandler):
153 154 'success': 'question-success.html',
154 155 }
155 156  
156   - # @tornado.web.authenticated
157   - # def get(self): # FIXME unused
158   - # self.redirect('/')
159   -
160 157 @tornado.web.authenticated
161 158 def post(self):
162   - # ref = self.get_body_arguments('question_ref')
163 159 user = self.current_user
164 160 answer = self.get_body_arguments('answer')
165 161 next_question = self.learn.check_answer(user, answer)
... ... @@ -201,38 +197,33 @@ def main():
201 197  
202 198 # --- Commandline argument parsing
203 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 204 arg = argparser.parse_args()
212 205  
213 206 # --- Setup logging
214 207 try:
215 208 logging.config.dictConfig(load_yaml(LOGGER_CONF))
216   - except: # FIXME should this be done in a different way?
  209 + except:
217 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 211 sys.exit(1)
220   -
221 212 logging.info('===========================================================')
222 213  
223 214 # --- start application
224 215 learnapp = LearnApp(arg.conffile[0])
225 216 try:
226   - webapp = WebApplication(learnapp)
  217 + webapp = WebApplication(learnapp, debug=argparser.debug)
227 218 except Exception as e:
228 219 logging.critical('Can\'t start application.')
229   - # sys.exit(1)
230   - raise e # FIXME
  220 + raise e
231 221  
232 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 228 http_server.listen(8443)
238 229  
... ... @@ -240,7 +231,9 @@ def main():
240 231 try:
241 232 logging.info('Webserver running...')
242 233 tornado.ioloop.IOLoop.current().start()
  234 +
243 235 # running...
  236 +
244 237 except KeyboardInterrupt:
245 238 tornado.ioloop.IOLoop.current().stop()
246 239 logging.info('Webserver stopped.')
... ...