def get_member(self, name):
        #Check filter access
        if name not in self.member_name_list:
            return None
        if name in ['delete_all_operations', 'duplicate_item', 'accept', 'reject', 'assign_to_myself', 'submit_segmentation']:
            return ISSMFunctionCollection(join_uri(self.path, name), self.environ, self.role_name, name, self.project, self.case)

        image_path = None
        temp_name = name.replace(".nii.gz", "")

        # Find the type of the member (images, manual_segmentations or automatic_segmentation)
        if temp_name.startswith("Image"):
            image_path = "images"
        elif temp_name.startswith("Manual Segmentation"):
            image_path = "manual_segmentations"
        elif temp_name.startswith("Automatic Segmentation"):
            model_id = temp_name.replace("Automatic Segmentation", "")
            image_path = "automatic_segmentation/model_{}".format(int(model_id))


        if image_path is None:
            return None
        
        # Build the dest image path
        image_path = join_uri(self.project_path, image_path, "{}.nii.gz".format(self.case_id))
        
        # Create a non collection item wich represents the image.
        return ISSMDAVNonCollection(join_uri(self.path, name), self.environ, image_path, name, self.project, self.case)
Пример #2
0
    def get_member_list(self):
        """Return list of (direct) collection member names (UTF-8 byte strings).

        See DAVResource.get_member_list()
        """
        members = []
        conn = self.provider._init_connection()
        try:
            tableName, primKey = self.provider._split_path(self.path)
            if tableName is None:
                retlist = self.provider._list_tables(conn)
                for name in retlist:
                    members.append(MySQLBrowserResource(self.provider,
                                                        util.join_uri(self.path, name),
                                                        True,
                                                        self.environ))
            elif primKey is None:
                pri_key = self.provider._find_primary_key(conn, tableName)
                if pri_key is not None:
                    retlist = self.provider._list_fields(conn, tableName, pri_key)
                    for name in retlist:
                        members.append(MySQLBrowserResource(
                                self.provider, util.join_uri(self.path, name),
                                False, self.environ))
                members.insert(0, MySQLBrowserResource(
                        self.provider, util.join_uri(self.path, "_ENTIRE_CONTENTS"),
                        False, self.environ))
        finally:
            conn.close()
        return members
Пример #3
0
 def get_member(self, name):
     if self.name == "by_key":
         data = _get_res_by_key(name)
         if data:
             return VirtualResource(join_uri(self.path, name), self.environ, data)
         else:
             return None
     return CategoryCollection(join_uri(self.path, name), self.environ, self.name)
    def get_member(self, name):
        # Create a ISSMCaseFilterCollection for the given by name
        #Check filter access
        if name not in self.member_name_list:
            return None

        if name in ['all', 'to_review', 'todo', 'queued']:
            return ISSMCaseFilterCollection(join_uri(self.path, name), self.environ, self.role_name, name, self.project)
        elif name in ['upload']:
            return ISSMFunctionCollection(join_uri(self.path, name), self.environ, self.role_name, name, self.project, None)
Пример #5
0
 def get_member(self, name):
     if name in self._artifactNames:
         return VirtualArtifact(join_uri(self.path, name), self.environ, self.data)
     for file_path in self.data["resPathList"]:
         fname = os.path.basename(file_path)
         if fname == name:
             return VirtualResFile(
                 join_uri(self.path, name), self.environ, self.data, file_path
             )
     return None
Пример #6
0
 def get_member(self, name):
     if self.name == "by_key":
         data = _get_res_by_key(name)
         if data:
             return VirtualResource(join_uri(self.path, name), self.environ,
                                    data)
         else:
             return None
     return CategoryCollection(join_uri(self.path, name), self.environ,
                               self.name)
Пример #7
0
 def get_member(self, name):
     if name in self._artifactNames:
         return VirtualArtifact(join_uri(self.path, name), self.environ,
                                self.data)
     for file_path in self.data["resPathList"]:
         fname = os.path.basename(file_path)
         if fname == name:
             return VirtualResFile(join_uri(self.path, name), self.environ,
                                   self.data, file_path)
     return None
 def get_member(self, name):
     # Create a ISSMRoleCollection for the given rolename (name)
     #Check role access
     if name not in self.member_name_list:
         return None
         
     return ISSMRoleCollection(join_uri(self.path, name), self.environ, self.project, name)
Пример #9
0
 def create_collection(self, name):
     assert "/" not in name
     if self.provider.readonly:
         raise DAVError(HTTP_FORBIDDEN)
     path = util.join_uri(self.path, name)
     fp = self.provider._loc_to_file_path(path, self.environ)
     self.db.dir_create(fp)
Пример #10
0
 def create_empty_resource(self, name):
     assert "/" not in name
     if self.provider.readonly:
         raise DAVError(HTTP_FORBIDDEN)
     path = util.join_uri(self.path, name)
     fp = self.provider._loc_to_file_path(path, self.environ)
     self.db.file_create_empty(fp)
     return self.provider.get_resource_inst(path, self.environ)
Пример #11
0
    def create_collection(self, name):
        """Create a new collection as member of self.

        See _DAVResource.create_collection()
        """
        assert self.is_collection
        self._check_write_access()
        path = util.join_uri(self.path, name)
        fire_fs.mkdir(path)
    def get_member(self, name):
        if name not in self.member_name_list:
            return None

        tempfile_path = self.environ['wsgidav.filehandler'].getTempFile(self.path, self.environ['wsgidav.auth.user'])

        if tempfile_path is None:
            return None

        return ISSMDAVNonCollection(join_uri(self.path, name), self.environ, tempfile_path, name, self.project, self.case)    
Пример #13
0
    def get_member(self, name):
        """Return list of (direct) collection members (_DAVResource or derived).

        See _DAVResource.get_member_list()
        """
        # logging.debug('%r + %r' % (self.path, name))
        # self._check_browse_access()
        # res = FirestoreDAVResource(util.join_uri(self.path, name), self.environ)
        res = type(self)(util.join_uri(self.path, name), self.environ)
        return res
    def get_member(self, name):
        # Find all available projects by project_name (should be unique)
        filtered_projects = list(filter(lambda item: item['short_name'] == name,self.environ["wsgidav.auth.projects"]))
        temp_project = None
        if len(filtered_projects) >= 1:
            temp_project = filtered_projects[0]
        else:
            return None

        # Retur a ISSMProjectCollection member wich list all case for the given user
        return ISSMProjectCollection(join_uri(self.path, name), self.environ, temp_project)
Пример #15
0
    def create_collection(self, name):
        """Create a new collection as member of self.

        See DAVResource.create_collection()
        """
        assert "/" not in name
        if self.provider.readonly:
            raise DAVError(HTTP_FORBIDDEN)
        path = util.join_uri(self.path, name)
        fp = self.provider._loc_to_file_path(path, self.environ)
        os.mkdir(fp)
Пример #16
0
    def create_collection(self, name):
        """Create a new collection as member of self.

        See DAVResource.create_collection()
        """
        assert "/" not in name
        if self.provider.readonly:
            raise DAVError(HTTP_FORBIDDEN)
        path = util.join_uri(self.path, name)
        fp = self.provider._loc_to_file_path(path, self.environ)
        os.mkdir(fp)
    def __init__(self, path, environ, role_name, project_path, project, case):
        super(ISSMCaseCollection, self).__init__(path, environ)

        self.display_info = {"type":"Case"}
        self.project_path = project_path
        self.role_name = role_name
        self.project = project
        self.case = case
        self.case_id = case['id']
        self.member_name_list = []

        
        if role_name == 'administration':
            #Only in all
            self.member_name_list.append('delete_all_operations')
            self.member_name_list.append('duplicate_item')
        elif role_name == 'review':
            #Only for cases to review
            self.member_name_list.append('accept')
            self.member_name_list.append('reject')
        elif role_name == 'segmentation':
            #Only for queued
            if case['status'] == "Queued" and case['assignee_id'] != self.environ["wsgidav.auth.user"]['id']:
                self.member_name_list.append('assign_to_myself')
                
            #Only for todo
            if case['assignee_id']  == self.environ["wsgidav.auth.user"]['id']:
                self.member_name_list.append('submit_segmentation')

       
        #Search all stored images for the given case id
        if isfile(join_uri(self.project_path, "images","{}.nii.gz".format(self.case_id))):
            self.member_name_list.append("Image.nii.gz")
        if isfile(join_uri(self.project_path, "manual_segmentations","{}.nii.gz".format(self.case_id))):
            self.member_name_list.append("Manual Segmentation.nii.gz")
        
        # Search for stored auttomatic segementaion models
        for model in listdir(join_uri(self.project_path,"automatic_segmentation")):
            model_id = model.replace("model_", "")
            if str(model_id).isdigit() and isfile(join_uri(self.project_path, "automatic_segmentation","{}/{}.nii.gz".format(model, self.case_id))):
                self.member_name_list.append("Automatic Segmentation {}.nii.gz".format(model_id))
    def create_empty_resource(self, name):
        """Create and return an empty (length-0) resource as member of self.
        Called for LOCK requests on unmapped URLs.
        Preconditions (to be ensured by caller):
          - this must be a collection
          - <self.path + name> must not exist
          - there must be no conflicting locks
        Returns a DAVResuource.
        This method MUST be implemented by all providers that support write
        access.
        This default implementation simply raises HTTP_FORBIDDEN.
        """

        print(f"create_empty_resource")

        cur_path = self.path
        cfile_path = self.environ['wsgidav.filehandler'].getTempFile(cur_path,self.environ['wsgidav.auth.user'])
        
        if cfile_path is not None:
            return ISSMDAVNonCollection(join_uri(self.path, name), self.environ, cfile_path, name, self.project, self.case)

        if (self.name == "upload" or self.name == "submit_segmentation") and cfile_path is None:
            if cfile_path is None:
                cfile_path = self.environ['wsgidav.filehandler'].newTempFile(cur_path,self.environ['wsgidav.auth.user'], name)
            
            self.environ['wsgidav.filehandler'].addInformationToTempFile(cur_path,self.environ['wsgidav.auth.user'],{
                'project_id':  self.project['id'],
                'case_id': self.case['id'],
                'user': self.environ['wsgidav.auth.user']
            })

            return ISSMDAVNonCollection(join_uri(self.path, name), self.environ, cfile_path, name, self.project, self.case)
        elif self.case is not None:
            result_state = perform_function(self.name, self.project['id'], self.case['id'], self.environ["wsgidav.auth.user"])

            if result_state:
                if cfile_path is None:
                    cfile_path = self.environ['wsgidav.filehandler'].newTempFile(cur_path,self.environ['wsgidav.auth.user'], name)
                return ISSMDAVNonCollection(join_uri(self.path, name), self.environ, cfile_path, name, self.project, self.case)
            
        raise DAVError(HTTP_FORBIDDEN)
Пример #19
0
    def create_empty_resource(self, name):
        """Create an empty (length-0) resource.

        See DAVResource.create_empty_resource()
        """
        assert "/" not in name
        if self.provider.readonly:
            raise DAVError(HTTP_FORBIDDEN)
        path = util.join_uri(self.path, name)
        fp = self.provider._loc_to_file_path(path, self.environ)
        f = open(fp, "wb")
        f.close()
        return self.provider.get_resource_inst(path, self.environ)
Пример #20
0
    def create_empty_resource(self, name):
        """Create an empty (length-0) resource.

        See DAVResource.create_empty_resource()
        """
        assert "/" not in name
        if self.provider.readonly:
            raise DAVError(HTTP_FORBIDDEN)
        path = util.join_uri(self.path, name)
        fp = self.provider._loc_to_file_path(path, self.environ)
        f = open(fp, "wb")
        f.close()
        return self.provider.get_resource_inst(path, self.environ)
Пример #21
0
    def create_empty_resource(self, name):
        """Create an empty (length-0) resource.

        See _DAVResource.create_empty_resource()
        """
        assert self.is_collection
        assert not "/" in name
        self._check_write_access()
        path = util.join_uri(self.path, name)
        f = fire_fs.btopen(path, "wb")
        # FIXME: should be length-0
        # f.write(".")
        f.close()
        return self.provider.get_resource_inst(path, self.environ)
Пример #22
0
    def create_empty_resource(self, name):
        """Create an empty (length-0) resource.

        See DAVResource.create_empty_resource()
        """
        assert "/" not in name
        if self.provider.readonly:
            raise fdp.DAVError(fdp.HTTP_FORBIDDEN)
        path = util.join_uri(self.path, name)
        # noinspection PyProtectedMember
        fp = self.provider._loc_to_file_path(path, self.environ)
        f = open(fp, "wb")
        f.close()
        os.chown(fp, self.uid, self.gid)
        os.chmod(fp, self.chmask)
        return self.provider.get_resource_inst(path, self.environ)
Пример #23
0
    def get_member(self, name):
        """Return direct collection member (DAVResource or derived).

        See DAVCollection.get_member()
        """
        assert compat.is_native(name), "{!r}".format(name)
        fp = os.path.join(self._file_path, compat.to_unicode(name))
        #        name = name.encode("utf8")
        path = util.join_uri(self.path, name)
        if os.path.isdir(fp):
            res = FolderResource(path, self.environ, fp)
        elif os.path.isfile(fp):
            res = FileResource(path, self.environ, fp)
        else:
            _logger.debug("Skipping non-file {}".format(path))
            res = None
        return res
Пример #24
0
    def get_member(self, name):
        """Return direct collection member (DAVResource or derived).

        See DAVCollection.get_member()
        """
        assert compat.is_native(name), "{!r}".format(name)
        fp = os.path.join(self._file_path, compat.to_unicode(name))
        #        name = name.encode("utf8")
        path = util.join_uri(self.path, name)
        if os.path.isdir(fp):
            res = FolderResource(path, self.environ, fp)
        elif os.path.isfile(fp):
            res = FileResource(path, self.environ, fp)
        else:
            _logger.debug("Skipping non-file {}".format(path))
            res = None
        return res
    def __init__(self, path, environ, role_name, name, project):
        super(ISSMCaseFilterCollection, self).__init__(path, environ)
        
        # Download the case for this collection depending on the collection name.
        filtername = name
        if filtername == 'to_review':
            filtername = "review"
        elif filtername == 'todo':
            filtername = "assign"

        self.display_info = {"type":"Filter"}
        self.project = project
        self.role_name = role_name
        self.members = None
        self.filter_name = filtername

        # Set the project path by the short_name 
        self.project_path = join_uri("/data", project['short_name'])
    def get_member(self, name):
        self.load_members()
        
        if self.members is None:
            return None

        # Find the case to the image
        target_case = None
        for case in self.members:
            if case['name'] == name:
                target_case = case
                break

        # Create a ISSMCaseCollection for the given case_id (name)
        if target_case is not None:
            return ISSMCaseCollection(join_uri(self.path, target_case['name']), self.environ, self.role_name, self.project_path, self.project, target_case)
        else:
            return None
Пример #27
0
    def testBasics(self):
        """Test basic tool functions."""
        assert join_uri("/a/b", "c") == "/a/b/c"
        assert join_uri("/a/b/", "c") == "/a/b/c"
        assert join_uri("/a/b", "c", "d") == "/a/b/c/d"
        assert join_uri("a/b", "c", "d") == "a/b/c/d"
        assert join_uri("/", "c") == "/c"
        assert join_uri("", "c") == "/c"

        assert not is_child_uri("/a/b", "/a/")
        assert not is_child_uri("/a/b", "/a/b")
        assert not is_child_uri("/a/b", "/a/b/")
        assert not is_child_uri("/a/b", "/a/bc")
        assert not is_child_uri("/a/b", "/a/bc/")
        assert is_child_uri("/a/b", "/a/b/c")
        assert is_child_uri("/a/b", "/a/b/c")

        assert not is_equal_or_child_uri("/a/b", "/a/")
        assert is_equal_or_child_uri("/a/b", "/a/b")
        assert is_equal_or_child_uri("/a/b", "/a/b/")
        assert not is_equal_or_child_uri("/a/b", "/a/bc")
        assert not is_equal_or_child_uri("/a/b", "/a/bc/")
        assert is_equal_or_child_uri("/a/b", "/a/b/c")
        assert is_equal_or_child_uri("/a/b", "/a/b/c")

        assert lstripstr("/dav/a/b", "/dav") == "/a/b"
        assert lstripstr("/dav/a/b", "/DAV") == "/dav/a/b"
        assert lstripstr("/dav/a/b", "/DAV", True) == "/a/b"

        assert pop_path("/a/b/c") == ("a", "/b/c")
        assert pop_path("/a/b/") == ("a", "/b/")
        assert pop_path("/a/") == ("a", "/")
        assert pop_path("/a") == ("a", "/")
        assert pop_path("/") == ("", "")
        assert pop_path("") == ("", "")

        self.assertEqual(shift_path("", "/a/b/c"), ("a", "/a", "/b/c"))
        self.assertEqual(shift_path("/a", "/b/c"), ("b", "/a/b", "/c"))
        self.assertEqual(shift_path("/a/b", "/c"), ("c", "/a/b/c", ""))
        self.assertEqual(shift_path("/a/b/c", "/"), ("", "/a/b/c", ""))
        self.assertEqual(shift_path("/a/b/c", ""), ("", "/a/b/c", ""))
Пример #28
0
    def testBasics(self):
        """Test basic tool functions."""
        assert join_uri("/a/b", "c") == "/a/b/c"
        assert join_uri("/a/b/", "c") == "/a/b/c"
        assert join_uri("/a/b", "c", "d") == "/a/b/c/d"
        assert join_uri("a/b", "c", "d") == "a/b/c/d"
        assert join_uri("/", "c") == "/c"
        assert join_uri("", "c") == "/c"

        assert not is_child_uri("/a/b", "/a/")
        assert not is_child_uri("/a/b", "/a/b")
        assert not is_child_uri("/a/b", "/a/b/")
        assert not is_child_uri("/a/b", "/a/bc")
        assert not is_child_uri("/a/b", "/a/bc/")
        assert is_child_uri("/a/b", "/a/b/c")
        assert is_child_uri("/a/b", "/a/b/c")

        assert not is_equal_or_child_uri("/a/b", "/a/")
        assert is_equal_or_child_uri("/a/b", "/a/b")
        assert is_equal_or_child_uri("/a/b", "/a/b/")
        assert not is_equal_or_child_uri("/a/b", "/a/bc")
        assert not is_equal_or_child_uri("/a/b", "/a/bc/")
        assert is_equal_or_child_uri("/a/b", "/a/b/c")
        assert is_equal_or_child_uri("/a/b", "/a/b/c")

        assert lstripstr("/dav/a/b", "/dav") == "/a/b"
        assert lstripstr("/dav/a/b", "/DAV") == "/dav/a/b"
        assert lstripstr("/dav/a/b", "/DAV", True) == "/a/b"

        assert pop_path("/a/b/c") == ("a", "/b/c")
        assert pop_path("/a/b/") == ("a", "/b/")
        assert pop_path("/a/") == ("a", "/")
        assert pop_path("/a") == ("a", "/")
        assert pop_path("/") == ("", "")
        assert pop_path("") == ("", "")

        self.assertEqual(shift_path("", "/a/b/c"), ("a", "/a", "/b/c"))
        self.assertEqual(shift_path("/a", "/b/c"), ("b", "/a/b", "/c"))
        self.assertEqual(shift_path("/a/b", "/c"), ("c", "/a/b/c", ""))
        self.assertEqual(shift_path("/a/b/c", "/"), ("", "/a/b/c", ""))
        self.assertEqual(shift_path("/a/b/c", ""), ("", "/a/b/c", ""))
Пример #29
0
 def get_member(self, name):
     # Rely on provider to get member oinstances
     assert self.is_collection
     return self.provider.get_resource_inst(
         util.join_uri(self.path, name), self.environ
     )
Пример #30
0
 def get_member(self, name):
     for data in _get_res_list_by_attr(self.catType, self.name):
         if data["title"] == name:
             return VirtualResource(join_uri(self.path, name), self.environ,
                                    data)
     return None
Пример #31
0
 def get_member(self, name):
     return DbCollection(join_uri(self.path, name), self.environ)
Пример #32
0
 def get_member(self, name):
     # Handle visible categories and also /by_key/...
     if name in self._validMemberNames:
         return CategoryTypeCollection(join_uri(self.path, name),
                                       self.environ)
     return None
Пример #33
0
 def get_member(self, name):
     doc = self.coll.find_one(ObjectId(name))
     return DocResource(join_uri(self.path, name), self.environ, doc)
Пример #34
0
 def get_member(self, name):
     coll = self.db[name]
     return CollCollection(join_uri(self.path, name), self.environ, coll)
Пример #35
0
 def get_member(self, name):
     return DbCollection(join_uri(self.path, name), self.environ)
Пример #36
0
 def get_member(self, name):
     coll = self.db[name]
     return CollCollection(join_uri(self.path, name), self.environ, coll)
Пример #37
0
 def get_member(self, name):
     doc = self.coll.find_one(ObjectId(name))
     return DocResource(join_uri(self.path, name), self.environ, doc)
Пример #38
0
 def get_member(self, name):
     for data in _get_res_list_by_attr(self.catType, self.name):
         if data["title"] == name:
             return VirtualResource(join_uri(self.path, name), self.environ, data)
     return None
Пример #39
0
 def get_member(self, name):
     # Handle visible categories and also /by_key/...
     if name in self._validMemberNames:
         return CategoryTypeCollection(join_uri(self.path, name), self.environ)
     return None
Пример #40
0
 def get_member(self, name):
     # Rely on provider to get member oinstances
     assert self.is_collection
     return self.provider.get_resource_inst(util.join_uri(self.path, name),
                                            self.environ)
Пример #41
0
 def get_member(self, name):
     # raise NotImplementedError
     return self.provider.get_resource_inst(util.join_uri(self.path, name),
                                            self.environ)
Пример #42
0
 def get_member(self, name):
     # raise NotImplementedError
     return self.provider.get_resource_inst(
         util.join_uri(self.path, name), self.environ
     )