def historize(self): """version database""" uri = None conn_info = "" schema = "" for layer_id in self.current_layers: layer = QgsMapLayerRegistry.instance().mapLayer(layer_id) uri = QgsDataSourceURI(layer.source()) if not conn_info: conn_info = uri.connectionInfo() else: assert conn_info == uri.connectionInfo() if not schema: schema = uri.schema() else: assert schema == uri.schema() if QMessageBox.Ok != QMessageBox.warning( self.iface.mainWindow(), "Warning", "This will add 4 columns to all tables in schema " + schema + " (i.e. even to tables not in this project)", QMessageBox.Ok, QMessageBox.Cancel, ): print "aborted" return versioning_base.historize(self.pg_conn_info(), schema) grp_name = "trunk revision head" 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 + "_trunk_rev_head", 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.legendInterface().removeGroup(self.current_group_idx) self.current_layers = []
def historize(self): """version database""" uri = None conn_info = '' schema = '' for layer_id in self.current_layers: layer = QgsMapLayerRegistry.instance().mapLayer(layer_id) uri = QgsDataSourceURI(layer.source()) if not conn_info: conn_info = uri.connectionInfo() else: assert (conn_info == uri.connectionInfo()) if not schema: schema = uri.schema() else: assert (schema == uri.schema()) if QMessageBox.Ok != QMessageBox.warning( self.iface.mainWindow(), "Warning", "This will add 4 columns to all tables in schema " + schema + " (i.e. even to tables not in this project)", QMessageBox.Ok, QMessageBox.Cancel): print "aborted" return versioning_base.historize(self.pg_conn_info(), schema) grp_name = 'trunk revision head' 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 + '_trunk_rev_head', 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.legendInterface().removeGroup(self.current_group_idx) self.current_layers = []
roughness float, minor_loss_coefficient float, status varchar, geometry geometry('LINESTRING',2154) )""") pcur.execute(""" INSERT INTO epanet.pipes (id, start_node, end_node, length, diameter, geometry) VALUES ('0','0','1',1,2,ST_GeometryFromText('LINESTRING(1 0,0 1)',2154))""") pcur.commit() pcur.close() versioning_base.historize( pg_conn_info, 'epanet' ) failed = False try: versioning_base.add_branch( pg_conn_info, 'epanet', 'trunk' ) except: failed = True assert( failed ) failed = False try: versioning_base.add_branch( pg_conn_info, 'epanet', 'mybranch', 'message', 'toto' ) except: failed = True assert( failed )
from pyspatialite import dbapi2 import psycopg2 import os import shutil test_data_dir = os.path.dirname(os.path.realpath(__file__)) tmp_dir = "/tmp" # create the test database 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_unversioned.sql") versioning_base.historize("dbname=epanet_test_db","epanet") # try the update wc = tmp_dir+"/bug_in_branch_after_commit_wc.sqlite" if os.path.isfile(wc): os.remove(wc) versioning_base.checkout("dbname=epanet_test_db", ['epanet_trunk_rev_head.junctions', 'epanet_trunk_rev_head.pipes'], wc) scur = versioning_base.Db( dbapi2.connect( wc ) ) scur.execute("SELECT * FROM pipes") scur.execute("UPDATE pipes_view SET length = 1 WHERE OGC_FID = 1") scur.commit() versioning_base.commit(wc,'test', "dbname=epanet_test_db" ) versioning_base.add_branch("dbname=epanet_test_db","epanet","mybranch","add 'branch")