get-google-credentials: Remove Python 2 compatibility.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2023-10-25 16:19:32 -07:00
parent f55d5ea555
commit 40fba154c2

View file

@ -1,18 +1,11 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import argparse
import os import os
from typing import Optional
from oauth2client import client, tools from oauth2client import client, tools
from oauth2client.file import Storage from oauth2client.file import Storage
try: flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args()
import argparse
flags: Optional[argparse.Namespace] = argparse.ArgumentParser(
parents=[tools.argparser]
).parse_args()
except ImportError:
flags = None
# If modifying these scopes, delete your previously saved credentials # If modifying these scopes, delete your previously saved credentials
# at zulip/bots/gcal/ # at zulip/bots/gcal/
@ -43,13 +36,10 @@ def get_credentials() -> client.Credentials:
if not credentials or credentials.invalid: if not credentials or credentials.invalid:
flow = client.flow_from_clientsecrets(os.path.join(HOME_DIR, CLIENT_SECRET_FILE), SCOPES) flow = client.flow_from_clientsecrets(os.path.join(HOME_DIR, CLIENT_SECRET_FILE), SCOPES)
flow.user_agent = APPLICATION_NAME flow.user_agent = APPLICATION_NAME
if flags:
# This attempts to open an authorization page in the default web browser, and asks the user # This attempts to open an authorization page in the default web browser, and asks the user
# to grant the bot access to their data. If the user grants permission, the run_flow() # to grant the bot access to their data. If the user grants permission, the run_flow()
# function returns new credentials. # function returns new credentials.
credentials = tools.run_flow(flow, store, flags) credentials = tools.run_flow(flow, store, flags)
else: # Needed only for compatibility with Python 2.6
credentials = tools.run(flow, store)
print("Storing credentials to " + credential_path) print("Storing credentials to " + credential_path)