def configure(args, parser):
if not args.force and on_travis():<EOL><INDENT>parser.error(red("<STR_LIT>"<EOL>"<STR_LIT>"))<EOL><DEDENT>if not args.authenticate:<EOL><INDENT>args.upload_key = False<EOL><DEDENT>if args.travis_tld:<EOL><INDENT>if args.travis_tld in ['<STR_LIT:c>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>args.travis_tld = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>args.travis_tld = '<STR_LIT>'<EOL><DEDENT><DEDENT>print(green(dedent("""<STR_LIT>""")))<EOL>login_kwargs = {}<EOL>if args.authenticate:<EOL><INDENT>while not login_kwargs:<EOL><INDENT>try:<EOL><INDENT>login_kwargs = GitHub_login()<EOL><DEDENT>except AuthenticationFailed as e:<EOL><INDENT>print(red(e))<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>login_kwargs = {'<STR_LIT>': None, '<STR_LIT>': None}<EOL><DEDENT>GitHub_token = None<EOL>get_build_repo = False<EOL>default_repo = guess_github_repo()<EOL>while not get_build_repo:<EOL><INDENT>try:<EOL><INDENT>if default_repo:<EOL><INDENT>build_repo = input("<STR_LIT>".format(default_repo=blue(default_repo)))<EOL>if not build_repo:<EOL><INDENT>build_repo = default_repo<EOL><DEDENT><DEDENT>else:<EOL><INDENT>build_repo = input("<STR_LIT>")<EOL><DEDENT>is_private = check_repo_exists(build_repo, service='<STR_LIT>',<EOL>**login_kwargs)['<STR_LIT>']<EOL>if is_private and not args.authenticate:<EOL><INDENT>sys.exit(red("<STR_LIT>"))<EOL><DEDENT>headers = {}<EOL>travis_token = None<EOL>if is_private:<EOL><INDENT>if args.token:<EOL><INDENT>GitHub_token = generate_GitHub_token(note="<STR_LIT>".format(build_repo=build_repo),<EOL>scopes=["<STR_LIT>", "<STR_LIT>", "<STR_LIT>"], **login_kwargs)['<STR_LIT>']<EOL><DEDENT>travis_token = get_travis_token(GitHub_token=GitHub_token, **login_kwargs)<EOL>headers['<STR_LIT>'] = "<STR_LIT>".format(travis_token)<EOL><DEDENT>service = args.travis_tld if args.travis_tld else '<STR_LIT>'<EOL>c = check_repo_exists(build_repo, service=service, ask=True, headers=headers)<EOL>tld = c['<STR_LIT>'][-<NUM_LIT:4>:]<EOL>is_private = c['<STR_LIT>'] or is_private<EOL>if is_private and not args.authenticate:<EOL><INDENT>sys.exit(red("<STR_LIT>"))<EOL><DEDENT>get_build_repo = True<EOL><DEDENT>except GitHubError:<EOL><INDENT>raise<EOL><DEDENT>except RuntimeError as e:<EOL><INDENT>print(red('<STR_LIT>'.format(e, <NUM_LIT>)))<EOL><DEDENT><DEDENT>get_deploy_repo = False<EOL>while not get_deploy_repo:<EOL><INDENT>try:<EOL><INDENT>deploy_repo = input("<STR_LIT>".format(build_repo=blue(build_repo)))<EOL>if not deploy_repo:<EOL><INDENT>deploy_repo = build_repo<EOL><DEDENT>if deploy_repo != build_repo:<EOL><INDENT>check_repo_exists(deploy_repo, service='<STR_LIT>', **login_kwargs)<EOL><DEDENT>get_deploy_repo = True<EOL><DEDENT>except GitHubError:<EOL><INDENT>raise<EOL><DEDENT>except RuntimeError as e:<EOL><INDENT>print(red('<STR_LIT>'.format(e, <NUM_LIT>)))<EOL><DEDENT><DEDENT>N = IncrementingInt(<NUM_LIT:1>)<EOL>header = green("<STR_LIT>")<EOL>if args.token:<EOL><INDENT>if not GitHub_token:<EOL><INDENT>GitHub_token = generate_GitHub_token(**login_kwargs)['<STR_LIT>']<EOL><DEDENT>encrypted_variable = encrypt_variable("<STR_LIT>".format(GitHub_token=GitHub_token).encode('<STR_LIT:utf-8>'),<EOL>build_repo=build_repo, tld=tld, travis_token=travis_token, **login_kwargs)<EOL>print(dedent("""<STR_LIT>"""))<EOL>print(header)<EOL><DEDENT>else:<EOL><INDENT>deploy_key_repo, env_name, keypath = get_deploy_key_repo(deploy_repo, args.key_path)<EOL>private_ssh_key, public_ssh_key = generate_ssh_key()<EOL>key = encrypt_to_file(private_ssh_key, keypath + '<STR_LIT>')<EOL>del private_ssh_key <EOL>public_ssh_key = public_ssh_key.decode('<STR_LIT>')<EOL>encrypted_variable = encrypt_variable(env_name.encode('<STR_LIT:utf-8>') + b"<STR_LIT:=>" + key,<EOL>build_repo=build_repo, tld=tld, travis_token=travis_token, **login_kwargs)<EOL>deploy_keys_url = '<STR_LIT>'.format(deploy_repo=deploy_key_repo)<EOL>if args.upload_key:<EOL><INDENT>upload_GitHub_deploy_key(deploy_key_repo, public_ssh_key, **login_kwargs)<EOL>print(dedent("""<STR_LIT>""".format(deploy_repo=deploy_key_repo, deploy_keys_url=deploy_keys_url, keypath=keypath)))<EOL>print(header)<EOL><DEDENT>else:<EOL><INDENT>print(header)<EOL>print(dedent("""<STR_LIT>""".format(ssh_key=public_ssh_key, deploy_keys_url=deploy_keys_url, N=N,<EOL>BOLD_MAGENTA=BOLD_MAGENTA, RESET=RESET)))<EOL><DEDENT>print(dedent("""<STR_LIT>""".format(keypath=keypath, N=N, BOLD_MAGENTA=BOLD_MAGENTA, RESET=RESET)))<EOL><DEDENT>options = '<STR_LIT>' + bold_black('<STR_LIT>')<EOL>if args.key_path:<EOL><INDENT>options += '<STR_LIT>'.format(keypath=keypath)<EOL><DEDENT>if deploy_repo != build_repo:<EOL><INDENT>options += '<STR_LIT>'.format(deploy_repo=deploy_repo)<EOL><DEDENT>key_type = "<STR_LIT>"<EOL>if args.token:<EOL><INDENT>options += '<STR_LIT>'<EOL>key_type = "<STR_LIT>"<EOL><DEDENT>print(dedent("""<STR_LIT>""".format(options=options, N=N, key_type=key_type,<EOL>encrypted_variable=encrypted_variable.decode('<STR_LIT:utf-8>'),<EOL>deploy_repo=deploy_repo, BOLD_MAGENTA=BOLD_MAGENTA,<EOL>BOLD_BLACK=BOLD_BLACK, RESET=RESET)))<EOL>print(dedent("""<STR_LIT>""".format(BOLD_BLACK=BOLD_BLACK, RESET=RESET)))<EOL>print(dedent("""<STR_LIT>"""))<EOL>print(dedent("""<STR_LIT>""".format(N=N, BOLD_MAGENTA=BOLD_MAGENTA, RESET=RESET)))<EOL>print("<STR_LIT>")<EOL>
Color guide

- red: Error and warning messages
- green: Welcome messages (use sparingly)
- blue: Default values
- bold_magenta: Action items
- bold_black: Parts of code to be run or copied that should be modified