Example #1
2
    def view(self):
        """create view and import layers"""
        layer = QgsMapLayerRegistry.instance().mapLayer(
                self.current_layers[0] )
        uri = QgsDataSourceURI(layer.source())
        mtch = re.match(r'(.+)_([^_]+)_rev_(head|\d+)', uri.schema())
        schema = mtch.group(1)
        assert(schema)
        dlg = QDialog()
        layout = QVBoxLayout(dlg)
        button_box = QDialogButtonBox(dlg)
        button_box.setStandardButtons(
                QDialogButtonBox.Cancel|QDialogButtonBox.Ok)
        button_box.accepted.connect(dlg.accept)
        button_box.rejected.connect(dlg.reject)

        pcur = versioning_base.Db( psycopg2.connect(self.pg_conn_info()) )
        pcur.execute("SELECT rev, commit_msg, branch, date, author "
            "FROM "+schema+".revisions")
        revs = pcur.fetchall()
        pcur.close()
        tblw = QTableWidget( dlg )
        tblw.setRowCount(len(revs))
        tblw.setColumnCount(5)
        tblw.setSortingEnabled(True)
        tblw.setHorizontalHeaderLabels(['Revision', 'Commit Message',
                                      'Branch', 'Date', 'Author'])
        tblw.verticalHeader().setVisible(False)
        for i, rev in enumerate(revs):
            for j, item in enumerate(rev):
                tblw.setItem(i, j, QTableWidgetItem( str(item) ))
        layout.addWidget( tblw )
        layout.addWidget( button_box )
        dlg.resize( 600, 300 )
        if not dlg.exec_() :
            return

        rows = set()
        for i in tblw.selectedIndexes():
            rows.add(i.row())
        for row in rows:
            branch = revs[row][2]
            rev = revs[row][0]
            versioning_base.add_revision_view(uri.connectionInfo(),
                    schema, branch, rev )
            grp_name = branch+' revision '+str(rev)
            grp_idx = self.iface.legendInterface().addGroup( grp_name )
            for layer_id in reversed(self.current_layers):
                layer = QgsMapLayerRegistry.instance().mapLayer(layer_id)
                new_uri = QgsDataSourceURI(layer.source())
                new_uri.setDataSource(schema+'_'+branch+'_rev_'+str(rev),
                        new_uri.table(),
                        new_uri.geometryColumn(),
                        new_uri.sql(),
                        new_uri.keyColumn())
                display_name =  QgsMapLayerRegistry.instance().mapLayer(layer_id).name()
                src = new_uri.uri().replace('()','')
                new_layer = self.iface.addVectorLayer( src,
                        display_name, 'postgres')
                self.iface.legendInterface().moveLayer( new_layer, grp_idx)
Example #2
0
    def view(self):
        """create view and import layers"""
        layer = QgsMapLayerRegistry.instance().mapLayer(self.current_layers[0])
        uri = QgsDataSourceURI(layer.source())
        mtch = re.match(r'(.+)_([^_]+)_rev_(head|\d+)', uri.schema())
        schema = mtch.group(1)
        assert (schema)
        dlg = QDialog()
        layout = QVBoxLayout(dlg)
        button_box = QDialogButtonBox(dlg)
        button_box.setStandardButtons(QDialogButtonBox.Cancel
                                      | QDialogButtonBox.Ok)
        button_box.accepted.connect(dlg.accept)
        button_box.rejected.connect(dlg.reject)

        pcur = versioning_base.Db(psycopg2.connect(self.pg_conn_info()))
        pcur.execute("SELECT rev, commit_msg, branch, date, author "
                     "FROM " + schema + ".revisions")
        revs = pcur.fetchall()
        pcur.close()
        tblw = QTableWidget(dlg)
        tblw.setRowCount(len(revs))
        tblw.setColumnCount(5)
        tblw.setSortingEnabled(True)
        tblw.setHorizontalHeaderLabels(
            ['Revision', 'Commit Message', 'Branch', 'Date', 'Author'])
        tblw.verticalHeader().setVisible(False)
        for i, rev in enumerate(revs):
            for j, item in enumerate(rev):
                tblw.setItem(i, j, QTableWidgetItem(str(item)))
        layout.addWidget(tblw)
        layout.addWidget(button_box)
        dlg.resize(600, 300)
        if not dlg.exec_():
            return

        rows = set()
        for i in tblw.selectedIndexes():
            rows.add(i.row())
        for row in rows:
            branch = revs[row][2]
            rev = revs[row][0]
            versioning_base.add_revision_view(uri.connectionInfo(), schema,
                                              branch, rev)
            grp_name = branch + ' revision ' + str(rev)
            grp_idx = self.iface.legendInterface().addGroup(grp_name)
            for layer_id in reversed(self.current_layers):
                layer = QgsMapLayerRegistry.instance().mapLayer(layer_id)
                new_uri = QgsDataSourceURI(layer.source())
                new_uri.setDataSource(
                    schema + '_' + branch + '_rev_' + str(rev),
                    new_uri.table(), new_uri.geometryColumn(), new_uri.sql(),
                    new_uri.keyColumn())
                display_name = QgsMapLayerRegistry.instance().mapLayer(
                    layer_id).name()
                src = new_uri.uri().replace('()', '')
                new_layer = self.iface.addVectorLayer(src, display_name,
                                                      'postgres')
                self.iface.legendInterface().moveLayer(new_layer, grp_idx)
try:
    versioning_base.add_branch( pg_conn_info, 'epanet', 'mybranch', 'message', 'toto' )
except:
    failed = True
assert( failed )

versioning_base.add_branch( pg_conn_info, 'epanet', 'mybranch', 'test msg' )


pcur = versioning_base.Db(psycopg2.connect(pg_conn_info))
pcur.execute("SELECT * FROM epanet_mybranch_rev_head.junctions")
assert( len(pcur.fetchall()) == 2 )
pcur.execute("SELECT * FROM epanet_mybranch_rev_head.pipes")
assert( len(pcur.fetchall()) == 1 )

versioning_base.add_revision_view( pg_conn_info, 'epanet', 'mybranch', 2)
pcur.execute("SELECT * FROM epanet_mybranch_rev_2.junctions")
assert( len(pcur.fetchall()) == 2 )
pcur.execute("SELECT * FROM epanet_mybranch_rev_2.pipes")
assert( len(pcur.fetchall()) == 1 )

pcur.execute("SELECT ST_AsText(geometry), ST_AsText(geometry_schematic) FROM epanet_mybranch_rev_2.junctions")
res = pcur.fetchall()
assert( res[0][0] == 'POINT(0 0)' )
assert( res[1][1] == 'POLYGON((0 0,2 0,2 2,0 2,0 0))' )


wc = tmp_dir+'/wc_multiple_geometry_test.sqlite'
if os.path.isfile(wc): os.remove(wc) 
versioning_base.checkout( pg_conn_info, ['epanet_trunk_rev_head.pipes','epanet_trunk_rev_head.junctions'], wc )
Example #4
0
    def view(self):
        """create view and import layers"""
        layer = QgsMapLayerRegistry.instance().mapLayer(
                self.current_layers[0] )
        uri = QgsDataSourceURI(layer.source())
        mtch = re.match(r'(.+)_([^_]+)_rev_(head|\d+)', uri.schema())
        schema = mtch.group(1)
        assert(schema)
        dlg = QDialog()
        layout = QVBoxLayout(dlg)
        button_box = QDialogButtonBox(dlg)
        button_box.setStandardButtons(
                QDialogButtonBox.Cancel|QDialogButtonBox.Ok)
        button_box.accepted.connect(dlg.accept)
        button_box.rejected.connect(dlg.reject)

        user_msg1 = QgsMessageBar(dlg)
        user_msg1.pushInfo("Select:", "one [many] for single [multiple] "
        "revisions.  Fetching may take time.")

        pcur = versioning_base.Db( psycopg2.connect(self.pg_conn_info()) )
        pcur.execute("SELECT rev, commit_msg, branch, date, author "
            "FROM "+schema+".revisions")
        revs = pcur.fetchall()
        pcur.close()
        tblw = QTableWidget( dlg )
        tblw.setRowCount(len(revs))
        tblw.setColumnCount(6)
        tblw.setSortingEnabled(True)
        tblw.setHorizontalHeaderLabels(['Select','Revision', 'Commit Message',
                                      'Branch', 'Date', 'Author'])
        tblw.verticalHeader().setVisible(False)
        for i, rev in enumerate(revs):
            for j, item in enumerate(rev):
                chkBoxItem = QTableWidgetItem()
                chkBoxItem.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
                chkBoxItem.setCheckState(Qt.Unchecked)
                tblw.setItem(i, 0, chkBoxItem)
                tblw.setItem(i, j+1, QTableWidgetItem( str(item) ))

        layout.addWidget( user_msg1 )
        layout.addWidget( tblw )
        layout.addWidget( button_box )
        dlg.resize( 650, 300 )
        if not dlg.exec_() :
            return

        rows = set()
        revision_number_list = []
        for i in range(len(revs)):
            if  tblw.item(i,0).checkState():
                print "Revision "+ str(i + 1) +" will be fetched"
                revision_number_list.append(i + 1)
                rows.add(tblw.item(i,0).row())

        progressMessageBar = self.iface.messageBar().createMessage("Querying "
        "the database for revision(s) "+str(revision_number_list))
        progress = QProgressBar()
        progress.setMaximum(len(rows))
        progress.setAlignment(Qt.AlignLeft|Qt.AlignVCenter)
        progressMessageBar.layout().addWidget(progress)
        self.iface.messageBar().pushWidget(progressMessageBar, self.iface.messageBar().INFO)
        progress.setValue(0)

        for i, row in enumerate(rows):
            progress.setValue(i+1)
            branch = revs[row][2]
            rev = revs[row][0]
            versioning_base.add_revision_view(uri.connectionInfo(),
                    schema, branch, rev )
            grp_name = branch+' revision '+str(rev)
            grp_idx = self.iface.legendInterface().addGroup( grp_name )
            for layer_id in reversed(self.current_layers):
                layer = QgsMapLayerRegistry.instance().mapLayer(layer_id)
                new_uri = QgsDataSourceURI(layer.source())
                new_uri.setDataSource(schema+'_'+branch+'_rev_'+str(rev),
                        new_uri.table(),
                        new_uri.geometryColumn(),
                        new_uri.sql(),
                        new_uri.keyColumn())
                display_name =  QgsMapLayerRegistry.instance().mapLayer(layer_id).name()
                src = new_uri.uri().replace('()','')
                new_layer = self.iface.addVectorLayer( src,
                        display_name, 'postgres')
                self.iface.legendInterface().moveLayer( new_layer, grp_idx)
        self.iface.messageBar().clearWidgets()
Example #5
0
    def view(self):
        """create view and import layers"""
        layer = QgsMapLayerRegistry.instance().mapLayer(self.current_layers[0])
        uri = QgsDataSourceURI(layer.source())
        mtch = re.match(r'(.+)_([^_]+)_rev_(head|\d+)', uri.schema())
        schema = mtch.group(1)
        assert (schema)
        dlg = QDialog()
        layout = QVBoxLayout(dlg)
        button_box = QDialogButtonBox(dlg)
        button_box.setStandardButtons(QDialogButtonBox.Cancel
                                      | QDialogButtonBox.Ok)
        button_box.accepted.connect(dlg.accept)
        button_box.rejected.connect(dlg.reject)

        user_msg1 = QgsMessageBar(dlg)
        user_msg1.pushInfo(
            "Select:", "one [many] for single [multiple] "
            "revisions.  Fetching may take time.")

        pcur = versioning_base.Db(psycopg2.connect(self.pg_conn_info()))
        pcur.execute("SELECT rev, commit_msg, branch, date, author "
                     "FROM " + schema + ".revisions")
        revs = pcur.fetchall()
        pcur.close()
        tblw = QTableWidget(dlg)
        tblw.setRowCount(len(revs))
        tblw.setColumnCount(6)
        tblw.setSortingEnabled(True)
        tblw.setHorizontalHeaderLabels([
            'Select', 'Revision', 'Commit Message', 'Branch', 'Date', 'Author'
        ])
        tblw.verticalHeader().setVisible(False)
        for i, rev in enumerate(revs):
            for j, item in enumerate(rev):
                chkBoxItem = QTableWidgetItem()
                chkBoxItem.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
                chkBoxItem.setCheckState(Qt.Unchecked)
                tblw.setItem(i, 0, chkBoxItem)
                tblw.setItem(i, j + 1, QTableWidgetItem(str(item)))

        layout.addWidget(user_msg1)
        layout.addWidget(tblw)
        layout.addWidget(button_box)
        dlg.resize(650, 300)
        if not dlg.exec_():
            return

        rows = set()
        revision_number_list = []
        for i in range(len(revs)):
            if tblw.item(i, 0).checkState():
                print "Revision " + str(i + 1) + " will be fetched"
                revision_number_list.append(i + 1)
                rows.add(tblw.item(i, 0).row())

        progressMessageBar = self.iface.messageBar().createMessage(
            "Querying "
            "the database for revision(s) " + str(revision_number_list))
        progress = QProgressBar()
        progress.setMaximum(len(rows))
        progress.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
        progressMessageBar.layout().addWidget(progress)
        self.iface.messageBar().pushWidget(progressMessageBar,
                                           self.iface.messageBar().INFO)
        progress.setValue(0)

        for i, row in enumerate(rows):
            progress.setValue(i + 1)
            branch = revs[row][2]
            rev = revs[row][0]
            versioning_base.add_revision_view(uri.connectionInfo(), schema,
                                              branch, rev)
            grp_name = branch + ' revision ' + str(rev)
            grp_idx = self.iface.legendInterface().addGroup(grp_name)
            for layer_id in reversed(self.current_layers):
                layer = QgsMapLayerRegistry.instance().mapLayer(layer_id)
                new_uri = QgsDataSourceURI(layer.source())
                new_uri.setDataSource(
                    schema + '_' + branch + '_rev_' + str(rev),
                    new_uri.table(), new_uri.geometryColumn(), new_uri.sql(),
                    new_uri.keyColumn())
                display_name = QgsMapLayerRegistry.instance().mapLayer(
                    layer_id).name()
                src = new_uri.uri().replace('()', '')
                new_layer = self.iface.addVectorLayer(src, display_name,
                                                      'postgres')
                self.iface.legendInterface().moveLayer(new_layer, grp_idx)
        self.iface.messageBar().clearWidgets()