def _WriteCacheFile(self, cache_filename, scopes): """Writes the credential metadata to the cache file. This does not save the credentials themselves (CredentialStore class optionally handles that after this class is initialized). Args: cache_filename: Cache filename to check. scopes: Scopes for the desired credentials. """ if _EnsureFileExists(cache_filename): locked_file = oauth2client.locked_file.LockedFile( cache_filename, 'r+b', 'rb') try: locked_file.open_and_lock() if locked_file.is_locked(): creds = { # Credentials metadata dict. 'scopes': sorted(list(scopes)), 'svc_acct_name': self.__service_account_name } locked_file.file_handle().write( json.dumps(creds, encoding='ascii')) # If it's not locked, the locking process will write the same # data to the file, so just continue. finally: locked_file.unlock_and_close()
def _WriteCacheFile(self, cache_filename, scopes): """Writes the credential metadata to the cache file. This does not save the credentials themselves (CredentialStore class optionally handles that after this class is initialized). Args: cache_filename: Cache filename to check. scopes: Scopes for the desired credentials. """ if _EnsureFileExists(cache_filename): locked_file = oauth2client.locked_file.LockedFile( cache_filename, 'r+b', 'rb') try: locked_file.open_and_lock() if locked_file.is_locked(): creds = { # Credentials metadata dict. 'scopes': sorted(list(scopes)), 'svc_acct_name': self.__service_account_name} locked_file.file_handle().write( json.dumps(creds, encoding='ascii')) # If it's not locked, the locking process will # write the same data to the file, so just # continue. finally: locked_file.unlock_and_close()