def main(): logging.basicConfig(level=logging.INFO, format="[%(asctime)s]:%(levelname)s:%(name)s:%(message)s") from wsgiref.simple_server import make_server, WSGIRequestHandler from ankisyncd.thread import shutdown import ankisyncd.config class RequestHandler(WSGIRequestHandler): logger = logging.getLogger("ankisyncd.http") def log_error(self, format, *args): self.logger.error("%s %s", self.address_string(), format%args) def log_message(self, format, *args): self.logger.info("%s %s", self.address_string(), format%args) if len(sys.argv) > 1: # backwards compat config = ankisyncd.config.load(sys.argv[1]) else: config = ankisyncd.config.load() ankiserver = SyncApp(config) httpd = make_server(config['host'], int(config['port']), ankiserver, handler_class=RequestHandler) try: logger.info("Serving HTTP on {} port {}...".format(*httpd.server_address)) httpd.serve_forever() except KeyboardInterrupt: logger.info("Exiting...") finally: shutdown()
def main(): from eventlet import wsgi,wrap_ssl,listen from ankisyncd.thread import shutdown config = SafeConfigParser() config.read("ankisyncd.conf") ankiserver = SyncApp(config) host = config.get("sync_app", "host") port = config.getint("sync_app", "port") if(config.getboolean("sync_app", "ssl")): certfile = config.get("sync_app", "certfile") keyfile = config.get("sync_app", "keyfile") socket = wrap_ssl( listen((host, port)), certfile=certfile, keyfile=keyfile, server_side=True ) else: socket = listen((host, port)) try: wsgi.server(socket, ankiserver) finally: shutdown()
def main(): logging.basicConfig(level=logging.INFO) from wsgiref.simple_server import make_server from ankisyncd.thread import shutdown import ankisyncd.config if len(sys.argv) > 1: # backwards compat config = ankisyncd.config.load(sys.argv[1]) else: config = ankisyncd.config.load() ankiserver = SyncApp(config) httpd = make_server(config['host'], int(config['port']), ankiserver) try: logging.info("Serving HTTP on {} port {}...".format(*httpd.server_address)) httpd.serve_forever() except KeyboardInterrupt: logging.info("Exiting...") finally: shutdown()
def main(): logging.basicConfig( level=logging.INFO, format="[%(asctime)s]:%(levelname)s:%(name)s:%(message)s") config = load() host, port, app = config['host'], int(config['port']), SyncApp(config) httpd = make_server(host, port, app, handler_class=RequestHandler) httpd.timeout = 5 * 60 # httpd = make_server(host, port, app, handler_class=RequestHandler) # httpd.socket = ssl.wrap_socket(httpd.socket, # server_side=True, # certfile='/Users/zqk/cert/myCA.pem', # keyfile='/Users/zqk/cert/myCA.key', # ssl_version=ssl.PROTOCOL_TLS) try: logger.info( "Serving HTTP on {} port {}...".format(*httpd.server_address)) httpd.serve_forever() except KeyboardInterrupt: logger.info("Exiting...") finally: from ankisyncd.thread import shutdown shutdown()
def main(): from wsgiref.simple_server import make_server from ankisyncd.thread import shutdown logging.basicConfig(level=logging.INFO) if len(sys.argv) < 2: print("usage: {} configfile".format(os.path.basename(sys.argv[0])), file=sys.stderr) exit(1) parser = ConfigParser() parser.read(sys.argv[1]) config = parser['sync_app'] ankiserver = SyncApp(config) httpd = make_server(config['host'], int(config['port']), ankiserver) try: print("Serving HTTP on {} port {}...".format(*httpd.server_address)) httpd.serve_forever() except KeyboardInterrupt: print("Exiting...") finally: shutdown()