Пример #1
0
Файл: server.py Проект: p/midge
 def do_maintenance(self):
     self.acquire_lock()
     try:
         logger.info("Scheduled maintenance")
         self.application.do_maintenance()
     finally:
         self.release_lock()
Пример #2
0
 def __init__(self, connection):
     StateTable.__init__(self, connection)
     existing_values = self.values
     for value in ("1", "2", "3", "4", "5"):
         if value not in existing_values:
             logger.info("Adding (unchangeable) Priority value: %s" % \
                         value)
             self.create_new_value(value)
Пример #3
0
Файл: server.py Проект: p/midge
 def _send_no_such_location(self, path):
     logger.info("No such location: %s" % path)
     self.send_response(HttpCodes.NotFound)
     self.send_header("Content-type", "text/html")
     self.send_header("Server", self.SERVER_NAME)
     self.end_headers()
     self.wfile.write("<html><body><h1>No such location!</h1>"
                      "<p>The location <b>%s</b> does not exist." % path)
     self.wfile.write("</body></html>")
Пример #4
0
Файл: server.py Проект: p/midge
 def start(self):
     logger.info("Starting server")
     next_hour = lib.get_utc_time_of_next_hour()
     while True:
         rs, ws, es = select.select([self.httpd], [self.httpd], [], 1)
         if rs or ws:
             self.httpd.handle_request()
         if lib.get_utc_time() > next_hour:
             self.sessions.do_maintenance()
             next_hour = lib.get_utc_time_of_next_hour()
Пример #5
0
 def logout(self, session_id):
     user = self.logged_in_users.get(session_id, None)
     if user is not None:
         logger.info('Logged out user "%s" under session: %s' % (
             user.username, session_id))
         user.logout()
         del self.logged_in_users[session_id]
         return True
     else:
         return False
Пример #6
0
 def login(self, session_id, username, password):
     user = User(self.connection)
     if user.login(username, password):
         self.logged_in_users[session_id] = user
         logger.info('Logging in user "%s" under session: %s' % (
             user.username, session_id))
         return True
     else:
         logger.info('Failed login attempt for user "%s"' % username)
         return False
Пример #7
0
Файл: server.py Проект: p/midge
 def _get_locations(self, locations, application):
     """Build a dictionary of Location's from the locations module."""
     locations_map = {}
     for candidate_name in dir(locations):
         candidate = getattr(locations, candidate_name)
         if type(candidate) == type(locations.Location) and \
                issubclass(candidate, locations.Location) and \
                candidate != locations.Location:
             locations_map[candidate.path] = candidate(application)
             logger.info("Found %s class to handle path %s" % \
                         (candidate.__name__, candidate.path))
     return locations_map
Пример #8
0
Файл: server.py Проект: p/midge
 def __init__(self, application, locations):
     self.sessions = Sessions(application)
     RequestHandler._locations = self._get_locations(locations,
                                                     application)
     RequestHandler._sessions = self.sessions
     interface = config.Server.interface
     port = config.Server.port
     if interface:
         logger.info("Creating server on %s:%s" % (interface, port))
     else:
         logger.info("Creating server on all interfaces:%s" % port)
     self.httpd = MyHTTPServer( (interface, port), RequestHandler)
Пример #9
0
 def _setup_tables(self):
     if not administration.have_tables(config.Database.name):
         logger.info("No tables defined - creating new ones")
         administration.create_tables(config.Database.name)
Пример #10
0
 def expired_session(self, session_id):
     user = self.logged_in_users.get(session_id, None)
     if user is not None:
         logger.info('"Timeout of user "%s"' % user.username)
         user.logout()
         del self.logged_in_users[session_id]