def _get_file_meta(self, file_id): """Returns the raw un-wrapped metadata""" try: return self._drive_client.files().get(fileId=file_id).execute() except apiclient_errors.Error as error: # pylint: disable=protected-access raise errors._WrappedError(error) # pylint: enable=protected-access except urlfetch_errors.DeadlineExceededError as error: raise errors.TimeoutError(error)
def from_service_account_secrets(cls, email, key, scope=_ALL_SCOPES): try: credentials = oauth2client.client.SignedJwtAssertionCredentials( email, key, scope) http_auth = credentials.authorize(httplib2.Http()) api = discovery.build('drive', 'v2', http=http_auth) except Exception as error: # pylint: disable=protected-access raise errors._WrappedError(error) # pylint: enable=protected-access return cls(api)
def list_file_meta(self, max_results=100, page_token=None): """Returns a DriveItemList""" # TODO(nretallack): It's possible that this could time out. # Stress-test and tune the max_results number. try: return DriveItemList.from_api_list(self._drive_client.files().list( maxResults=max_results, pageToken=page_token, ).execute()) except apiclient_errors.Error as error: # pylint: disable=protected-access raise errors._WrappedError(error) # pylint: enable=protected-access except urlfetch_errors.DeadlineExceededError as error: raise errors.TimeoutError(error)
def share_file(self, file_id, email): """Share a file to an email address""" # pylint: disable=protected-access body = { "name": "cb-reader", "kind": "drive#permission", "value": email, "type": "user", "role": "reader", } try: self._drive_client.permissions().insert(fileId=file_id, body=body).execute() except apiclient_errors.Error as error: if is_sharing_permission_error(error): raise errors.SharingPermissionError(error) else: raise errors._WrappedError(error)
def share_file(self, file_id, email): """Share a file to an email address""" # pylint: disable=protected-access body = { "name": "cb-reader", "kind": "drive#permission", "value": email, "type": "user", "role": "reader", } try: self._drive_client.permissions().insert(fileId=file_id, body=body ).execute() except apiclient_errors.Error as error: if is_sharing_permission_error(error): raise errors.SharingPermissionError(error) else: raise errors._WrappedError(error)