def _setReposFolder(folder): global _oldReposPath global _tempReposPath _oldReposPath = config.getConfigValue(config.GENERAL, config.REPOS_FOLDER) reposPath = os.path.join(os.path.dirname(__file__), "data", "repos", folder) _tempReposPath = tempfile.mkdtemp() tempReposPath = os.path.join(_tempReposPath, "repos") shutil.copytree(reposPath, tempReposPath) config.setConfigValue(config.GENERAL, config.REPOS_FOLDER, tempReposPath)
def _removeUserConfig(): global _oldUserName global _configContent configFile = os.path.join(os.path.expanduser("~"), ".geogigconfig") if os.path.exists(configFile): with open(configFile) as f: _configContent = "".join(f.readlines()) os.unlink(configFile) else: _configContent = "" _oldUserName = config.getConfigValue(config.GENERAL, config.USERNAME) config.setConfigValue(config.GENERAL, config.USERNAME, "")
def commitLayer(layer): trackedLayer = getTrackingInfo(layer) try: repo = createRepository(trackedLayer.repoFolder, False) except Py4JConnectionException: QtGui.QApplication.restoreOverrideCursor() dlg = GatewayNotAvailableWhileEditingDialog(config.iface.mainWindow()) dlg.exec_() return QtGui.QApplication.restoreOverrideCursor() if layer.dataProvider().fieldNameIndex("geogigid") == -1: config.iface.messageBar().pushMessage( "Cannot update GeoGig repository. Layer has no 'geogigid' field", level=QgsMessageBar.WARNING, duration=4) return exported, charset = exportVectorLayer(layer) repo.importshp(exported, False, trackedLayer.layername, "geogigid", True, charset) unstaged = repo.difftreestats(geogig.HEAD, geogig.WORK_HEAD) total = 0 for counts in unstaged.values(): total += sum(counts) if total == 0: config.iface.messageBar().pushMessage( "No changes detected. Repository was already up to date", level=QgsMessageBar.INFO, duration=4) return dlg = CommitDialog(repo, config.iface.mainWindow()) dlg.exec_() try: repo.addandcommit(dlg.getMessage()) except UnconfiguredUserException, e: user = config.getConfigValue(config.GENERAL, config.USERNAME) email = config.getConfigValue(config.GENERAL, config.EMAIL) if not (user and email): configdlg = UserConfigDialog(config.iface.mainWindow()) configdlg.exec_() if configdlg.user is not None: user = configdlg.user email = configdlg.email config.setConfigValue(config.GENERAL, config.USERNAME, user) config.setConfigValue(config.GENERAL, config.EMAIL, email) else: return repo.config(geogig.USER_NAME, user, True) repo.config(geogig.USER_EMAIL, email, True) repo.commit(dlg.getMessage())
def commitLayer(layer): trackedLayer = getTrackingInfo(layer) try: repo = createRepository(trackedLayer.repoFolder, False) except Py4JConnectionException: QtGui.QApplication.restoreOverrideCursor() dlg = GatewayNotAvailableWhileEditingDialog(config.iface.mainWindow()) dlg.exec_() return QtGui.QApplication.restoreOverrideCursor() if layer.dataProvider().fieldNameIndex("geogigid") == -1: config.iface.messageBar().pushMessage("Cannot update GeoGig repository. Layer has no 'geogigid' field", level = QgsMessageBar.WARNING, duration = 4) return exported, charset = exportVectorLayer(layer) repo.importshp(exported, False, trackedLayer.layername, "geogigid", True, charset) unstaged = repo.difftreestats(geogig.HEAD, geogig.WORK_HEAD) total = 0 for counts in unstaged.values(): total += sum(counts) if total == 0: config.iface.messageBar().pushMessage("No changes detected. Repository was already up to date", level = QgsMessageBar.INFO, duration = 4) return dlg = CommitDialog(repo, config.iface.mainWindow()) dlg.exec_() try: repo.addandcommit(dlg.getMessage()) except UnconfiguredUserException, e: user = config.getConfigValue(config.GENERAL, config.USERNAME) email = config.getConfigValue(config.GENERAL, config.EMAIL) if not (user and email): configdlg = UserConfigDialog(config.iface.mainWindow()) configdlg.exec_() if configdlg.user is not None: user = configdlg.user email = configdlg.email config.setConfigValue(config.GENERAL, config.USERNAME, user) config.setConfigValue(config.GENERAL, config.EMAIL, email) else: return repo.config(geogig.USER_NAME, user, True) repo.config(geogig.USER_EMAIL, email, True) repo.commit(dlg.getMessage())
def configureUser(): user = config.getConfigValue(config.GENERAL, config.USERNAME) email = config.getConfigValue(config.GENERAL, config.EMAIL) if not (user and email): configdlg = UserConfigDialog(config.iface.mainWindow()) configdlg.exec_() if configdlg.user is not None: user = configdlg.user email = configdlg.email config.setConfigValue(config.GENERAL, config.USERNAME, user) config.setConfigValue(config.GENERAL, config.EMAIL, email) else: return con = PyQtConnectorDecorator() con.configglobal(geogig.USER_NAME, user) con.configglobal(geogig.USER_EMAIL, email)
def _restoreReposFolder(): config.setConfigValue(config.GENERAL, config.REPOS_FOLDER, _oldReposPath)
def _restoreUserConfig(): config.setConfigValue(config.GENERAL, config.USERNAME, _oldUserName) configFile = os.path.join(os.path.expanduser("~"), ".geogigconfig") with open(configFile, "w") as f: f.write(_configContent) _restoreReposFolder()