def main():
  """ Main. """

  logging.getLogger().setLevel(logging.INFO)
  logging.info("Starting server on port {0}".format(DEFAULT_PORT))

  # Create backups dir if it doesn't exist.
  if not backup_recovery_helper.mkdir(BACKUP_DIR_LOCATION):
    logging.warning("Dir '{0}' already exists. Skipping dir creation...".
      format(BACKUP_DIR_LOCATION))

  # Start Tornado.
  http_server = tornado.httpserver.HTTPServer(get_application())
  http_server.bind(DEFAULT_PORT)
  http_server.start(0)
  tornado.ioloop.IOLoop.instance().start()
    request = self.request
    http_request_data = request.body
    response = self.backup_recovery_service.remote_request(http_request_data)

    request.connection.write_headers(
      tornado.httputil.ResponseStartLine('HTTP/1.1', HTTP_OK, 'OK'),
      tornado.httputil.HTTPHeaders({"Content-Length": str(len(response))}))
    request.connection.write(response)
    request.connection.finish()

def get_application():
  """ Retrieves the application to feed into tornado. """
  return tornado.web.Application([
    (r"/?", MainHandler, dict(backup_recovery_service=BackupService())),
    ], )

if __name__ == "__main__":
  logging.getLogger().setLevel(logging.INFO)
  logging.info("Starting server on port {0}".format(DEFAULT_PORT))

  # Create backups dir if it doesn't exist.
  if not backup_recovery_helper.mkdir(BACKUP_DIR_LOCATION):
    logging.warning("Dir '{0}' already exists. Skipping dir creation...".
      format(BACKUP_DIR_LOCATION))

  # Start Tornado.
  http_server = tornado.httpserver.HTTPServer(get_application())
  http_server.bind(DEFAULT_PORT)
  http_server.start(0)
  tornado.ioloop.IOLoop.instance().start()
Example #3
0
        request.connection.write_headers(
            tornado.httputil.ResponseStartLine('HTTP/1.1', HTTP_OK, 'OK'),
            tornado.httputil.HTTPHeaders(
                {"Content-Length": str(len(response))}))
        request.connection.write(response)
        request.connection.finish()


def get_application():
    """ Retrieves the application to feed into tornado. """
    return tornado.web.Application([
        (r"/?", MainHandler, dict(backup_recovery_service=BackupService())),
    ], )


if __name__ == "__main__":
    logging.getLogger().setLevel(logging.INFO)
    logging.info("Starting server on port {0}".format(DEFAULT_PORT))

    # Create backups dir if it doesn't exist.
    if not backup_recovery_helper.mkdir(BACKUP_DIR_LOCATION):
        logging.warning(
            "Dir '{0}' already exists. Skipping dir creation...".format(
                BACKUP_DIR_LOCATION))

    # Start Tornado.
    http_server = tornado.httpserver.HTTPServer(get_application())
    http_server.bind(DEFAULT_PORT)
    http_server.start(0)
    tornado.ioloop.IOLoop.instance().start()
Example #4
0
  def test_mkdir(self):
    flexmock(os).should_receive('mkdir').and_return().at_least().times(1)
    self.assertEquals(True, backup_recovery_helper.mkdir('foo'))

    flexmock(os).should_receive('mkdir').and_raise(OSError)
    self.assertEquals(False, backup_recovery_helper.mkdir('foo'))