(args)
| 339 | return len(quotes) |
| 340 | |
| 341 | def run(args): |
| 342 | schema = None |
| 343 | secret = None |
| 344 | |
| 345 | if args.login_token: |
| 346 | """Use token to login""" |
| 347 | schema = 'token' |
| 348 | secret = args.login_token.encode('ascii') |
| 349 | log("Logging in with token", args.login_token) |
| 350 | |
| 351 | elif args.login_basic: |
| 352 | """Use username:password""" |
| 353 | schema = 'basic' |
| 354 | secret = args.login_basic.encode('utf-8') |
| 355 | log("Logging in with login:password", args.login_basic) |
| 356 | |
| 357 | else: |
| 358 | """Try reading the cookie file""" |
| 359 | try: |
| 360 | schema, secret = read_auth_cookie(args.login_cookie) |
| 361 | log("Logging in with cookie file", args.login_cookie) |
| 362 | except Exception as err: |
| 363 | log("Failed to read authentication cookie", err) |
| 364 | |
| 365 | if schema: |
| 366 | # Load random quotes from file |
| 367 | log("Loaded {} quotes".format(load_quotes(args.quotes))) |
| 368 | |
| 369 | # Start Plugin server |
| 370 | server = init_server(args.listen) |
| 371 | |
| 372 | # Initialize and launch client |
| 373 | client = init_client(args.host, schema, secret, args.login_cookie, args.ssl, args.ssl_host) |
| 374 | |
| 375 | # Setup closure for graceful termination |
| 376 | def exit_gracefully(signo, stack_frame): |
| 377 | log("Terminated with signal", signo) |
| 378 | server.stop(0) |
| 379 | client.cancel() |
| 380 | sys.exit(0) |
| 381 | |
| 382 | # Add signal handlers |
| 383 | signal.signal(signal.SIGINT, exit_gracefully) |
| 384 | signal.signal(signal.SIGTERM, exit_gracefully) |
| 385 | |
| 386 | # Run blocking message loop in a cycle to handle |
| 387 | # server being down. |
| 388 | while True: |
| 389 | client_message_loop(client) |
| 390 | time.sleep(3) |
| 391 | client_reset() |
| 392 | client = init_client(args.host, schema, secret, args.login_cookie, args.ssl, args.ssl_host) |
| 393 | |
| 394 | # Close connections gracefully before exiting |
| 395 | server.stop(None) |
| 396 | client.cancel() |
| 397 | |
| 398 | else: |
no test coverage detected