Esempio n. 1
0
    def readdir_mount(self, path, offset, file_hash, action, rest):
        file_descr = get_file_descr(file_hash)

        LOG.debug('Rest:\n\t%s' % rest)
        if not rest:
            rest = ''

        if rest == '':
            yield fuse.Direntry(os.path.basename(file_descr.file.filename))

        file_ids = get_referenced_file_ids(file_descr)
        file_id_paths = set([file_id.filename for file_id in file_ids])
        LOG.debug(os.path.dirname(file_descr.file.filename))
        LOG.debug(file_id_paths)
        tree = file_ids_as_tree(
            file_ids,
            os.path.dirname(file_descr.file.filename)
        )
        files = get_files_for_path(tree, rest)
        LOG.debug('Files:\n\t%s' % files)
        for key, value in files.iteritems():
            if key == FILE_MARKER:
                for entry in value:
                    yield fuse.Direntry(entry[0])
            else:
                yield fuse.Direntry(key)
Esempio n. 2
0
    def getattr_mount(self, path, file_hash, action, rest):
        file_descr = get_file_descr(file_hash)

        if not rest:
            rest = ''

        file_ids = get_referenced_file_ids(file_descr)
        tree = file_ids_as_tree(file_ids,
                                os.path.dirname(file_descr.file.filename))

        if rest == os.path.basename(file_descr.file.filename):
            path_to = find_path_for_file_id(tree, file_descr.file)
            LOG.debug("Rest:\n\t%s\n\t%s" % (rest, path_to))
            file_stat = self.getattr_mount_file(path, file_hash, action, rest,
                                                ('', file_descr.file),
                                                file_descr)
            if path_to.count('/') != 0:
                file_stat.st_mode = stat.S_IFLNK | 0o755
            return file_stat

        files = get_files_for_path(tree, rest)
        if isinstance(files, dict):
            return MyStat(True, 0)
        else:
            return self.getattr_mount_file(path, file_hash, action, rest,
                                           files, file_descr)
Esempio n. 3
0
    def test_file_ids_as_tree(self):
        """Test file_ids_as_tree"""
        file_ids = []
        file_ids.append(FileId(filename='../damn-test-files/mesh/blender/cube1.blend'))
        file_ids.append(FileId(filename='../../image/jpg/crate10b.jpg'))
        file_ids.append(FileId(filename='../../image/jpg/crate10.jpg'))

        main_dict = file_ids_as_tree(file_ids, '../damn-test-files/mesh/blender')

        prettify(main_dict)
        assert True
Esempio n. 4
0
 def readlink(self, path):
     print('*** readlink', path)
     file_hash, action, rest = parse_path(path)
     file_descr = get_file_descr(file_hash)
     
     file_ids = get_referenced_file_ids(file_descr)      
     tree = file_ids_as_tree(file_ids, os.path.dirname(file_descr.file.filename))
     
     path_to = find_path_for_file_id(tree, file_descr.file)
     
     return path_to
Esempio n. 5
0
    def test_file_ids_as_tree(self):
        """Test file_ids_as_tree"""
        file_ids = []
        file_ids.append(FileId(filename="../damn-test-files/mesh/blender/cube1.blend"))
        file_ids.append(FileId(filename="../../image/jpg/crate10b.jpg"))
        file_ids.append(FileId(filename="../../image/jpg/crate10.jpg"))

        main_dict = file_ids_as_tree(file_ids, "../damn-test-files/mesh/blender")

        prettify(main_dict)
        assert True
Esempio n. 6
0
    def readlink(self, path):
        LOG.debug("*** readlink: %s", path)
        file_hash, action, rest = parse_path(path)
        file_descr = get_file_descr(file_hash)

        file_ids = get_referenced_file_ids(file_descr)
        tree = file_ids_as_tree(file_ids,
                                os.path.dirname(file_descr.file.filename))

        path_to = find_path_for_file_id(tree, file_descr.file)

        return path_to
Esempio n. 7
0
    def test_find_path_for_file_id(self):
        """Test find_path_for_file_id"""
        file_ids = []
        file_ids.append(FileId(hash='1', filename='../damn-test-files/mesh/blender/cube1.blend'))
        file_ids.append(FileId(hash='2', filename='../../image/jpg/crate10b.jpg'))
        file_ids.append(FileId(hash='3', filename='../../image/jpg/crate10.jpg'))

        main_dict = file_ids_as_tree(file_ids, '../damn-test-files/mesh/blender')

        prettify(main_dict)

        assert '_/_/cube1.blend' == find_path_for_file_id(main_dict, file_ids[0])
        assert 'image/jpg/crate10b.jpg' == find_path_for_file_id(main_dict, file_ids[1])
        assert 'image/jpg/crate10.jpg' == find_path_for_file_id(main_dict, file_ids[2])
Esempio n. 8
0
    def test_find_path_for_file_id(self):
        """Test find_path_for_file_id"""
        file_ids = []
        file_ids.append(FileId(hash="1", filename="../damn-test-files/mesh/blender/cube1.blend"))
        file_ids.append(FileId(hash="2", filename="../../image/jpg/crate10b.jpg"))
        file_ids.append(FileId(hash="3", filename="../../image/jpg/crate10.jpg"))

        main_dict = file_ids_as_tree(file_ids, "../damn-test-files/mesh/blender")

        prettify(main_dict)

        assert "_/_/cube1.blend" == find_path_for_file_id(main_dict, file_ids[0])
        assert "image/jpg/crate10b.jpg" == find_path_for_file_id(main_dict, file_ids[1])
        assert "image/jpg/crate10.jpg" == find_path_for_file_id(main_dict, file_ids[2])
Esempio n. 9
0
        def __init__(self, path, flags, *mode):
            file_hash, action, rest = parse_path(path)
        
            file_descr = get_file_descr(file_hash)

            if not rest:
                rest = ''
                
            file_ids = get_referenced_file_ids(file_descr)     
            tree = file_ids_as_tree(file_ids, os.path.dirname(file_descr.file.filename))
            files = get_files_for_path(tree, rest)
            if not isinstance(files, dict):
                abs_path = abspath(files[1].filename, file_descr)
                
                self.file = os.fdopen(os.open(abs_path, flags, *mode), flag2mode(flags))
                self.fd = self.file.fileno()       
Esempio n. 10
0
        def __init__(self, path, flags, *mode):
            file_hash, action, rest = parse_path(path)

            file_descr = get_file_descr(file_hash)

            if not rest:
                rest = ''

            file_ids = get_referenced_file_ids(file_descr)
            tree = file_ids_as_tree(file_ids,
                                    os.path.dirname(file_descr.file.filename))
            files = get_files_for_path(tree, rest)
            if not isinstance(files, dict):
                abs_path = abspath(files[1].filename, file_descr)

                self.file = os.fdopen(os.open(abs_path, flags, *mode),
                                      flag2mode(flags))
                self.fd = self.file.fileno()
Esempio n. 11
0
    def getattr_mount(self, path, file_hash, action, rest):
        file_descr = get_file_descr(file_hash)

        if not rest:
            rest = ''

        file_ids = get_referenced_file_ids(file_descr)
        tree = file_ids_as_tree(
            file_ids,
            os.path.dirname(file_descr.file.filename)
        )

        if rest == os.path.basename(file_descr.file.filename):
            path_to = find_path_for_file_id(tree, file_descr.file)
            LOG.debug("Rest:\n\t%s\n\t%s" % (rest, path_to))
            file_stat = self.getattr_mount_file(
                path,
                file_hash,
                action,
                rest,
                ('', file_descr.file),
                file_descr
            )
            if path_to.count('/') != 0:
                file_stat.st_mode = stat.S_IFLNK | 0755
            return file_stat

        files = get_files_for_path(tree, rest)
        if isinstance(files, dict):
            return MyStat(True, 0)
        else:
            return self.getattr_mount_file(
                path,
                file_hash,
                action,
                rest,
                files,
                file_descr
            )
Esempio n. 12
0
    def test_get_files_for_path(self):
        """Test get_files_for_path"""

        file_ids = []
        file_ids.append(FileId(hash="1", filename="test.blend"))
        file_ids.append(FileId(hash="2", filename="../../image/jpeg/test-image1.jpg"))
        file_ids.append(FileId(hash="3", filename="../../image/test-image2.image"))
        file_ids.append(FileId(hash="4", filename="../../image/jpeg/test-image3.jpg"))

        main_dict = file_ids_as_tree(file_ids, "")
        prettify(main_dict)

        paths = [("", 0), ("_/", 0), ("_/_/", 1), ("image/", 1), ("image/jpeg", 2)]
        for path, count in paths:
            files = get_files_for_path(main_dict, path)
            # print('path', count, path, files.get('<children>', None), isinstance(files, dict))
            if isinstance(files, dict):
                assert len(files["<children>"]) == count
            else:
                assert count == 1

        assert True
Esempio n. 13
0
    def test_get_files_for_path(self):
        """Test get_files_for_path"""

        file_ids = []
        file_ids.append(FileId(hash='1', filename='test.blend'))
        file_ids.append(FileId(hash='2', filename='../../image/jpeg/test-image1.jpg'))
        file_ids.append(FileId(hash='3', filename='../../image/test-image2.image'))
        file_ids.append(FileId(hash='4', filename='../../image/jpeg/test-image3.jpg'))


        main_dict = file_ids_as_tree(file_ids, '')
        prettify(main_dict)

        paths = [('', 0), ('_/', 0), ('_/_/', 1), ('image/', 1), ('image/jpeg', 2)]
        for path, count in paths:
            files = get_files_for_path(main_dict, path)
            #print('path', count, path, files.get('<children>', None), isinstance(files, dict))
            if isinstance(files, dict):
                assert len(files['<children>']) == count
            else:
                assert count == 1

        assert True