Ejemplo n.º 1
0
    async def create_folder(self, path: wb_path.WaterButlerPath, folder_precheck: bool=True,
                            **kwargs) -> BoxFolderMetadata:
        wb_path.WaterButlerPath.validate_folder(path)

        if folder_precheck:
            if path.identifier is not None:
                raise exceptions.FolderNamingConflict(path.name)

        async with self.request(
            'POST',
            self.build_url('folders'),
            data={
                'name': path.name,
                'parent': {
                    'id': path.parent.identifier
                }
            },
            expects=(201, 409),
            throws=exceptions.CreateFolderError,
        ) as resp:
            # Catch 409s to avoid race conditions
            if resp.status == 409:
                raise exceptions.FolderNamingConflict(path.name)
            resp_json = await resp.json()
        # save new folder's id into the WaterButlerPath object. logs will need it later.
        path._parts[-1]._id = resp_json['id']
        return BoxFolderMetadata(resp_json, path)
Ejemplo n.º 2
0
    def create_folder(self, path, **kwargs):
        WaterButlerPath.validate_folder(path)

        if path.identifier is not None:
            raise exceptions.FolderNamingConflict(str(path))

        resp = yield from self.make_request(
            'POST',
            self.build_url('folders'),
            data={
                'name': path.name,
                'parent': {
                    'id': path.parent.identifier
                }
            },
            expects=(201, 409),
            throws=exceptions.CreateFolderError,
        )

        # Catch 409s to avoid race conditions
        if resp.status == 409:
            raise exceptions.FolderNamingConflict(str(path))

        resp_json = yield from resp.json()
        # save new folder's id into the WaterButlerPath object. logs will need it later.
        path._parts[-1]._id = resp_json['id']
        return BoxFolderMetadata(resp_json, path)
Ejemplo n.º 3
0
    async def create_folder(self, path, **kwargs):
        """
        :param str path: The path to create a folder at
        """
        WaterButlerPath.validate_folder(path)

        response = await self.make_request(
            'POST',
            self.build_url('fileops', 'create_folder'),
            params={
                'root': 'auto',
                'path': path.full_path
            },
            expects=(200, 403),
            throws=exceptions.CreateFolderError
        )

        data = await response.json()

        if response.status == 403:
            if 'because a file or folder already exists at path' in data.get('error'):
                raise exceptions.FolderNamingConflict(str(path))
            raise exceptions.CreateFolderError(data, code=403)

        return DropboxFolderMetadata(data, self.folder)
Ejemplo n.º 4
0
    def create_folder(self, path, **kwargs):
        GoogleDrivePath.validate_folder(path)

        if path.identifier:
            raise exceptions.FolderNamingConflict(str(path))

        resp = yield from self.make_request(
            'POST',
            self.build_url('files'),
            headers={
                'Content-Type': 'application/json',
            },
            data=json.dumps({
                'title': path.name,
                'parents': [{
                    'id': path.parent.identifier
                }],
                'mimeType': 'application/vnd.google-apps.folder'
            }),
            expects=(200, ),
            throws=exceptions.CreateFolderError,
        )

        return GoogleDriveFolderMetadata((yield from resp.json()),
                                         path).serialized()
Ejemplo n.º 5
0
    async def create_folder(self,
                            path: wb_path.WaterButlerPath,
                            folder_precheck: bool=True,
                            **kwargs) -> GoogleDriveFolderMetadata:
        GoogleDrivePath.validate_folder(path)

        if folder_precheck:
            if path.identifier:
                raise exceptions.FolderNamingConflict(path.name)

        async with self.request(
            'POST',
            self.build_url('files'),
            headers={
                'Content-Type': 'application/json',
            },
            data=json.dumps({
                'title': path.name,
                'parents': [{
                    'id': path.parent.identifier
                }],
                'mimeType': self.FOLDER_MIME_TYPE,
            }),
            expects=(200, ),
            throws=exceptions.CreateFolderError,
        ) as resp:
            return GoogleDriveFolderMetadata(await resp.json(), path)
Ejemplo n.º 6
0
    def create_folder(self, path, **kwargs):
        WaterButlerPath.validate_folder(path)

        if path.identifier is not None:
            raise exceptions.FolderNamingConflict(str(path))

        resp = yield from self.make_request(
            'POST',
            self.build_url('folders'),
            data={
                'name': path.name,
                'parent': {
                    'id': path.parent.identifier
                }
            },
            expects=(201, 409),
            throws=exceptions.CreateFolderError,
        )

        # Catch 409s to avoid race conditions
        if resp.status == 409:
            raise exceptions.FolderNamingConflict(str(path))

        return BoxFolderMetadata((yield from resp.json()), path)
Ejemplo n.º 7
0
    def create_folder(self, path, **kwargs):
        """
        :param str path: The path to create a folder at
        """
        WaterButlerPath.validate_folder(path)

        if (yield from self.exists(path)):
            raise exceptions.FolderNamingConflict(str(path))

        yield from self.make_request(
            'PUT',
            self.bucket.new_key(path.path).generate_url(settings.TEMP_URL_SECS, 'PUT'),
            expects=(200, 201),
            throws=exceptions.CreateFolderError
        )

        return S3FolderMetadata({'Prefix': path.path})
Ejemplo n.º 8
0
    async def create_folder(self, path, folder_precheck=True, **kwargs):
        """
        :param str path: The path to create a folder at
        """
        await self._check_region()

        WaterButlerPath.validate_folder(path)

        if folder_precheck:
            if (await self.exists(path)):
                raise exceptions.FolderNamingConflict(str(path))

        async with self.request(
            'PUT',
            functools.partial(self.bucket.new_key(path.path).generate_url, settings.TEMP_URL_SECS, 'PUT'),
            skip_auto_headers={'CONTENT-TYPE'},
            expects=(200, 201),
            throws=exceptions.CreateFolderError
        ):
            return S3FolderMetadata({'Prefix': path.path})
Ejemplo n.º 9
0
    async def create_folder(self, path, **kwargs):
        """Create a folder in the current provider at ``path``. Returns an
        `.metadata.OwnCloudFolderMetadata` object if successful.

        :param waterbutler.core.path.WaterButlerPath path: user-supplied directory path to create
        :param boolean precheck_folder: flag to check for folder before attempting create
        :rtype: `.metadata.OwnCloudFolderMetadata`
        :raises: `waterbutler.core.exceptions.CreateFolderError`
        """
        resp = await self.make_request('MKCOL',
                                       self._webdav_url_ + path.full_path,
                                       expects=(201, 405),
                                       throws=exceptions.CreateFolderError,
                                       auth=self._auth,
                                       connector=self.connector())
        await resp.release()
        if resp.status == 405:
            raise exceptions.FolderNamingConflict(path.name)
        # get the folder metadata
        meta = await self.metadata(path.parent)
        return [m for m in meta if m.path == path.materialized_path][0]
Ejemplo n.º 10
0
    async def create_folder(self, path, branch=None, message=None, **kwargs):
        GitHubPath.validate_folder(path)

        assert self.name is not None
        assert self.email is not None
        message = message or settings.UPLOAD_FILE_MESSAGE

        keep_path = path.child('.gitkeep')

        data = {
            'content': '',
            'path': keep_path.path,
            'committer': self.committer,
            'branch': path.branch_ref,
            'message': message or settings.UPLOAD_FILE_MESSAGE
        }

        resp = await self.make_request('PUT',
                                       self.build_repo_url(
                                           'contents', keep_path.path),
                                       data=json.dumps(data),
                                       expects=(201, 422, 409),
                                       throws=exceptions.CreateFolderError)

        data = await resp.json()

        if resp.status in (422, 409):
            if resp.status == 409 or data.get(
                    'message'
            ) == 'Invalid request.\n\n"sha" wasn\'t supplied.':
                raise exceptions.FolderNamingConflict(str(path))
            raise exceptions.CreateFolderError(data, code=resp.status)

        data['content']['name'] = path.name
        data['content']['path'] = data['content']['path'].replace(
            '.gitkeep', '')

        return GitHubFolderContentMetadata(data['content'],
                                           commit=data['commit'],
                                           ref=path.branch_ref)