Example #1
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 #2
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 #3
0
assert (len(pcur.fetchall()) == 1)

prtTab(pcur, 'epanet.pipes')
prtTab(pcur, 'epanet_working_copy.pipes_diff')
pcur.execute(
    "UPDATE epanet_working_copy.pipes_view SET length = 4 WHERE pid = 1")
prtTab(pcur, 'epanet_working_copy.pipes_diff')
pcur.execute(
    "UPDATE epanet_working_copy.pipes_view SET length = 5 WHERE pid = 4")
prtTab(pcur, 'epanet_working_copy.pipes_diff')

pcur.execute("DELETE FROM epanet_working_copy.pipes_view WHERE pid = 4")
pcur.commit()
prtTab(pcur, 'epanet_working_copy.pipes_diff')

versioning_base.pg_commit("dbname=epanet_test_db", "epanet_working_copy",
                          "test commit msg")
prtTab(pcur, 'epanet.pipes')

pcur.execute("SELECT trunk_rev_end FROM epanet.pipes WHERE pid = 1")
assert (1 == pcur.fetchone()[0])
pcur.execute("SELECT COUNT(*) FROM epanet.pipes WHERE trunk_rev_begin = 2")
assert (2 == pcur.fetchone()[0])

# modify the second working copy to create conflict
prtTab(pcur, 'epanet.pipes')
pcur.execute("SELECT * FROM epanet_working_copy_cflt.initial_revision")
print '-- epanet_working_copy_cflt.initial_revision ---'
for r in pcur.fetchall():
    print r

prtHid(pcur, 'epanet_working_copy_cflt.pipes_view')
Example #4
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 #5
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")
for resolution in ['theirs','mine']:
    os.system("dropdb epanet_test_db")
    os.system("createdb epanet_test_db")
    os.system("psql epanet_test_db -c 'CREATE EXTENSION postgis'")
    os.system("psql epanet_test_db -f "+test_data_dir+"/epanet_test_db.sql")

    pcur = versioning_base.Db(psycopg2.connect("dbname=epanet_test_db"))

    tables = ['epanet_trunk_rev_head.junctions', 'epanet_trunk_rev_head.pipes']
    versioning_base.pg_checkout("dbname=epanet_test_db",tables, "wc1")
    versioning_base.pg_checkout("dbname=epanet_test_db",tables, "wc2")

    pcur.execute("UPDATE wc1.pipes_view SET length = 4 WHERE pid = 1")
    pcur.commit()
    prtTab( pcur, "wc1.pipes_diff")
    versioning_base.pg_commit("dbname=epanet_test_db","wc1","msg1")

    pcur.execute("UPDATE wc2.pipes_view SET length = 5 WHERE pid = 1")
    pcur.commit()
    prtTab( pcur, "wc2.pipes_diff")
    versioning_base.pg_update("dbname=epanet_test_db","wc2")
    prtTab( pcur, "wc2.pipes_diff")
    prtTab( pcur, "wc2.pipes_conflicts")

    pcur.execute("SELECT COUNT(*) FROM wc2.pipes_conflicts WHERE origin = 'mine'")
    assert( 1 == pcur.fetchone()[0] )
    pcur.execute("SELECT COUNT(*) FROM wc2.pipes_conflicts WHERE origin = 'theirs'")
    assert( 1 == pcur.fetchone()[0] )

    pcur.execute("DELETE FROM wc2.pipes_conflicts WHERE origin = '"+resolution+"'")
    prtTab( pcur, "wc2.pipes_conflicts")
pcur.execute("SELECT pid FROM epanet.pipes")
assert( len(pcur.fetchall()) == 1 )


prtTab(pcur, 'epanet.pipes')
prtTab(pcur, 'epanet_working_copy.pipes_diff')
pcur.execute("UPDATE epanet_working_copy.pipes_view SET length = 4 WHERE pid = 1")
prtTab(pcur, 'epanet_working_copy.pipes_diff')
pcur.execute("UPDATE epanet_working_copy.pipes_view SET length = 5 WHERE pid = 4")
prtTab(pcur, 'epanet_working_copy.pipes_diff')

pcur.execute("DELETE FROM epanet_working_copy.pipes_view WHERE pid = 4")
pcur.commit()
prtTab(pcur, 'epanet_working_copy.pipes_diff')

versioning_base.pg_commit("dbname=epanet_test_db", "epanet_working_copy","test commit msg")
prtTab(pcur, 'epanet.pipes')

pcur.execute("SELECT trunk_rev_end FROM epanet.pipes WHERE pid = 1")
assert( 1 == pcur.fetchone()[0] )
pcur.execute("SELECT COUNT(*) FROM epanet.pipes WHERE trunk_rev_begin = 2")
assert( 2 == pcur.fetchone()[0] )


# modify the second working copy to create conflict
prtTab(pcur, 'epanet.pipes')
pcur.execute("SELECT * FROM epanet_working_copy_cflt.initial_revision")
print '-- epanet_working_copy_cflt.initial_revision ---'
for r in pcur.fetchall(): print r

prtHid(pcur, 'epanet_working_copy_cflt.pipes_view')