コード例 #1
0
 def test_free_space_returns_cur_size_if_is_limitsizefs(self):
     # Arrange
     fs = LimitSizeFS(MemoryFS(), mb(230))
     # Act
     space = free_space(fs)
     # Assert
     assert space == mb(230)
コード例 #2
0
ファイル: test_multifs.py プロジェクト: TrienDo/cuckoodrive
 def test_free_space_returns_cur_size_if_is_limitsizefs(self):
     # Arrange
     fs = LimitSizeFS(MemoryFS(), mb(230))
     # Act
     space = free_space(fs)
     # Assert
     assert space == mb(230)
コード例 #3
0
 def test_free_space_returns_meta_if_has_meta(self):
     # Arrange
     fs = MemoryFS()
     fs.getmeta = Mock(return_value=mb(230))
     # Act
     space = free_space(fs)
     # Assert
     assert space == mb(230)
コード例 #4
0
ファイル: test_multifs.py プロジェクト: TrienDo/cuckoodrive
 def test_free_space_returns_meta_if_has_meta(self):
     # Arrange
     fs = MemoryFS()
     fs.getmeta = Mock(return_value=mb(230))
     # Act
     space = free_space(fs)
     # Assert
     assert space == mb(230)
コード例 #5
0
    def setUp(self):
        multifs = WritableMultiFS()
        fs1 = LimitSizeFS(MemoryFS(), mb(230))
        fs2 = LimitSizeFS(MemoryFS(), mb(300))

        multifs.addfs("fs1", fs1)
        multifs.addfs("fs2", fs2)

        self.fs = multifs
コード例 #6
0
ファイル: test_multifs.py プロジェクト: TrienDo/cuckoodrive
    def setUp(self):
        multifs = WritableMultiFS()
        fs1 = LimitSizeFS(MemoryFS(), mb(230))
        fs2 = LimitSizeFS(MemoryFS(), mb(300))

        multifs.addfs("fs1", fs1)
        multifs.addfs("fs2", fs2)

        self.fs = multifs
コード例 #7
0
    def fs(self):
        multifs = WritableMultiFS()

        fs1 = LimitSizeFS(MemoryFS(), mb(300))
        fs2 = LimitSizeFS(MemoryFS(), mb(240))

        multifs.addfs("fs1", fs1)
        multifs.addfs("fs2", fs2)

        return multifs
コード例 #8
0
ファイル: test_multifs.py プロジェクト: TrienDo/cuckoodrive
    def fs(self):
        multifs = WritableMultiFS()

        fs1 = LimitSizeFS(MemoryFS(), mb(300))
        fs2 = LimitSizeFS(MemoryFS(), mb(240))

        multifs.addfs("fs1", fs1)
        multifs.addfs("fs2", fs2)

        return multifs
コード例 #9
0
class CuckooDriveFS(WrapFS):
    """This filesystem is used in CuckooDrive an basically encapsulates a PartedFS on top of
    a WritableMultiFS containg the custom cloud provider filesystems.

    The Filesystem stack usually looks something like this:

    +------------+------------+-----------+
    |               PartedFS              |
    +------------+------------+-----------+
    |            WritableMultiFS          |
    +------------+------------+-----------+
    | DropboxFS  | OneDriveFS | RemoteFS  |
    +------------+------------+-----------+

    You can aggregate every custom PyFilesystem you want. For testing we often use OSFS instances::
        fs = CuckooDriveFS(remote_filesystems=[OSFS('/tmp/fs1'), OSFS('/tmp/fs2')])

    You can also use the filesystem URI syntax to create a CuckooDriveFS::
        fs = CuckooDriveFS.from_uris(remote_uris=['/tmp/fs1', '/tmp/fs1'])

    This works for all filesystem that have an Opener implemented::
        fs = CuckooDriveFS.from_uris(remote_uris=['dropbox://morgenkaffee/cuckoo'])

    When the verbose option is specified, each filesystem is wrapped in a DebugFS that logs
    every action.

    Manipulate the maximum file_size of a PartFile of the PartedFS::
        CuckooDriveFS.file_size = mb(40)
    """
    skip_methods = ('listdir', 'listdirinfo', 'getinfo', 'exists', 'isfile',
                    'getsize')
    file_size = mb(10)

    def __init__(self, remote_filesystems, verbose=False):
        self.verbose = verbose
        fs = self._create_fs(remote_filesystems)
        super(CuckooDriveFS, self).__init__(fs)

    def _create_fs(self, remote_filesystems):
        """Create the cuckoo drive fileystem out of the remote filesystems"""
        multifs = CuckooDriveFS.verbose_fs(WritableMultiFS(), "MultiFS",
                                           self.verbose)
        for idx, remote_fs in enumerate(remote_filesystems):
            multifs.addfs("Remote{0}".format(idx), remote_fs)

        return CuckooDriveFS.verbose_fs(PartedFS(multifs, self.file_size),
                                        "PartedFS", self.verbose)

    @staticmethod
    def verbose_fs(wrapped_fs, identifier, verbose):
        """Wrap the filesystem into a DebugFS if the verbose option is specified"""
        if verbose:
            return DebugFS(wrapped_fs,
                           identifier=identifier,
                           skip=CuckooDriveFS.skip_methods,
                           verbose=False)
        return wrapped_fs

    @classmethod
    def from_uris(cls, remote_uris, verbose=False):
        """Create remote filesystem for each given uri and return them"""
        def create_fs(idx, fs_uri):
            return CuckooDriveFS.verbose_fs(fsopendir(fs_uri),
                                            "Remote{0}".format(idx), verbose)

        remote_filesystems = [
            create_fs(idx, fs_uri) for idx, fs_uri in enumerate(remote_uris)
        ]
        return cls(remote_filesystems, verbose)
コード例 #10
0
 def filesystems(self):
     userfs = TempFS()
     fs1 = LimitSizeFS(MemoryFS(), mb(300))
     fs2 = LimitSizeFS(MemoryFS(), mb(300))
     remotefs = CuckooDriveFS(remote_filesystems=[fs1, fs2])
     return (userfs, remotefs)
コード例 #11
0
 def fs(self, request):
     fs1 = LimitSizeFS(MemoryFS(), mb(300))
     fs2 = LimitSizeFS(MemoryFS(), mb(300))
     fs = CuckooDriveFS([fs1, fs2])
     request.addfinalizer(lambda: fs.close())
     return fs
コード例 #12
0
 def setUp(self):
     fs1 = LimitSizeFS(MemoryFS(), mb(300))
     fs2 = LimitSizeFS(MemoryFS(), mb(300))
     self.fs = CuckooDriveFS([fs1, fs2])