Beispiel #1
0
    def validate_folder(cls, path):
        if not path.is_dir:
            raise exceptions.CreateFolderError('Path must be a directory',
                                               code=400)

        if path.is_root:
            raise exceptions.CreateFolderError('Path can not be root',
                                               code=400)
Beispiel #2
0
    def validate_folder(self):
        """Raise CreateFolderErrors if the folder path is invalid
        :returns: None
        :raises: waterbutler.CreateFolderError
        """
        if not self.is_dir:
            raise exceptions.CreateFolderError('Path must be a directory',
                                               code=400)

        if self.path == '/':
            raise exceptions.CreateFolderError('Path can not be root',
                                               code=400)
Beispiel #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)
Beispiel #4
0
    async def create_folder(self, path, **kwargs):
        """Create a folder at ``path``. Returns a `FigshareFolderMetadata` object if successful.

        :param FigsharePath path: FigsharePath representing the folder to create
        :rtype: :class:`waterbutler.core.metadata.FigshareFolderMetadata`
        :raises: :class:`waterbutler.core.exceptions.CreateFolderError`
        """
        if (len(path.parts) == 2) and path.is_folder:
            article_name = path.parts[-1].value
        else:
            raise exceptions.CreateFolderError(
                'Only projects and collections may contain folders. Unable to create '
                '"{}/"'.format(path.name),
                code=400,
            )

        article_data = json.dumps({
            'title': article_name,
            'defined_type': 'fileset'
        })
        article_id = await self._create_article(article_data)
        get_article_response = await self.make_request(
            'GET',
            self.build_url(False, *self.root_path_parts, 'articles',
                           article_id),
            expects=(200, ),
            throws=exceptions.CreateFolderError,
        )
        article_json = await get_article_response.json()

        return metadata.FigshareFolderMetadata(article_json)
Beispiel #5
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)
Beispiel #6
0
 async def create_folder(self, path, **kwargs):
     raise exceptions.CreateFolderError(
         'Cannot create folders within articles.', code=400)