This method creates a group tree

def _create_group_tree(self, levels):
        """This method creates a group tree"""

        if levels[0] != 0:
            raise KPError("Invalid group tree")
        
        for i in range(len(self.groups)):
            if(levels[i] == 0):
                self.groups[i].parent = self.root_group
                self.groups[i].index = len(self.root_group.children)
                self.root_group.children.append(self.groups[i])
                continue

            j = i-1
            while j >= 0:
                if levels[j] < levels[i]:
                    if levels[i]-levels[j] != 1:
                        raise KPError("Invalid group tree")
                    
                    self.groups[i].parent = self.groups[j]
                    self.groups[i].index = len(self.groups[j].children)
                    self.groups[i].parent.children.append(self.groups[i])
                    break
                if j == 0:
                    raise KPError("Invalid group tree")
                j -= 1
            
        for e in range(len(self.entries)):
            for g in range(len(self.groups)):
                if self.entries[e].group_id == self.groups[g].id_:
                    self.groups[g].entries.append(self.entries[e])
                    self.entries[e].group = self.groups[g]
                    # from original KeePassX-code, but what does it do?
                    self.entries[e].index = 0           
        return True