def _removeLayer(self): user, email = config.getUserInfo() if user is None: return self.repo.removetree(self.layer, user, email, self.branch) config.iface.messageBar().pushMessage("Layer correctly removed from repository", level = QgsMessageBar.INFO, duration = 5) layer = getProjectLayerForGeoGigLayer(self.repo.url, self.layer) if layer: branches = self.repo.branches() layerInRepo = False for branch in branches: layers = self.repo.trees(branch) if self.layer in layers: layerInRepo = True break if not layerInRepo: setAsNonRepoLayer(layer) tracking = getTrackingInfoForGeogigLayer(self.repo.url, self.layer) if tracking: removeTrackedLayer(tracking.source) #TODO remove triggers from layer repoWatcher.repoChanged.emit(self.repo)
def importClicked(self): if self.repo is None: self.repo = repository.repos[self.repoCombo.currentIndex()] if self.layer is None: text = self.layerCombo.currentText() self.layer = resolveLayer(text) user, email = config.getUserInfo() if user is None: self.close() return message = self.messageBox.toPlainText() branch = self.branchCombo.currentText() try: self.repo.importgeopkg(self.layer, branch, message, user, email, False) filename, layername = namesFromLayer(self.layer) self.repo.checkoutlayer(filename, layername, ref = branch) self.layer.reload() self.layer.triggerRepaint() except GeoGigException as e: iface.messageBar().pushMessage("Error", str(e), level=QgsMessageBar.CRITICAL, duration=5) self.close() return addTrackedLayer(self.layer, self.repo.url) self.ok = True iface.messageBar().pushMessage("Layer was correctly added to repository", level=QgsMessageBar.INFO, duration=5) self.close()
def mergeInto(self, mergeInto, branch): conflicts = self.repo.merge(branch, mergeInto) if conflicts: ret = QMessageBox.warning(iface.mainWindow(), "Conflict(s) found while syncing", "There are conflicts between local and remote changes.\n" "Do you want to continue and fix them?", QMessageBox.Yes | QMessageBox.No) if ret == QMessageBox.No: self.repo.closeTransaction(conflicts[0].transactionId) return dlg = ConflictDialog(conflicts) dlg.exec_() solved, resolvedConflicts = dlg.solved, dlg.resolvedConflicts if not solved: self.repo.closeTransaction(conflicts[0].transactionId) return for conflict, resolution in zip(conflicts, list(resolvedConflicts.values())): if resolution == ConflictDialog.LOCAL: conflict.resolveWithLocalVersion() elif resolution == ConflictDialog.REMOTE: conflict.resolveWithRemoteVersion() elif resolution == ConflictDialog.DELETE: conflict.resolveDeletingFeature() else: conflict.resolveWithNewFeature(resolution) user, email = config.getUserInfo() if user is None: return self.repo.commitAndCloseMergeAndTransaction(user, email, "Resolved merge conflicts", conflicts[0].transactionId) iface.messageBar().pushMessage("GeoGig", "Branch has been correctly merged", level=QgsMessageBar.INFO, duration=5) repoWatcher.repoChanged.emit(self.repo)
def pull(self): dlg = RemoteRefDialog(self.currentRepo) dlg.exec_() if dlg.remote is not None: conflicts = execute( lambda: self.currentRepo.pull(dlg.remote, dlg.branch)) if conflicts: ret = QMessageBox.warning( iface.mainWindow(), "Error while syncing", "There are conflicts between local and remote changes.\n" "Do you want to continue and fix them?", QMessageBox.Yes | QMessageBox.No) if ret == QMessageBox.No: self.currentRepo.closeTransaction( conflicts[0].transactionId) return dlg = ConflictDialog(conflicts) dlg.exec_() solved, resolvedConflicts = dlg.solved, dlg.resolvedConflicts if not solved: self.repo.closeTransaction(conflicts[0].transactionId) return for conflict, resolution in zip( conflicts, list(resolvedConflicts.values())): if resolution == ConflictDialog.LOCAL: conflict.resolveWithLocalVersion() elif resolution == ConflictDialog.REMOTE: conflict.resolveWithRemoteVersion() elif resolution == ConflictDialog.DELETE: conflict.resolveDeletingFeature() else: conflict.resolveWithNewFeature(resolution) user, email = config.getUserInfo() if user is None: return self.currentRepo.commitAndCloseMergeAndTransaction( user, email, "Resolved merge conflicts", conflicts[0].transactionId) config.iface.messageBar().pushMessage( "Changes have been correctly pulled from remote", level=QgsMessageBar.INFO, duration=5) repoWatcher.repoChanged.emit(self.currentRepo) else: config.iface.messageBar().pushMessage( "Changes have been correctly pulled from remote", level=QgsMessageBar.INFO, duration=5) repoWatcher.repoChanged.emit(self.currentRepo)
def importClicked(self): ret = QMessageBox.warning( config.iface.mainWindow(), 'Import warning', "Importing a layer will modify the original layer and might cause data loss.\n" "Make sure you have a backup copy of your layer before importing.\n" "Do you want to import the selected layer?", QMessageBox.Yes | QMessageBox.No) if ret == QMessageBox.No: return if self.repo is None: self.repo = repository.repos[self.repoCombo.currentIndex()] if self.layer is None: text = self.layerCombo.currentText() self.layer = layerFromName(text) user, email = config.getUserInfo() if user is None: self.close() return message = self.messageBox.toPlainText() or datetime.now().strftime( "%Y-%m-%d %H_%M_%S") branch = self.branchCombo.currentText() try: self.repo.importgeopkg(self.layer, branch, message, user, email, False) filename, layername = namesFromLayer(self.layer) self.repo.checkoutlayer(filename, layername, ref=branch) self.layer.reload() self.layer.triggerRepaint() except GeoGigException as e: iface.messageBar().pushMessage("Error", str(e), level=QgsMessageBar.CRITICAL, duration=5) self.close() return addTrackedLayer(self.layer, self.repo.url) self.ok = True iface.messageBar().pushMessage( "Layer was correctly added to repository", level=QgsMessageBar.INFO, duration=5) self.close()
def importClicked(self): ret = QMessageBox.warning(config.iface.mainWindow(), 'Import warning', "Importing a layer will modify the original layer and might cause data loss.\n" "Make sure you have a backup copy of your layer before importing.\n" "Do you want to import the selected layer?", QMessageBox.Yes | QMessageBox.No) if ret == QMessageBox.No: return if self.repo is None: self.repo = repository.repos[self.repoCombo.currentIndex()] if self.layer is None: text = self.layerCombo.currentText() self.layer = layerFromName(text) user, email = config.getUserInfo() if user is None: self.close() return message = self.messageBox.toPlainText() or datetime.now().strftime("%Y-%m-%d %H_%M_%S") branch = self.branchCombo.currentText() try: self.repo.importgeopkg(self.layer, branch, message, user, email, False) filename, layername = namesFromLayer(self.layer) self.repo.checkoutlayer(filename, layername, ref = branch) self.layer.reload() self.layer.triggerRepaint() except GeoGigException as e: iface.messageBar().pushMessage("Error", str(e), level=QgsMessageBar.CRITICAL, duration=5) self.close() return addTrackedLayer(self.layer, self.repo.url) self.ok = True iface.messageBar().pushMessage("Layer was correctly added to repository", level=QgsMessageBar.INFO, duration=5) self.close()
def pull(self): dlg = RemoteRefDialog(self.repo) dlg.exec_() if dlg.remote is not None: conflicts = execute(lambda: self.repo.pull(dlg.remote, dlg.branch)) if conflicts: ret = QMessageBox.warning(iface.mainWindow(), "Conflict(s) found while syncing", "There are conflicts between local repository and connection.\n" "Do you want to continue and fix them?", QMessageBox.Yes | QMessageBox.No) if ret == QMessageBox.No: self.repo.closeTransaction(conflicts[0].transactionId) return dlg = ConflictDialog(conflicts) dlg.exec_() solved, resolvedConflicts = dlg.solved, dlg.resolvedConflicts if not solved: self.repo.closeTransaction(conflicts[0].transactionId) return for conflict, resolution in zip(conflicts, list(resolvedConflicts.values())): if resolution == ConflictDialog.LOCAL: conflict.resolveWithLocalVersion() elif resolution == ConflictDialog.REMOTE: conflict.resolveWithRemoteVersion() elif resolution == ConflictDialog.DELETE: conflict.resolveDeletingFeature() else: conflict.resolveWithNewFeature(resolution) user, email = config.getUserInfo() if user is None: return self.repo.commitAndCloseMergeAndTransaction(user, email, "Resolved merge conflicts", conflicts[0].transactionId) config.iface.messageBar().pushMessage("Changes have been correctly pulled from the connection", level = QgsMessageBar.INFO, duration = 5) repoWatcher.repoChanged.emit(self.repo) else: config.iface.messageBar().pushMessage("Changes have been correctly pulled from the connection", level = QgsMessageBar.INFO, duration = 5) repoWatcher.repoChanged.emit(self.repo)
def mergeInto(self, mergeInto, branch): conflicts = self.repo.merge(branch, mergeInto) if conflicts: ret = QMessageBox.warning( iface.mainWindow(), "Conflict(s) found while syncing", "There are conflicts between local and remote changes.\n" "Do you want to continue and fix them?", QMessageBox.Yes | QMessageBox.No) if ret == QMessageBox.No: self.repo.closeTransaction(conflicts[0].transactionId) return dlg = ConflictDialog(conflicts) dlg.exec_() solved, resolvedConflicts = dlg.solved, dlg.resolvedConflicts if not solved: self.repo.closeTransaction(conflicts[0].transactionId) return for conflict, resolution in zip(conflicts, list(resolvedConflicts.values())): if resolution == ConflictDialog.LOCAL: conflict.resolveWithLocalVersion() elif resolution == ConflictDialog.REMOTE: conflict.resolveWithRemoteVersion() elif resolution == ConflictDialog.DELETE: conflict.resolveDeletingFeature() else: conflict.resolveWithNewFeature(resolution) user, email = config.getUserInfo() if user is None: return self.repo.commitAndCloseMergeAndTransaction( user, email, "Resolved merge conflicts", conflicts[0].transactionId) iface.messageBar().pushMessage("GeoGig", "Branch has been correctly merged", level=QgsMessageBar.INFO, duration=5) repoWatcher.repoChanged.emit(self.repo)
def syncLayer(layer): tracking = getTrackingInfo(layer) repo = Repository(tracking.repoUrl) filename, layername = namesFromLayer(layer) con = sqlite3.connect(filename) cursor = con.cursor() cursor.execute("SELECT * FROM %s_audit;" % layername) changes = bool(cursor.fetchall()) cursor.close() con.close() if changes: con = sqlite3.connect(filename) cursor = con.cursor() beforeAttrs = set(v[1] for v in cursor.execute("PRAGMA table_info('%s');" % layername)) afterAttrs = set( v[1] for v in cursor.execute("PRAGMA table_info('%s_audit');" % layername) if v[1] not in ["audit_timestamp", "audit_op"]) cursor.close() con.close() if beforeAttrs != afterAttrs: ret = QMessageBox.warning( iface.mainWindow(), "Cannot commit changes to repository", "The structure of attributes table has been modified.\n" "This type of change is not supported by GeoGig.", QMessageBox.Yes) return user, email = config.getUserInfo() if user is None: return dlg = CommitDialog(repo, layername) dlg.exec_() if dlg.branch is None: return if dlg.branch not in repo.branches(): commitId = getCommitId(layer) repo.createbranch(commitId, dlg.branch) mergeCommitId, importCommitId, conflicts, featureIds = repo.importgeopkg( layer, dlg.branch, dlg.message, user, email, True) if conflicts: ret = QMessageBox.warning( iface.mainWindow(), "Error while syncing", "There are conflicts between local and remote changes.\n" "Do you want to continue and fix them?", QMessageBox.Yes | QMessageBox.No) if ret == QMessageBox.No: repo.closeTransaction(conflicts[0].transactionId) return solved, resolvedConflicts = solveConflicts(conflicts) if not solved: repo.closeTransaction(conflicts[0].transactionId) return for conflict, resolution in zip(conflicts, list(resolvedConflicts.values())): if resolution == ConflictDialog.LOCAL: conflict.resolveWithLocalVersion() elif resolution == ConflictDialog.REMOTE: conflict.resolveWithRemoteVersion() elif resolution == ConflictDialog.DELETE: conflict.resolveDeletingFeature() else: conflict.resolveWithNewFeature(resolution) repo.commitAndCloseMergeAndTransaction(user, email, "Resolved merge conflicts", conflicts[0].transactionId) updateFeatureIds(repo, layer, featureIds) try: applyLayerChanges(repo, layer, importCommitId, mergeCommitId) except: QgsMessageLog.logMessage( "Database locked while syncing. Using full layer checkout instead", level=QgsMessageLog.CRITICAL) repo.checkoutlayer(tracking.geopkg, layername, None, mergeCommitId) commitdialog.suggestedMessage = "" else: branches = [] for branch in repo.branches(): trees = repo.trees(branch) if layername in trees: branches.append(branch) branch, ok = QInputDialog.getItem(iface.mainWindow(), "Sync", "Select branch to update from", branches, 0, False) if not ok: return commitId = getCommitId(layer) headCommitId = repo.revparse(branch) applyLayerChanges(repo, layer, commitId, headCommitId) layer.reload() layer.triggerRepaint() repoWatcher.repoChanged.emit(repo) iface.messageBar().pushMessage("GeoGig", "Layer has been correctly synchronized", level=QgsMessageBar.INFO, duration=5) repoWatcher.layerUpdated.emit(layer)