def run():
args = parse_args()<EOL>appname = sys.argv[<NUM_LIT:0>]<EOL>hostname = platform.node()<EOL>codetools.setup_logging(args.debug)<EOL>password = '<STR_LIT>'<EOL>if args.token_path is None and args.delete_role is True:<EOL><INDENT>cred_path = os.path.expanduser('<STR_LIT>')<EOL><DEDENT>elif args.token_path is None and args.delete_role is False:<EOL><INDENT>cred_path = os.path.expanduser('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>cred_path = os.path.expandvars(os.path.expanduser(args.token_path))<EOL><DEDENT>if not os.path.isfile(cred_path):<EOL><INDENT>print("""<STR_LIT>""".format(cred_path))<EOL>while not password:<EOL><INDENT>password = getpass('<STR_LIT>'.format(args.user))<EOL><DEDENT>note = textwrap.dedent("""<STR_LIT>""").format(<EOL>app=appname,<EOL>host=hostname,<EOL>user=args.user,<EOL>creds=cred_path<EOL>)<EOL>note_url = '<STR_LIT>'<EOL>if args.delete_role:<EOL><INDENT>scopes = ['<STR_LIT>', '<STR_LIT:user>', '<STR_LIT>', '<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>scopes = ['<STR_LIT>', '<STR_LIT:user>']<EOL><DEDENT>global g<EOL>g = github.Github(args.user, password)<EOL>u = g.get_user()<EOL>try:<EOL><INDENT>auth = u.create_authorization(<EOL>scopes=scopes,<EOL>note=note,<EOL>note_url=note_url,<EOL>)<EOL><DEDENT>except github.TwoFactorException:<EOL><INDENT>auth = u.create_authorization(<EOL>scopes=scopes,<EOL>note=note,<EOL>note_url=note_url,<EOL>onetime_password=codetools.github_2fa_callback()<EOL>)<EOL><DEDENT>g = github.Github(auth.token)<EOL>with open(cred_path, '<STR_LIT:w>') as fdo:<EOL><INDENT>fdo.write(auth.token + '<STR_LIT:\n>')<EOL>fdo.write(str(auth.id))<EOL><DEDENT>print('<STR_LIT>'.format(cred_path))<EOL><DEDENT>else:<EOL><INDENT>print("<STR_LIT>".format(cred_path))<EOL>print("<STR_LIT>")<EOL>print("<STR_LIT>")<EOL><DEDENT>
Log in and store credentials