本文整理匯總了Python中oauth2client.tools.run方法的典型用法代碼示例。如果您正苦於以下問題:Python tools.run方法的具體用法?Python tools.run怎麽用?Python tools.run使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類oauth2client.tools
的用法示例。
在下文中一共展示了tools.run方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: authenticate
# 需要導入模塊: from oauth2client import tools [as 別名]
# 或者: from oauth2client.tools import run [as 別名]
def authenticate(flow, storage=None):
"""
Try to retrieve a valid set of credentials from the token store if possible
Otherwise use the given authentication flow to obtain new credentials
and return an authenticated http object
Parameters
----------
flow : authentication workflow
storage: token storage, default None
"""
http = httplib2.Http()
# Prepare credentials, and authorize HTTP object with them.
credentials = storage.get()
if credentials is None or credentials.invalid:
credentials = tools.run(flow, storage)
http = credentials.authorize(http)
return http
示例2: run
# 需要導入模塊: from oauth2client import tools [as 別名]
# 或者: from oauth2client.tools import run [as 別名]
def run():
"""Provides feature for maintaining good eye-sight.
Provides notification to look 20 feet away for 20 seconds every 20 minutes.
"""
toaster = ToastNotifier()
time_seconds = 60
while True:
time.sleep(time_seconds-5)
speak.say("Please look 20 feet away for 20 seconds")
speak.runAndWait()
#Takes 5 seconds to execute
toaster.show_toast("Advice","Please look 20 feet away for 20 seconds")
time.sleep(5)
#Takes 5 seconds to execute
toaster.show_toast("Remaining Time", "10 seconds remaining")
time.sleep(5)
toaster.show_toast("Get Ready!", "Please carry your work!")
speak.say("Please carry your work!")
speak.runAndWait()
示例3: _Authenticate
# 需要導入模塊: from oauth2client import tools [as 別名]
# 或者: from oauth2client.tools import run [as 別名]
def _Authenticate(self, http, needs_auth):
"""Pre or Re-auth stuff...
This will attempt to avoid making any OAuth related HTTP connections or
user interactions unless it's needed.
Args:
http: An 'Http' object from httplib2.
needs_auth: If the user has already tried to contact the server.
If they have, it's OK to prompt them. If not, we should not be asking
them for auth info--it's possible it'll suceed w/o auth, but if we have
some credentials we'll use them anyway.
Raises:
AuthPermanentFail: The user has requested non-interactive auth but
the token is invalid.
"""
if needs_auth and (not self.credentials or self.credentials.invalid):
if self.refresh_token:
logger.debug('_Authenticate and skipping auth because user explicitly '
'supplied a refresh token.')
raise AuthPermanentFail('Refresh token is invalid.')
logger.debug('_Authenticate and requesting auth')
flow = client.OAuth2WebServerFlow(
client_id=self.client_id,
client_secret=self.client_secret,
scope=self.scope,
user_agent=self.user_agent)
self.credentials = tools.run(flow, self.storage)
if self.credentials and not self.credentials.invalid:
if not self.credentials.access_token_expired or needs_auth:
logger.debug('_Authenticate configuring auth; needs_auth=%s',
needs_auth)
self.credentials.authorize(http)
return
logger.debug('_Authenticate skipped auth; needs_auth=%s', needs_auth)
示例4: get_credentials
# 需要導入模塊: from oauth2client import tools [as 別名]
# 或者: from oauth2client.tools import run [as 別名]
def get_credentials():
"""Gets valid user credentials from storage.
If nothing has been stored, or if the stored credentials are invalid,
the OAuth2 flow is completed to obtain the new credentials.
Returns:
Credentials, the obtained credential.
"""
home_dir = os.path.expanduser('~')
credential_dir = os.path.join(home_dir, '.credentials')
if not os.path.exists(credential_dir):
os.makedirs(credential_dir)
credential_path = os.path.join(credential_dir,
'sheets.googleapis.com-python-quickstart.json')
store = Storage(credential_path)
credentials = store.get()
if not credentials or credentials.invalid:
flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES)
flow.user_agent = APPLICATION_NAME
if 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)
return credentials
示例5: get_credentials
# 需要導入模塊: from oauth2client import tools [as 別名]
# 或者: from oauth2client.tools import run [as 別名]
def get_credentials():
"""Gets valid user credentials from storage.
If nothing has been stored, or if the stored credentials are invalid,
the OAuth2 flow is completed to obtain the new credentials.
Returns:
Credentials, the obtained credential.
"""
home_dir = os.path.expanduser('~')
credential_dir = os.path.join(home_dir, '.credentials')
if not os.path.exists(credential_dir):
os.makedirs(credential_dir)
credential_path = os.path.join(credential_dir,
'calendar-python-quickstart.json')
store = Storage(credential_path)
credentials = store.get()
if not credentials or credentials.invalid:
flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES)
flow.user_agent = APPLICATION_NAME
if 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)
return credentials
示例6: get_credentials
# 需要導入模塊: from oauth2client import tools [as 別名]
# 或者: from oauth2client.tools import run [as 別名]
def get_credentials():
"""Gets valid user credentials from storage.
If nothing has been stored, or if the stored credentials are invalid,
the OAuth2 flow is completed to obtain the new credentials.
Returns:
Credentials, the obtained credential.
"""
home_dir = os.path.expanduser('~')
credential_dir = os.path.join(home_dir, '.credentials')
if not os.path.exists(credential_dir):
os.makedirs(credential_dir)
credential_path = os.path.join(credential_dir,
'gmail-python-quickstart.json')
store = oauth2client.file.Storage(credential_path)
credentials = store.get()
if not credentials or credentials.invalid:
flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES)
flow.user_agent = APPLICATION_NAME
if 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)
return credentials
示例7: get_authenticated_service
# 需要導入模塊: from oauth2client import tools [as 別名]
# 或者: from oauth2client.tools import run [as 別名]
def get_authenticated_service():
scope = "https://www.googleapis.com/auth/youtube.readonly"
storage = Storage("tokens/google.json")
credentials = storage.get()
if credentials is None or credentials.invalid:
flow = flow_from_clientsecrets("secrets/google_client_secrets.json",
scope=scope)
credentials = run(flow, storage)
return build("youtube", "v3", http=credentials.authorize(httplib2.Http()))
示例8: event
# 需要導入模塊: from oauth2client import tools [as 別名]
# 或者: from oauth2client.tools import run [as 別名]
def event():
try:
import argparse
flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args()
except ImportError:
flags = None
# If modifying these scopes, delete your previously saved credentials
# at ~/.credentials/calendar-python-quickstart.json
SCOPES = 'https://www.googleapis.com/auth/calendar'
store = file.Storage('storage.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
creds = tools.run_flow(flow, store, flags) \
if flags else tools.run(flow, store)
CAL = build('calendar', 'v3', http=creds.authorize(Http()))
SUBJECT = 'teste azul'
GMT_OFF = '-04:00'
EVENT = {
'summary' : SUBJECT,
'start' : {'dateTime': '2016-08-12T19:00:00%s' % GMT_OFF},
'end' : {'dateTime': '2016-08-12T22:00:00%s' % GMT_OFF},
'attendees': [
],
}
e = CAL.events().insert(calendarId='primary',
sendNotifications=True, body=EVENT).execute()
print('''*** %r event added:
Start: %s
End: %s''' % (e['summary'].encode('utf-8'),
e['start']['dateTime'], e['end']['dateTime']))
示例9: get_credentials
# 需要導入模塊: from oauth2client import tools [as 別名]
# 或者: from oauth2client.tools import run [as 別名]
def get_credentials():
"""Gets valid user credentials from storage.
If nothing has been stored, or if the stored credentials are invalid,
the OAuth2 flow is completed to obtain the new credentials.
Returns:
Credentials, the obtained credential.
"""
home_dir = os.path.expanduser('~')
credential_dir = os.path.join(home_dir, '.credentials')
if not os.path.exists(credential_dir):
os.makedirs(credential_dir)
credential_path = os.path.join(credential_dir,
'calendar-python-quickstart.json')
store = oauth2client.file.Storage(credential_path)
credentials = store.get()
if not credentials or credentials.invalid:
flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES)
flow.user_agent = APPLICATION_NAME
if 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)
return credentials
示例10: get_credentials
# 需要導入模塊: from oauth2client import tools [as 別名]
# 或者: from oauth2client.tools import run [as 別名]
def get_credentials():
home_dir = os.path.expanduser('~')
credential_dir = os.path.join(home_dir, '.credentials')
if not os.path.exists(credential_dir):
os.makedirs(credential_dir)
credential_path = os.path.join(credential_dir, 'gmail-python-quickstart.json')
store = Storage(credential_path)
credentials = store.get()
if not credentials or credentials.invalid:
flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES)
flow.user_agent = APPLICATION_NAME
credentials = tools.run(flow, store)
print('Storing credentials to ' + credential_path)
return credentials
示例11: get_credentials
# 需要導入模塊: from oauth2client import tools [as 別名]
# 或者: from oauth2client.tools import run [as 別名]
def get_credentials():
"""Gets valid user credentials from storage.
If nothing has been stored, or if the stored credentials are invalid,
the OAuth2 flow is completed to obtain the new credentials.
Returns:
Credentials, the obtained credential.
"""
home_dir = os.path.expanduser('~')
credential_dir = os.path.join(home_dir, '.credentials')
if not os.path.exists(credential_dir):
os.makedirs(credential_dir)
credential_path = os.path.join(credential_dir,
'calendar-python-quickstart.json')
store = oauth2client.file.Storage(credential_path)
credentials = store.get()
if not credentials or credentials.invalid:
flow = client.flow_from_clientsecrets(SECRET, SCOPES)
flow.user_agent = APPLICATION_NAME
if flags:
credentials = tools.run_flow(flow, store, flags)
else: # Needed only for compatability with Python 2.6
credentials = tools.run(flow, store)
print('Storing credentials to ' + credential_path)
return credentials
示例12: get_credentials
# 需要導入模塊: from oauth2client import tools [as 別名]
# 或者: from oauth2client.tools import run [as 別名]
def get_credentials():
"""Gets valid user credentials from storage.
If nothing has been stored, or if the stored credentials are invalid,
the OAuth2 flow is completed to obtain the new credentials.
Returns:
Credentials, the obtained credential.
"""
home_dir = os.path.expanduser('~')
credential_dir = os.path.join(home_dir, '.credentials')
if not os.path.exists(credential_dir):
os.makedirs(credential_dir)
credential_path = os.path.join(credential_dir,
'sheets.googleapis.com-singer-target.json')
store = Storage(credential_path)
credentials = store.get()
if not credentials or credentials.invalid:
flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES)
flow.user_agent = APPLICATION_NAME
if 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)
return credentials
示例13: get_credentials
# 需要導入模塊: from oauth2client import tools [as 別名]
# 或者: from oauth2client.tools import run [as 別名]
def get_credentials():
"""Gets valid user credentials from storage.
If nothing has been stored, or if the stored credentials are invalid,
the OAuth2 flow is completed to obtain the new credentials.
Returns:
Credentials, the obtained credential.
"""
home_dir = os.path.expanduser('~')
credential_dir = os.path.join(home_dir, '.credentials')
if not os.path.exists(credential_dir):
os.makedirs(credential_dir)
credential_path = os.path.join(credential_dir,
'drive-python-quickstart.json')
store = Storage(credential_path)
credentials = store.get()
if not credentials or credentials.invalid:
flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES)
flow.user_agent = APPLICATION_NAME
if 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)
return credentials
開發者ID:Github-Classroom-Cybros,項目名稱:Lecture-Series-Python,代碼行數:29,代碼來源:archive_deployment_packages.py
示例14: mv
# 需要導入模塊: from oauth2client import tools [as 別名]
# 或者: from oauth2client.tools import run [as 別名]
def mv(source, destination):
return subprocess.run(['../.bin/mv', source, destination])
示例15: zip
# 需要導入模塊: from oauth2client import tools [as 別名]
# 或者: from oauth2client.tools import run [as 別名]
def zip(source, destination):
return subprocess.run(['../.bin/7za', 'a', '-tzip', destination, source])