def main():
my_name = os.path.basename(sys.argv[<NUM_LIT:0>])<EOL>if not my_name:<EOL><INDENT>my_name = "<STR_LIT>"<EOL><DEDENT>syslog.openlog(my_name, syslog.LOG_PID, syslog.LOG_LOCAL0)<EOL>args = parse_args()<EOL>args_fixup(args)<EOL>aead_backend = None<EOL>if args.db_url:<EOL><INDENT>try:<EOL><INDENT>aead_backend = SQLBackend(args.db_url, args.key_handles)<EOL><DEDENT>except Exception as e:<EOL><INDENT>my_log_message(args.debug or args.verbose, syslog.LOG_ERR,<EOL>'<STR_LIT>' % (args.db_url, e))<EOL>return <NUM_LIT:1><EOL><DEDENT><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>aead_backend = FSBackend(args.aead_dir, args.key_handles)<EOL><DEDENT>except Exception as e:<EOL><INDENT>my_log_message(args.debug or args.verbose, syslog.LOG_ERR,<EOL>'<STR_LIT>' % e)<EOL>return <NUM_LIT:1><EOL><DEDENT><DEDENT>if args.device == '<STR_LIT:->':<EOL><INDENT>try:<EOL><INDENT>hsm = SoftYHSM.from_json(sys.stdin.read(), debug=args.debug)<EOL><DEDENT>except ValueError as e:<EOL><INDENT>my_log_message(args.debug or args.verbose, syslog.LOG_ERR,<EOL>'<STR_LIT>' % (e))<EOL>return <NUM_LIT:1><EOL><DEDENT><DEDENT>elif os.path.isfile(args.device):<EOL><INDENT>try:<EOL><INDENT>hsm = SoftYHSM.from_file(args.device, debug=args.debug)<EOL><DEDENT>except ValueError as e:<EOL><INDENT>my_log_message(args.debug or args.verbose, syslog.LOG_ERR,<EOL>'<STR_LIT>' % (args.device, e))<EOL>return <NUM_LIT:1><EOL><DEDENT><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>hsm = pyhsm.YHSM(device=args.device, debug=args.debug)<EOL>context.files_preserve = [hsm.get_raw_device()]<EOL><DEDENT>except serial.SerialException as e:<EOL><INDENT>my_log_message(args.debug or args.verbose, syslog.LOG_ERR,<EOL>'<STR_LIT>' % (args.device, e))<EOL>return <NUM_LIT:1><EOL><DEDENT><DEDENT>if args.daemon:<EOL><INDENT>with context:<EOL><INDENT>run(hsm, aead_backend, args)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>run(hsm, aead_backend, args)<EOL><DEDENT>except KeyboardInterrupt:<EOL><INDENT>print("<STR_LIT>")<EOL>print("<STR_LIT>")<EOL>print("<STR_LIT>")<EOL><DEDENT><DEDENT>
Main program.