Example #1
0
    def update(self):
        """merge modifiactions since last update into working copy"""
        print "update"
        if self.unresolved_conflicts():
            return
        layer = QgsMapLayerRegistry.instance().mapLayer(self.current_layers[0])
        uri = QgsDataSourceURI(layer.source())

        late_by = 0

        if layer.providerType() == "spatialite":
            late_by = versioning_base.late(uri.database(), self.pg_conn_info())
        else:  # postgres
            late_by = versioning_base.pg_late(self.pg_conn_info(),
                                              uri.schema())
        if late_by:
            if layer.providerType() == "spatialite":
                versioning_base.update(uri.database(), self.pg_conn_info())
                rev = versioning_base.revision(uri.database())
            else:  # postgres
                versioning_base.pg_update(uri.connectionInfo(), uri.schema())
                rev = versioning_base.pg_revision(uri.connectionInfo(),
                                                  uri.schema())

            # Force refresh of map
            if self.iface.mapCanvas().isCachingEnabled():
                self.iface.mapCanvas().clearCache()
                self.iface.mapCanvas().refresh()
            else:
                self.iface.mapCanvas().refresh()

            # Force refresh of rev number in menu text
            if layer.providerType() == "spatialite":
                self.info.setText(uri.database().split("/")[-1] +
                                  ' <b>working rev</b>=' + str(rev))
            else:
                self.info.setText(uri.database() + ' <b>working rev</b>=' +
                                  str(rev))

            if not self.unresolved_conflicts():
                QMessageBox.warning(
                    self.iface.mainWindow(), "Warning",
                    "Working copy was late by " + str(late_by) +
                    " revision(s).\n"
                    "Now up to date with remote revision " + str(rev - 1) +
                    ".")
        else:
            if layer.providerType() == "spatialite":
                rev = versioning_base.revision(uri.database())
            else:  # postgres
                rev = versioning_base.pg_revision(uri.connectionInfo(),
                                                  uri.schema())
            QMessageBox.information(
                self.iface.mainWindow(), "Info", "Working "
                "copy already up to date with remote revision " +
                str(rev - 1) + ".")
Example #2
0
    def update(self):
        """merge modifiactions since last update into working copy"""
        print "update"
        if self.unresolved_conflicts():
            return
        layer = QgsMapLayerRegistry.instance().mapLayer(
                self.current_layers[0] )
        uri = QgsDataSourceURI(layer.source())

        late_by = 0

        if layer.providerType() == "spatialite":
            late_by = versioning_base.late(
                    uri.database(), self.pg_conn_info() )
        else: # postgres
            late_by = versioning_base.pg_late(
                    self.pg_conn_info(), uri.schema() )
        if late_by:
            if layer.providerType() == "spatialite":
                versioning_base.update( uri.database(), self.pg_conn_info() )
                rev = versioning_base.revision( uri.database() )
            else: # postgres
                versioning_base.pg_update( uri.connectionInfo(), uri.schema() )
                rev = versioning_base.pg_revision(
                        uri.connectionInfo(), uri.schema() )

            # Force refresh of map
            if self.iface.mapCanvas().isCachingEnabled():
                self.iface.mapCanvas().clearCache()
                self.iface.mapCanvas().refresh()
            else:
                self.iface.mapCanvas().refresh()

            # Force refresh of rev number in menu text
            if layer.providerType() == "spatialite":
                self.info.setText( uri.database().split("/")[-1] +' <b>working rev</b>='+str(rev))
            else:
                self.info.setText( uri.database() +' <b>working rev</b>='+str(rev))

            if not self.unresolved_conflicts():
                QMessageBox.warning( self.iface.mainWindow(), "Warning",
                "Working copy was late by "+str(late_by)+" revision(s).\n"
                "Now up to date with remote revision "+str(rev-1)+".")
        else:
            if layer.providerType() == "spatialite":
                rev = versioning_base.revision( uri.database() )
            else: # postgres
                rev = versioning_base.pg_revision(
                        uri.connectionInfo(), uri.schema() )
            QMessageBox.information( self.iface.mainWindow(), "Info","Working "
            "copy already up to date with remote revision "+str(rev-1)+".")
Example #3
0
    def commit(self):
        """merge modifiactions into database"""
        print "commit"
        if self.unresolved_conflicts():
            return

        layer = QgsMapLayerRegistry.instance().mapLayer(self.current_layers[0])
        uri = QgsDataSourceURI(layer.source())

        late_by = 0
        if layer.providerType() == "spatialite":
            late_by = versioning_base.late(uri.database(), self.pg_conn_info())
        else:  #postgres
            late_by = versioning_base.pg_late(self.pg_conn_info(),
                                              uri.schema())

        if late_by:
            QMessageBox.warning(
                self.iface.mainWindow(), "Warning",
                "This working copy is not up to date (late by " +
                str(late_by) + " commit(s)).\n\n"
                "Please update before commiting your modifications")
            print "aborted"
            return

        # time to get the commit message
        if not self.q_commit_msg_dlg.exec_():
            return
        commit_msg = self.commit_msg_dlg.commitMessage.document().toPlainText()
        if not commit_msg:
            QMessageBox.warning(self.iface.mainWindow(), "Warning",
                                "No commit message, aborting commit")
            print "aborted"
            return

        nb_of_updated_layer = 0
        rev = 0
        if layer.providerType() == "spatialite":
            nb_of_updated_layer = versioning_base.commit(
                uri.database(), commit_msg, self.pg_conn_info())
            rev = versioning_base.revision(uri.database())
        else:  # postgres
            nb_of_updated_layer = versioning_base.pg_commit(
                uri.connectionInfo(), uri.schema(), commit_msg)
            rev = versioning_base.pg_revision(uri.connectionInfo(),
                                              uri.schema())

        if nb_of_updated_layer:
            QMessageBox.information(
                self.iface.mainWindow(), "Info",
                "You have successfully commited revision " + str(rev))
        else:
            QMessageBox.information(self.iface.mainWindow(), "Info",
                                    "There was no modification to commit")
Example #4
0
    def commit(self):
        """merge modifiactions into database"""
        print "commit"
        if self.unresolved_conflicts():
            return

        layer = QgsMapLayerRegistry.instance().mapLayer(
                self.current_layers[0] )
        uri = QgsDataSourceURI(layer.source())

        late_by = 0
        if layer.providerType() == "spatialite":
            late_by = versioning_base.late(
                    uri.database(), self.pg_conn_info() )
        else:#postgres
            late_by = versioning_base.pg_late(
                    self.pg_conn_info(), uri.schema() )

        if late_by:
            QMessageBox.warning(self.iface.mainWindow(), "Warning",
                    "This working copy is not up to date (late by "
                    +str(late_by)+" commit(s)).\n\n"
                    "Please update before commiting your modifications")
            print "aborted"
            return

        # time to get the commit message
        if not self.q_commit_msg_dlg.exec_():
            return
        commit_msg = self.commit_msg_dlg.commitMessage.document().toPlainText()
        if not commit_msg:
            QMessageBox.warning(self.iface.mainWindow(), "Warning",
                    "No commit message, aborting commit")
            print "aborted"
            return

        nb_of_updated_layer = 0
        rev = 0
        if layer.providerType() == "spatialite":
            nb_of_updated_layer = versioning_base.commit( uri.database(),
                    commit_msg, self.pg_conn_info() )
            rev = versioning_base.revision(uri.database())
        else: # postgres
            nb_of_updated_layer = versioning_base.pg_commit(
                    uri.connectionInfo(), uri.schema(), commit_msg )
            rev = versioning_base.pg_revision(
                    uri.connectionInfo(), uri.schema())

        if nb_of_updated_layer:
            QMessageBox.information(self.iface.mainWindow(), "Info",
                    "You have successfully commited revision "+str( rev ) )
        else:
            QMessageBox.information(self.iface.mainWindow(), "Info",
                    "There was no modification to commit")
Example #5
0
    def update(self):
        """merge modifiactions since last update into working copy"""
        print "update"
        if self.unresolved_conflicts():
            return
        layer = QgsMapLayerRegistry.instance().mapLayer(self.current_layers[0])
        uri = QgsDataSourceURI(layer.source())

        if layer.providerType() == "spatialite":
            versioning_base.update(uri.database(), self.pg_conn_info())
            rev = versioning_base.revision(uri.database())
        else:  # postgres
            versioning_base.pg_update(uri.connectionInfo(), uri.schema())
            rev = versioning_base.pg_revision(uri.connectionInfo(), uri.schema())

        if not self.unresolved_conflicts():
            QMessageBox.information(
                self.iface.mainWindow(), "Notice", "Your are up to date with revision " + str(rev - 1) + "."
            )
Example #6
0
    def update(self):
        """merge modifiactions since last update into working copy"""
        print "update"
        if self.unresolved_conflicts():
            return
        layer = QgsMapLayerRegistry.instance().mapLayer(self.current_layers[0])
        uri = QgsDataSourceURI(layer.source())

        if layer.providerType() == "spatialite":
            versioning_base.update(uri.database(), self.pg_conn_info())
            rev = versioning_base.revision(uri.database())
        else:  # postgres
            versioning_base.pg_update(uri.connectionInfo(), uri.schema())
            rev = versioning_base.pg_revision(uri.connectionInfo(),
                                              uri.schema())

        if not self.unresolved_conflicts():
            QMessageBox.information(
                self.iface.mainWindow(), "Notice",
                "Your are up to date with revision " + str(rev - 1) + ".")
Example #7
0
    def commit(self):
        """merge modifications into database"""
        print "commit"
        if self.unresolved_conflicts():
            return

        layer = QgsMapLayerRegistry.instance().mapLayer(
                self.current_layers[0] )
        uri = QgsDataSourceURI(layer.source())

        late_by = 0
        if layer.providerType() == "spatialite":
            late_by = versioning_base.late(
                    uri.database(), self.pg_conn_info() )
        else:#postgres
            late_by = versioning_base.pg_late(
                    self.pg_conn_info(), uri.schema() )

        if late_by:
            QMessageBox.warning(self.iface.mainWindow(), "Warning",
                    "This working copy is not up to date (late by "
                    +str(late_by)+" commit(s)).\n\n"
                    "Please update before committing your modifications")
            print "aborted"
            return

        # Make sure the combobox is visible; could be made invisible by a
        # previous call to branch
        self.q_commit_msg_dlg.pg_users_combobox.setVisible(True)
        self.q_commit_msg_dlg.pg_username_label.setVisible(True)
        # Populate combobox with list of pg usernames
        nb_items_in_list = self.q_commit_msg_dlg.pg_users_combobox.count()
        if not(nb_items_in_list) :
            self.get_pg_users_list()
        # Better if we could have a QgsDataSourceURI.username() but no such
        # thing in spatialite.  Next block is for the case the username cannot
        # be found in the connection info string (mainly for plugin tests)
        try:
            pg_username = self.pg_conn_info().split(' ')[3].replace("'","").split('=')[1]
            current_user_index = self.q_commit_msg_dlg.pg_users_combobox.findText(pg_username)
            # sets the current pg_user in the combobox to come
            current_user_combobox_item = self.q_commit_msg_dlg.pg_users_combobox.setCurrentIndex(current_user_index)
        except (IndexError):
            pg_username = ''

        # time to get the commit message
        if not self.q_commit_msg_dlg.exec_():
            return
        commit_msg = self.q_commit_msg_dlg.commitMessage.document().toPlainText()
        commit_pg_user = self.q_commit_msg_dlg.pg_users_combobox.itemText(self.q_commit_msg_dlg.pg_users_combobox.currentIndex())

        if not commit_msg:
            QMessageBox.warning(self.iface.mainWindow(), "Warning",
                    "No commit message, aborting commit")
            print "aborted"
            return

        nb_of_updated_layer = 0
        rev = 0
        if layer.providerType() == "spatialite":
            nb_of_updated_layer = versioning_base.commit( uri.database(),
                    commit_msg, self.pg_conn_info(),commit_pg_user )
            rev = versioning_base.revision(uri.database())
        else: # postgres
            nb_of_updated_layer = versioning_base.pg_commit(
                    uri.connectionInfo(), uri.schema(), commit_msg )
            rev = versioning_base.pg_revision(
                    uri.connectionInfo(), uri.schema())

        if nb_of_updated_layer:
            #self.iface.messageBar().pushMessage("Info",
            #"You have successfully committed revision "+str( rev ), duration=10)
            QMessageBox.information(self.iface.mainWindow(), "Info",
            "You have successfully committed remote revision "+str( rev-1 ) )

            # Force refresh of rev number in menu text
            if layer.providerType() == "spatialite":
                self.info.setText( uri.database().split("/")[-1] +' <b>working rev</b>='+str(rev))
            else:
                self.info.setText( uri.database() +' <b>working rev</b>='+str(rev))
        else:
            #self.iface.messageBar().pushMessage("Info",
            #"There was no modification to commit", duration=10)
            QMessageBox.information(self.iface.mainWindow(), "Info",
            "There was no modification to commit")
Example #8
0
    def on_legend_click(self, current, column=0):
        "changes menu when user clicks on legend"
        self.current_group_idx = -1
        name = ''
        self.current_layers = []
        self.info.setText('Versioning : no group selected')
        for act in self.actions:
            if act.text() in ['checkout',
                              'update',
                              'commit',
                              'view',
                              'branch',
                              'historize' ]:
                act.setVisible(False)
        if current:
            try: # qgis 2.2
                name = current.text(0)
            except: #qgis 2.4
                name = current.data()
        # we could look if we have something in selected layers
        # but we prefer impose grouping, otherwise it'll be easy to make errors

        # need to get all layers including subgroups
        rel_map = {}
        for grp, lay in self.iface.legendInterface().groupLayerRelationship():
            rel_map[grp] = lay

        if not name or name not in rel_map: # not a group
            return

        group_idx = [i for i, x in
                enumerate(self.iface.legendInterface().groups()) if x == name]
        if len(group_idx) != 1:
            self.info.setText("Versioning : more than one group with this name")
            self.current_layers = []
            return
        [self.current_group_idx] = group_idx

        replaced = True
        while replaced:
            replaced = False
            for i, item in enumerate(rel_map[name]):
                if item in rel_map:
                    rel_map[name][i:i+1] = rel_map[item]
                    replaced = True

        self.current_layers = rel_map[name]
        # we should check that the selection is homogeneous
        previous_conn = ()
        for layer_id in self.current_layers:
            layer = QgsMapLayerRegistry.instance().mapLayer( layer_id )
            uri = QgsDataSourceURI(layer.source())
            if previous_conn:
                if (uri.database(), uri.schema()) != previous_conn:
                    self.current_layers = []
                    self.info.setText("Versioning : layers don't share db and schema")
                    return
            else:
                previous_conn = (uri.database(), uri.schema())

        if not self.current_layers:
            return

        if not len(previous_conn[0]):
            self.current_layers = []
            self.info.setText("Versioning : not versionable")
            return

        layer = QgsMapLayerRegistry.instance().mapLayer(
                self.current_layers[0] )
        uri = QgsDataSourceURI( layer.source() )
        selection_type = ''
        if layer.providerType() == "spatialite":
            rev = 0
            try:
                rev = versioning_base.revision( uri.database() )
            except:
                self.current_layers = []
                self.info.setText("Versioning : the selected group is not a working copy")
                return
            # We can split on "/" irrespective of OS because QgsDataSourceURI
            # normalises the path separator to "/"
            self.info.setText( uri.database().split("/")[-1] +' <b>working rev</b>='+str(rev))
            selection_type = 'working copy'
        if layer.providerType() == "postgres":
            mtch = re.match(r'(.+)_([^_]+)_rev_(head|\d+)', uri.schema())
            if mtch:
                self.info.setText(uri.database()+' '+mtch.group(1)
                        +' branch='+mtch.group(2)+' rev='+mtch.group(3))
                if mtch.group(3) == 'head':
                    selection_type = 'head'
                else:
                    selection_type = 'versioned'
            else:
                # check if it's a working copy
                rev = 0
                try:
                    rev = versioning_base.pg_revision( self.pg_conn_info(),
                                                       uri.schema() )
                    selection_type = 'working copy'
                    self.info.setText( uri.database()+' '+uri.schema()
                            +' <b>working rev</b>='+str(rev) )
                except:
                    self.info.setText('Versioning : unversioned schema')
                    selection_type = 'unversioned'


        # refresh the available commands
        assert( selection_type )
        if selection_type == 'unversioned':
            for act in self.actions:
                if act.text() == 'historize':
                    act.setVisible(True)
        elif selection_type == 'versioned':
            for act in self.actions:
                if act.text() in ['view', 'branch']:
                    act.setVisible(True)
        elif selection_type == 'head':
            for act in self.actions:
                if act.text() in ['checkout', 'view', 'branch']:
                    act.setVisible(True)
        elif selection_type == 'working copy':
            for act in self.actions:
                if act.text() in ['update', 'commit']:
                    act.setVisible(True)
Example #9
0
    def commit(self):
        """merge modifications into database"""
        print "commit"
        if self.unresolved_conflicts():
            return

        layer = QgsMapLayerRegistry.instance().mapLayer(self.current_layers[0])
        uri = QgsDataSourceURI(layer.source())

        late_by = 0
        if layer.providerType() == "spatialite":
            late_by = versioning_base.late(uri.database(), self.pg_conn_info())
        else:  #postgres
            late_by = versioning_base.pg_late(self.pg_conn_info(),
                                              uri.schema())

        if late_by:
            QMessageBox.warning(
                self.iface.mainWindow(), "Warning",
                "This working copy is not up to date (late by " +
                str(late_by) + " commit(s)).\n\n"
                "Please update before committing your modifications")
            print "aborted"
            return

        # Make sure the combobox is visible; could be made invisible by a
        # previous call to branch
        self.q_commit_msg_dlg.pg_users_combobox.setVisible(True)
        self.q_commit_msg_dlg.pg_username_label.setVisible(True)
        # Populate combobox with list of pg usernames
        nb_items_in_list = self.q_commit_msg_dlg.pg_users_combobox.count()
        if not (nb_items_in_list):
            self.get_pg_users_list()
        # Better if we could have a QgsDataSourceURI.username() but no such
        # thing in spatialite.  Next block is for the case the username cannot
        # be found in the connection info string (mainly for plugin tests)
        try:
            pg_username = self.pg_conn_info().split(' ')[3].replace(
                "'", "").split('=')[1]
            current_user_index = self.q_commit_msg_dlg.pg_users_combobox.findText(
                pg_username)
            # sets the current pg_user in the combobox to come
            current_user_combobox_item = self.q_commit_msg_dlg.pg_users_combobox.setCurrentIndex(
                current_user_index)
        except (IndexError):
            pg_username = ''

        # time to get the commit message
        if not self.q_commit_msg_dlg.exec_():
            return
        commit_msg = self.q_commit_msg_dlg.commitMessage.document(
        ).toPlainText()
        commit_pg_user = self.q_commit_msg_dlg.pg_users_combobox.itemText(
            self.q_commit_msg_dlg.pg_users_combobox.currentIndex())

        if not commit_msg:
            QMessageBox.warning(self.iface.mainWindow(), "Warning",
                                "No commit message, aborting commit")
            print "aborted"
            return

        nb_of_updated_layer = 0
        rev = 0
        if layer.providerType() == "spatialite":
            nb_of_updated_layer = versioning_base.commit(
                uri.database(), commit_msg, self.pg_conn_info(),
                commit_pg_user)
            rev = versioning_base.revision(uri.database())
        else:  # postgres
            nb_of_updated_layer = versioning_base.pg_commit(
                uri.connectionInfo(), uri.schema(), commit_msg)
            rev = versioning_base.pg_revision(uri.connectionInfo(),
                                              uri.schema())

        if nb_of_updated_layer:
            #self.iface.messageBar().pushMessage("Info",
            #"You have successfully committed revision "+str( rev ), duration=10)
            QMessageBox.information(
                self.iface.mainWindow(), "Info",
                "You have successfully committed remote revision " +
                str(rev - 1))

            # Force refresh of rev number in menu text
            if layer.providerType() == "spatialite":
                self.info.setText(uri.database().split("/")[-1] +
                                  ' <b>working rev</b>=' + str(rev))
            else:
                self.info.setText(uri.database() + ' <b>working rev</b>=' +
                                  str(rev))
        else:
            #self.iface.messageBar().pushMessage("Info",
            #"There was no modification to commit", duration=10)
            QMessageBox.information(self.iface.mainWindow(), "Info",
                                    "There was no modification to commit")
Example #10
0
    def on_legend_click(self, current, column=0):
        "changes menu when user clicks on legend"
        self.current_group_idx = -1
        name = ''
        self.current_layers = []
        self.info.setText('Versioning : no group selected')
        for act in self.actions:
            if act.text() in [
                    'checkout', 'update', 'commit', 'view', 'branch',
                    'historize'
            ]:
                act.setVisible(False)
        if current:
            try:  # qgis 2.2
                name = current.text(0)
            except:  #qgis 2.4
                name = current.data()
        # we could look if we have something in selected layers
        # but we prefer impose grouping, otherwise it'll be easy to make errors

        # need to get all layers including subgroups
        rel_map = {}
        for grp, lay in self.iface.legendInterface().groupLayerRelationship():
            rel_map[grp] = lay

        if not name or name not in rel_map:  # not a group
            return

        group_idx = [
            i for i, x in enumerate(self.iface.legendInterface().groups())
            if x == name
        ]
        if len(group_idx) != 1:
            self.info.setText(
                "Versioning : more than one group with this name")
            self.current_layers = []
            return
        [self.current_group_idx] = group_idx

        replaced = True
        while replaced:
            replaced = False
            for i, item in enumerate(rel_map[name]):
                if item in rel_map:
                    rel_map[name][i:i + 1] = rel_map[item]
                    replaced = True

        self.current_layers = rel_map[name]
        # we should check that the selection is homogeneous
        previous_conn = ()
        for layer_id in self.current_layers:
            layer = QgsMapLayerRegistry.instance().mapLayer(layer_id)
            uri = QgsDataSourceURI(layer.source())
            if previous_conn:
                if (uri.database(), uri.schema()) != previous_conn:
                    self.current_layers = []
                    self.info.setText(
                        "Versioning : layers don't share db and schema")
                    return
            else:
                previous_conn = (uri.database(), uri.schema())

        if not self.current_layers:
            return

        if not len(previous_conn[0]):
            self.current_layers = []
            self.info.setText("Versioning : not versionable")
            return

        layer = QgsMapLayerRegistry.instance().mapLayer(self.current_layers[0])
        uri = QgsDataSourceURI(layer.source())
        selection_type = ''
        if layer.providerType() == "spatialite":
            rev = 0
            try:
                rev = versioning_base.revision(uri.database())
            except:
                self.current_layers = []
                self.info.setText(
                    "Versioning : the selected group is not a working copy")
                return
            # We can split on "/" irrespective of OS because QgsDataSourceURI
            # normalises the path separator to "/"
            self.info.setText(uri.database().split("/")[-1] +
                              ' <b>working rev</b>=' + str(rev))
            selection_type = 'working copy'
        if layer.providerType() == "postgres":
            mtch = re.match(r'(.+)_([^_]+)_rev_(head|\d+)', uri.schema())
            if mtch:
                self.info.setText(uri.database() + ' ' + mtch.group(1) +
                                  ' branch=' + mtch.group(2) + ' rev=' +
                                  mtch.group(3))
                if mtch.group(3) == 'head':
                    selection_type = 'head'
                else:
                    selection_type = 'versioned'
            else:
                # check if it's a working copy
                rev = 0
                try:
                    rev = versioning_base.pg_revision(self.pg_conn_info(),
                                                      uri.schema())
                    selection_type = 'working copy'
                    self.info.setText(uri.database() + ' ' + uri.schema() +
                                      ' <b>working rev</b>=' + str(rev))
                except:
                    self.info.setText('Versioning : unversioned schema')
                    selection_type = 'unversioned'

        # refresh the available commands
        assert (selection_type)
        if selection_type == 'unversioned':
            for act in self.actions:
                if act.text() == 'historize':
                    act.setVisible(True)
        elif selection_type == 'versioned':
            for act in self.actions:
                if act.text() in ['view', 'branch']:
                    act.setVisible(True)
        elif selection_type == 'head':
            for act in self.actions:
                if act.text() in ['checkout', 'view', 'branch']:
                    act.setVisible(True)
        elif selection_type == 'working copy':
            for act in self.actions:
                if act.text() in ['update', 'commit']:
                    act.setVisible(True)
Example #11
0
    def on_legend_click(self, current, column=0):
        "changes menu when user click on legend"
        self.current_group_idx = -1
        name = ""
        self.current_layers = []
        self.info.setText("No group selected")
        for act in self.actions:
            if act.text() in ["checkout", "update", "commit", "view", "branch", "historize"]:
                act.setVisible(False)
        if current:
            try:  # qgis 2.2
                name = current.text(0)
            except:  # qgis 2.4
                name = current.data()
        # we could look if we have something in selected layers
        # but we prefer impose grouping, otherwize it'll be easy to make errors

        # need to get all layers including subgroups
        rel_map = {}
        for grp, lay in self.iface.legendInterface().groupLayerRelationship():
            rel_map[grp] = lay

        if not name or name not in rel_map:  # not a group
            return

        group_idx = [i for i, x in enumerate(self.iface.legendInterface().groups()) if x == name]
        if len(group_idx) != 1:
            self.info.setText("More than one group with this name")
            self.current_layers = []
            return
        [self.current_group_idx] = group_idx

        replaced = True
        while replaced:
            replaced = False
            for i, item in enumerate(rel_map[name]):
                if item in rel_map:
                    rel_map[name][i : i + 1] = rel_map[item]
                    replaced = True

        self.current_layers = rel_map[name]
        # we should check that the selection is homogeneous
        previous_conn = ()
        for layer_id in self.current_layers:
            layer = QgsMapLayerRegistry.instance().mapLayer(layer_id)
            uri = QgsDataSourceURI(layer.source())
            if previous_conn:
                if (uri.database(), uri.schema()) != previous_conn:
                    self.current_layers = []
                    self.info.setText("Layers don't share db and schema")
                    return
            else:
                previous_conn = (uri.database(), uri.schema())

        if not self.current_layers:
            return

        layer = QgsMapLayerRegistry.instance().mapLayer(self.current_layers[0])
        uri = QgsDataSourceURI(layer.source())
        selection_type = ""
        if layer.providerType() == "spatialite":
            rev = 0
            try:
                rev = versioning_base.revision(uri.database())
            except:
                self.current_layers = []
                self.info.setText("The selected group is not a working copy")
                return
            self.info.setText(uri.database() + " rev=" + str(rev))
            selection_type = "working copy"
        if layer.providerType() == "postgres":
            mtch = re.match(r"(.+)_([^_]+)_rev_(head|\d+)", uri.schema())
            if mtch:
                self.info.setText(
                    uri.database() + " " + mtch.group(1) + " branch=" + mtch.group(2) + " rev=" + mtch.group(3)
                )
                if mtch.group(3) == "head":
                    selection_type = "head"
                else:
                    selection_type = "versioned"
            else:
                # check if it's a working copy
                rev = 0
                try:
                    rev = versioning_base.pg_revision(self.pg_conn_info(), uri.schema())
                    selection_type = "working copy"
                    self.info.setText(uri.database() + " " + uri.schema() + " rev=" + str(rev))
                except:
                    self.info.setText("Unversioned schema")
                    selection_type = "unversioned"

        # refresh the available commands
        assert selection_type
        if selection_type == "unversioned":
            for act in self.actions:
                if act.text() == "historize":
                    act.setVisible(True)
        elif selection_type == "versioned":
            for act in self.actions:
                if act.text() in ["view", "branch"]:
                    act.setVisible(True)
        elif selection_type == "head":
            for act in self.actions:
                if act.text() in ["checkout", "view", "branch"]:
                    act.setVisible(True)
        elif selection_type == "working copy":
            for act in self.actions:
                if act.text() in ["update", "commit"]:
                    act.setVisible(True)