comparison multimerge.py @ 99:4b84bb5bb8b5

Make credential_file and secret_file arguments to gcm_get_credentials().
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 10 Oct 2016 13:07:24 +0300
parents fe3bfabf0b5f
children b4058d935560
comparison
equal deleted inserted replaced
98:fe3bfabf0b5f 99:4b84bb5bb8b5
100 gcm_print(u"\nQuitting due to SIGINT / Ctrl+C!") 100 gcm_print(u"\nQuitting due to SIGINT / Ctrl+C!")
101 sys.exit(0) 101 sys.exit(0)
102 102
103 103
104 ## Function for handling Google API credentials 104 ## Function for handling Google API credentials
105 def gcm_get_credentials(mcfg): 105 def gcm_get_credentials(mcfg, credential_file, secret_file):
106 try: 106 try:
107 store = oauth2client.file.Storage(mcfg.credential_file) 107 store = oauth2client.file.Storage(credential_file)
108 except Exception as e: 108 except Exception as e:
109 gcm_fatal(u"Failed to read credential file:\n{0}\n\nERROR: {1}\n".format(mcfg.credential_file, str(e))) 109 gcm_fatal(u"Failed to read credential file:\n{0}\n\nERROR: {1}\n".format(credential_file, str(e)))
110 110
111 credentials = store.get() 111 credentials = store.get()
112 if not credentials or credentials.invalid: 112 if not credentials or credentials.invalid:
113 try: 113 try:
114 flow = client.flow_from_clientsecrets(mcfg.secret_file, mcfg.scope) 114 flow = client.flow_from_clientsecrets(secret_file, mcfg.scope)
115 except Exception as e: 115 except Exception as e:
116 gcm_fatal(u"Failed to fetch client secret:\n{0}\n\nERROR: {1}\n".format(mcfg.secret_file, str(e))) 116 gcm_fatal(u"Failed to fetch client secret:\n{0}\n\nERROR: {1}\n".format(secret_file, str(e)))
117 117
118 flow.user_agent = mcfg.app_name 118 flow.user_agent = mcfg.app_name
119 credentials = tools.run_flow(flow, store, mcfg) 119 credentials = tools.run_flow(flow, store, mcfg)
120 if not credentials or credentials.invalid: 120 if not credentials or credentials.invalid:
121 gcm_fatal(u"Failed to authenticate / invalid credentials.") 121 gcm_fatal(u"Failed to authenticate / invalid credentials.")
439 if not cfg.dst_regex and not cfg.dst_id: 439 if not cfg.dst_regex and not cfg.dst_id:
440 gcm_fatal(u"Target calendar ID or name required, but not set.") 440 gcm_fatal(u"Target calendar ID or name required, but not set.")
441 441
442 442
443 ## Initialize and authorize API connection 443 ## Initialize and authorize API connection
444 credentials = gcm_get_credentials(cfg) 444 credentials = gcm_get_credentials(cfg, cfg.credential_file, cfg.secret_file)
445 http = credentials.authorize(httplib2.Http()) 445 http = credentials.authorize(httplib2.Http())
446 service = discovery.build("calendar", "v3", http=http) 446 service = discovery.build("calendar", "v3", http=http)
447 447
448 448
449 ## Fetch complete calendar list 449 ## Fetch complete calendar list