Ejemplo n.º 1
0
 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)
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
0
 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)
Ejemplo n.º 4
0
 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)
Ejemplo n.º 5
0
    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)
Ejemplo n.º 6
0
    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)
Ejemplo n.º 7
0
    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)
Ejemplo n.º 8
0
    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)