comparison multimerge.py @ 42:ac949d2b268a

Add some error handling.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 05 Jul 2016 14:15:57 +0300
parents 9eadb97a2e98
children a331209e24fc
comparison
equal deleted inserted replaced
41:9eadb97a2e98 42:ac949d2b268a
75 sys.exit(0) 75 sys.exit(0)
76 76
77 77
78 ## Function for handling Google API credentials 78 ## Function for handling Google API credentials
79 def gcm_get_credentials(mcfg): 79 def gcm_get_credentials(mcfg):
80 store = oauth2client.file.Storage(mcfg.credential_file) 80 try:
81 store = oauth2client.file.Storage(mcfg.credential_file)
82 except Exception as e:
83 gcm_fatal("Failed to read credential file:\n{0}\n\nERROR: {1}\n".format(mcfg.credential_file, str(e)))
84
81 credentials = store.get() 85 credentials = store.get()
82 if not credentials or credentials.invalid: 86 if not credentials or credentials.invalid:
83 flow = client.flow_from_clientsecrets(mcfg.secret_file, mcfg.scope) 87 try:
88 flow = client.flow_from_clientsecrets(mcfg.secret_file, mcfg.scope)
89 except Exception as e:
90 gcm_fatal("Failed to fetch client secret:\n{0}\n\nERROR: {1}\n".format(mcfg.secret_file, str(e)))
91
84 flow.user_agent = mcfg.app_name 92 flow.user_agent = mcfg.app_name
85 credentials = tools.run_flow(flow, store, mcfg) 93 credentials = tools.run_flow(flow, store, mcfg)
86 if not credentials or credentials.invalid: 94 if not credentials or credentials.invalid:
87 gcm_fatal("Failed to authenticate / invalid credentials.") 95 gcm_fatal("Failed to authenticate / invalid credentials.")
88 return credentials 96 return credentials