Example #1
0
    def makedir(self, path, recursive=False, allow_recreate=False):
        path = normpath(path)
        if path in ('', '/'):
            return
        def checkdir(path):
            if not self.isdir(path):
                self.clear_dircache(dirname(path))
                try:
                    self.ftp.mkd(_encode(path))
                except error_reply:
                    return
                except error_perm as e:
                    if recursive or allow_recreate:
                        return
                    if str(e).split(' ', 1)[0]=='550':
                        raise DestinationExistsError(path)
                    else:
                        raise
        if recursive:
            for p in recursepath(path):
                checkdir(p)
        else:
            base = dirname(path)
            if not self.exists(base):
                raise ParentDirectoryMissingError(path)

            if not allow_recreate:
                if self.exists(path):
                    if self.isfile(path):
                        raise ResourceInvalidError(path)
                    raise DestinationExistsError(path)
            checkdir(path)
Example #2
0
    def makedir(self, path, recursive=False, allow_recreate=False):
        path = normpath(path)
        if path in ('', '/'):
            return

        if recursive:
            created = False
            for path_part in recursepath(path):
                if not self.isdir(path_part):
                    self.conn.mkdir(self.smb_path(path_part))
                    created = True
                else:
                    if self.isfile(path_part):
                        raise ResourceInvalidError(path_part)

            if not created and not allow_recreate:
                raise DestinationExistsError(path)
        else:
            base = dirname(path)
            if not self.exists(base):
                raise ParentDirectoryMissingError(path)

            if not allow_recreate:
                if self.exists(path):
                    if self.isfile(path):
                        raise ResourceInvalidError(path)
                    raise DestinationExistsError(path)
                self.conn.mkdir(self.smb_path(path))
            else:
                if not self.isdir(path):
                    self.conn.mkdir(self.smb_path(path))
Example #3
0
    def makedir(self, path, recursive=False, allow_recreate=False):
        path = normpath(path)
        if path in ('', '/'):
            return

        if recursive:
            created = False
            for path_part in recursepath(path):
                if not self.isdir(path_part):
                    self.conn.mkdir(self.smb_path(path_part))
                    created = True
                else:
                    if self.isfile(path_part):
                        raise ResourceInvalidError(path_part)

            if not created and not allow_recreate:
                raise DestinationExistsError(path)
        else:
            base = dirname(path)
            if not self.exists(base):
                raise ParentDirectoryMissingError(path)

            if not allow_recreate:
                if self.exists(path):
                    if self.isfile(path):
                        raise ResourceInvalidError(path)
                    raise DestinationExistsError(path)
                self.conn.mkdir(self.smb_path(path))
            else:
                if not self.isdir(path):
                    self.conn.mkdir(self.smb_path(path))
Example #4
0
    def _is_pending_delete(self, FileName):
        """Check if the given path is pending deletion.

		This is true if the path or any of its parents have been marked
		as pending deletion, false otherwise.
		"""
        for ppath in recursepath(FileName):
            if ppath in self._pending_delete:
                return True
        return False
Example #5
0
 def test_recursepath(self):
     self.assertEqual(recursepath("/"), ["/"])
     self.assertEqual(recursepath("hello"), ["/", "/hello"])
     self.assertEqual(recursepath("/hello/world/"),
                      ["/", "/hello", "/hello/world"])
     self.assertEqual(recursepath("/hello/world/", reverse=True),
                      ["/hello/world", "/hello", "/"])
     self.assertEqual(recursepath("hello", reverse=True), ["/hello", "/"])
     self.assertEqual(recursepath("", reverse=True), ["/"])
Example #6
0
    def removedir(self, path, recursive=False, force=False):
        if path == '/':
            raise RemoveRootError(path)

        # Remove directory tree from the bottom upwards depending upon the
        # flags.
        if force:
            for (del_dir, del_files) in self.walk(path, search='depth',
                                                  ignore_errors=True):
                for f in del_files:
                    self.remove(pathjoin(del_dir, f))
                self.removedir(del_dir)
        elif recursive:
            paths = recursepath(path, reverse=True)[:-1]
            for p in paths:
                self._remove_dir(p)
        else:
            self._remove_dir(path)
Example #7
0
    def removedir(self, path, recursive=False, force=False):
        if path == '/':
            raise RemoveRootError(path)

        # Remove directory tree from the bottom upwards depending upon the
        # flags.
        if force:
            for (del_dir, del_files) in self.walk(path,
                                                  search='depth',
                                                  ignore_errors=True):
                for f in del_files:
                    self.remove(pathjoin(del_dir, f))
                self.removedir(del_dir)
        elif recursive:
            paths = recursepath(path, reverse=True)[:-1]
            for p in paths:
                self._remove_dir(p)
        else:
            self._remove_dir(path)
Example #8
0
    def iter_dirs(handle):
        zipname = lambda n: abspath(n).rstrip('/')
        seen = set()
        root_filter = '/'.__contains__

        if hasattr(handle, 'seek') and handle.seekable():
            handle.seek(0)

        with zipfile.ZipFile(handle) as z:
            for name in z.namelist():
                # directory defined in the zipfile
                if name.endswith('/'):
                    seen.add(name)
                    yield zipname(name)
                # implicit directory
                else:
                    for path in filterfalse(root_filter, recursepath(name)):
                        if path != abspath(name) and not path in seen:
                            seen.add(path)
                            yield zipname(path)
Example #9
0
    def makedir(self, path, recursive=False, allow_recreate=False):
        # Create a directory from the top downwards depending upon the flags.
        paths = recursepath(path) if recursive else (path, )
        for p in paths:
            if p == '/':
                continue

            # Try to create a directory first then ask for forgiveness.
            try:
                self._create_dir(p)
            except DestinationExistsError as e:
                if self.isfile(p):
                    raise ResourceInvalidError(path)
                elif self.isdir(p):
                    if not recursive and not allow_recreate:
                        raise DestinationExistsError(path)
            except ResourceNotFoundError as e:
                if not recursive and not self.isdir(dirname(p)):
                    raise ParentDirectoryMissingError(path)
                e.path = path
                raise
            except FSError as e:
                e.path = path
                raise
Example #10
0
    def makedir(self, path, recursive=False, allow_recreate=False):
        # Create a directory from the top downwards depending upon the flags.
        paths = recursepath(path) if recursive else (path, )
        for p in paths:
            if p == '/':
                continue

            # Try to create a directory first then ask for forgiveness.
            try:
                self._create_dir(p)
            except DestinationExistsError as e:
                if self.isfile(p):
                    raise ResourceInvalidError(path)
                elif self.isdir(p):
                    if not recursive and not allow_recreate:
                        raise DestinationExistsError(path)
            except ResourceNotFoundError as e:
                if not recursive and not self.isdir(dirname(p)):
                    raise ParentDirectoryMissingError(path)
                e.path = path
                raise
            except FSError as e:
                e.path = path
                raise
Example #11
0
            if not self.isdir(path):
                self.clear_dircache(dirname(path))
                try:
                    self.ftp.mkd(_encode(path))
                except error_reply:
                    return
                except error_perm, e:
                    if recursive or allow_recreate:
                        return
                    if str(e).split(' ', 1)[0] == '550':
                        raise DestinationExistsError(path)
                    else:
                        raise

        if recursive:
            for p in recursepath(path):
                checkdir(p)
        else:
            base = dirname(path)
            if not self.exists(base):
                raise ParentDirectoryMissingError(path)

            if not allow_recreate:
                if self.exists(path):
                    if self.isfile(path):
                        raise ResourceInvalidError(path)
                    raise DestinationExistsError(path)
            checkdir(path)

    @ftperrors
    def remove(self, path):
Example #12
0
            if not self.isdir(path):
                self.clear_dircache(dirname(path))
                try:
                    self.ftp.mkd(_encode(path))
                except error_reply:
                    return
                except error_perm, e:
                    if recursive or allow_recreate:
                        return
                    if str(e).split(" ", 1)[0] == "550":
                        raise DestinationExistsError(path)
                    else:
                        raise

        if recursive:
            for p in recursepath(path):
                checkdir(p)
        else:
            base = dirname(path)
            if not self.exists(base):
                raise ParentDirectoryMissingError(path)

            if not allow_recreate:
                if self.exists(path):
                    if self.isfile(path):
                        raise ResourceInvalidError(path)
                    raise DestinationExistsError(path)
            checkdir(path)

    @ftperrors
    def remove(self, path):
Example #13
0
 def recurse(self):
     return fp.recursepath(self.path)