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 _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 initGui(self): readTrackedLayers() QgsMapLayerRegistry.instance().layerWasAdded.connect(trackLayer) icon = QtGui.QIcon(os.path.dirname(__file__) + "/ui/resources/versio-16.png") self.explorerAction = QtGui.QAction(icon, "GeoGig Navigator", self.iface.mainWindow()) self.explorerAction.triggered.connect(self.openNavigator) icon = QtGui.QIcon(os.path.dirname(__file__) + "/ui/resources/config.png") self.configAction = QtGui.QAction(icon, "GeoGig Settings", self.iface.mainWindow()) self.configAction.triggered.connect(self.openSettings) icon = QtGui.QIcon(os.path.dirname(__file__) + "/ui/resources/identify.png") self.toolAction = QtGui.QAction(icon, "GeoGig Feature Info Tool", self.iface.mainWindow()) self.toolAction.setCheckable(True) self.toolAction.triggered.connect(self.setTool) self.menu = QtGui.QMenu(self.iface.mainWindow()) self.menu.setTitle("GeoGig") self.menu.addAction(self.explorerAction) self.menu.addAction(self.toolAction) self.menu.addAction(self.configAction) bar = self.iface.layerToolBar() self.toolButton = QtGui.QToolButton() self.toolButton.setMenu(self.menu) self.toolButton.setPopupMode(QtGui.QToolButton.MenuButtonPopup) self.toolButton.setDefaultAction(self.explorerAction) useMainMenu = config.getConfigValue(config.GENERAL, config.USE_MAIN_MENUBAR) bar.addWidget(self.toolButton) if useMainMenu: menuBar = self.iface.mainWindow().menuBar() menuBar.insertMenu(self.iface.firstRightStandardMenu().menuAction(), self.menu) else: self.iface.addPluginToMenu(u"&GeoGig", self.explorerAction) self.iface.addPluginToMenu(u"&GeoGig", self.configAction) self.iface.addPluginToMenu(u"&GeoGig", self.toolAction) self.qgisHook = sys.excepthook; def pluginHook(t, value, tb): if isinstance(value, GeoGigException): trace = "".join(traceback.format_exception(t, value, tb)) logger.error(trace) self.setWarning(unicode(value)) elif isinstance(value, (Py4JConnectionException, Py4JNetworkError)): dlg = GatewayNotAvailableDialog(self.iface.mainWindow()) dlg.exec_() else: trace = "".join(traceback.format_exception(t, value, tb)) QgsMessageLog.logMessage(trace, "GeoGig", QgsMessageLog.CRITICAL) if "versio" in trace.lower(): dlg = GeoGigErrorDialog(trace, self.iface.mainWindow()) dlg.exec_() else: self.qgisHook(t, value, tb) sys.excepthook = pluginHook self.mapTool = MapToolGeoGigInfo(self.iface.mapCanvas())
def clone(url, dest, username = None, password = None): commands = ['clone', url, dest] if username is not None and password is not None: commands.extend(["--username", username, "--password", password]) port = config.getConfigValue(config.GENERAL, config.GATEWAY_PORT) setGatewayPort(port) try: execute(lambda: _runGateway(commands, os.path.dirname(__file__)), "Downloading repository data") except Py4JConnectionException: startGateway() execute(lambda: _runGateway(commands, os.path.dirname(__file__)), "Downloading repository data")
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 _startGateway(): if jrePath(): os.environ["JAVA_HOME"] = jrePath() if os.name == "nt": os.environ["JAVACMD"] = os.path.join(jrePath(), "bin", "java") global _proc if os.name == 'nt': _proc = subprocess.Popen([os.path.join(geogigPath() , "geogig-gateway.bat")], shell = True) else: _proc = subprocess.Popen(os.path.join(geogigPath(), "geogig-gateway"), stdout = subprocess.PIPE, stdin = subprocess.PIPE) port = config.getConfigValue(config.GENERAL, config.GATEWAY_PORT) gateway = JavaGateway(GatewayClient(port = int(port))) success = False retries = int(config.getConfigValue(config.GENERAL, config.TIMEOUT)) for i in range(retries): try: gateway.entry_point.isGeoGigServer() success = True break except Exception, e: time.sleep(1)
def execute(func, message=None): global _dialog cursor = QtGui.QApplication.overrideCursor() waitCursor = (cursor is not None and cursor.shape() == QtCore.Qt.WaitCursor) dialogCreated = False try: QtCore.QCoreApplication.processEvents() if not waitCursor: QtGui.QApplication.setOverrideCursor( QtGui.QCursor(QtCore.Qt.WaitCursor)) useThread = config.getConfigValue(config.GENERAL, config.USE_THREAD) if message is not None and useThread: t = GeoGigThread(func) loop = QtCore.QEventLoop() t.finished.connect(loop.exit, QtCore.Qt.QueuedConnection) if _dialog is None: dialogCreated = True _dialog = QtGui.QProgressDialog(message, "GeoGig", 0, 0, config.iface.mainWindow()) _dialog.setWindowTitle("GeoGig") _dialog.setWindowModality(QtCore.Qt.WindowModal) _dialog.setMinimumDuration(1000) _dialog.setMaximum(100) _dialog.setValue(0) _dialog.setMaximum(0) _dialog.setCancelButton(None) else: oldText = _dialog.labelText() _dialog.setLabelText(message) QtGui.QApplication.processEvents() t.start() loop.exec_(flags=QtCore.QEventLoop.ExcludeUserInputEvents) if t.exception is not None: raise t.exception return t.returnValue else: return func() finally: if message is not None and useThread: if dialogCreated: _dialog.reset() _dialog = None else: _dialog.setLabelText(oldText) if not waitCursor: QtGui.QApplication.restoreOverrideCursor() QtCore.QCoreApplication.processEvents()
def execute(func, message = None): global _dialog cursor = QtGui.QApplication.overrideCursor() waitCursor = (cursor is not None and cursor.shape() == QtCore.Qt.WaitCursor) dialogCreated = False try: QtCore.QCoreApplication.processEvents() if not waitCursor: QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor)) useThread = config.getConfigValue(config.GENERAL, config.USE_THREAD) if message is not None and useThread: t = GeoGigThread(func) loop = QtCore.QEventLoop() t.finished.connect(loop.exit, QtCore.Qt.QueuedConnection) if _dialog is None: dialogCreated = True _dialog = QtGui.QProgressDialog(message, "GeoGig", 0, 0, config.iface.mainWindow()) _dialog.setWindowTitle("GeoGig") _dialog.setWindowModality(QtCore.Qt.WindowModal); _dialog.setMinimumDuration(1000) _dialog.setMaximum(100) _dialog.setValue(0) _dialog.setMaximum(0) _dialog.setCancelButton(None) else: oldText = _dialog.labelText() _dialog.setLabelText(message) QtGui.QApplication.processEvents() t.start() loop.exec_(flags = QtCore.QEventLoop.ExcludeUserInputEvents) if t.exception is not None: raise t.exception return t.returnValue else: return func() finally: if message is not None and useThread: if dialogCreated: _dialog.reset() _dialog = None else: _dialog.setLabelText(oldText) if not waitCursor: QtGui.QApplication.restoreOverrideCursor() QtCore.QCoreApplication.processEvents()
def initGui(self): readTrackedLayers() QgsMapLayerRegistry.instance().layerWasAdded.connect(trackLayer) QgsMapLayerRegistry.instance().layerRemoved.connect(layerRemoved) icon = QtGui.QIcon( os.path.dirname(__file__) + "/ui/resources/geogig-16.png") self.explorerAction = navigatorInstance.toggleViewAction() self.explorerAction.setIcon(icon) self.explorerAction.setText("GeoGig Navigator") icon = QtGui.QIcon( os.path.dirname(__file__) + "/ui/resources/config.png") self.configAction = QtGui.QAction(icon, "GeoGig Settings", self.iface.mainWindow()) self.configAction.triggered.connect(self.openSettings) icon = QtGui.QIcon( os.path.dirname(__file__) + "/ui/resources/identify.png") self.toolAction = QtGui.QAction(icon, "GeoGig Feature Info Tool", self.iface.mainWindow()) self.toolAction.setCheckable(True) self.toolAction.triggered.connect(self.setTool) self.menu = QtGui.QMenu(self.iface.mainWindow()) self.menu.setTitle("GeoGig") self.menu.addAction(self.explorerAction) self.menu.addAction(self.toolAction) self.menu.addAction(self.configAction) bar = self.iface.layerToolBar() self.toolButton = QtGui.QToolButton() self.toolButton.setMenu(self.menu) self.toolButton.setPopupMode(QtGui.QToolButton.MenuButtonPopup) self.toolButton.setDefaultAction(self.explorerAction) useMainMenu = config.getConfigValue(config.GENERAL, config.USE_MAIN_MENUBAR) bar.addWidget(self.toolButton) if useMainMenu: menuBar = self.iface.mainWindow().menuBar() menuBar.insertMenu( self.iface.firstRightStandardMenu().menuAction(), self.menu) else: self.iface.addPluginToMenu(u"&GeoGig", self.explorerAction) self.iface.addPluginToMenu(u"&GeoGig", self.configAction) self.iface.addPluginToMenu(u"&GeoGig", self.toolAction) self.qgisHook = sys.excepthook def pluginHook(t, value, tb): if isinstance(value, GeoGigException): trace = "".join(traceback.format_exception(t, value, tb)) logger.error(trace) self.setWarning(unicode(value)) elif isinstance(value, (Py4JConnectionException, Py4JNetworkError)): dlg = GatewayNotAvailableDialog(self.iface.mainWindow()) dlg.exec_() else: trace = "".join(traceback.format_exception(t, value, tb)) QgsMessageLog.logMessage(trace, "GeoGig", QgsMessageLog.CRITICAL) if "geogig" in trace.lower(): dlg = GeoGigErrorDialog(trace, self.iface.mainWindow()) dlg.exec_() else: self.qgisHook(t, value, tb) sys.excepthook = pluginHook self.mapTool = MapToolGeoGigInfo(self.iface.mapCanvas()) #This crashes QGIS, so we comment it out until finding a solution #self.mapTool.setAction(self.toolAction) self.iface.addDockWidget(QtCore.Qt.RightDockWidgetArea, navigatorInstance)
def initGui(self): readTrackedLayers() QgsMapLayerRegistry.instance().layerWasAdded.connect(trackLayer) QgsMapLayerRegistry.instance().layerRemoved.connect(layerRemoved) icon = QIcon(os.path.dirname(__file__) + "/ui/resources/geogig.png") self.explorerAction = navigatorInstance.toggleViewAction() self.explorerAction.setIcon(icon) self.explorerAction.setText("GeoGig Navigator") icon = QIcon(os.path.dirname(__file__) + "/ui/resources/config.png") self.configAction = QAction(icon, "GeoGig Settings", self.iface.mainWindow()) self.configAction.triggered.connect(self.openSettings) icon = QIcon(os.path.dirname(__file__) + "/ui/resources/identify.png") self.toolAction = QAction(icon, "GeoGig Feature Info Tool", self.iface.mainWindow()) self.toolAction.setCheckable(True) self.toolAction.triggered.connect(self.setTool) helpIcon = QgsApplication.getThemeIcon('/mActionHelpAPI.png') self.helpAction = QAction(helpIcon, "GeoGig Plugin Help", self.iface.mainWindow()) self.helpAction.setObjectName("GeoGigHelp") self.helpAction.triggered.connect( lambda: webbrowser.open_new("file://" + os.path.join( os.path.dirname(__file__), "docs", "html", "index.html"))) self.menu = QMenu(self.iface.mainWindow()) self.menu.setTitle("GeoGig") self.menu.addAction(self.explorerAction) self.menu.addAction(self.toolAction) self.menu.addAction(self.configAction) self.menu.addAction(self.helpAction) bar = self.iface.layerToolBar() self.toolButton = QToolButton() self.toolButton.setMenu(self.menu) self.toolButton.setPopupMode(QToolButton.MenuButtonPopup) self.toolButton.setDefaultAction(self.explorerAction) useMainMenu = config.getConfigValue(config.GENERAL, config.USE_MAIN_MENUBAR) bar.addWidget(self.toolButton) if useMainMenu: menuBar = self.iface.mainWindow().menuBar() menuBar.insertMenu( self.iface.firstRightStandardMenu().menuAction(), self.menu) else: self.iface.addPluginToMenu(u"&GeoGig", self.explorerAction) self.iface.addPluginToMenu(u"&GeoGig", self.configAction) self.iface.addPluginToMenu(u"&GeoGig", self.toolAction) self.mapTool = MapToolGeoGigInfo(self.iface.mapCanvas()) #This crashes QGIS, so we comment it out until finding a solution #self.mapTool.setAction(self.toolAction) self.iface.addDockWidget(Qt.RightDockWidgetArea, navigatorInstance) try: from lessons import addLessonsFolder folder = os.path.join(os.path.dirname(__file__), "_lessons") addLessonsFolder(folder, "geogig") except Exception as e: pass
def runDecorated(self, func, progressMessage = None): port = config.getConfigValue(config.GENERAL, config.GATEWAY_PORT) setGatewayPort(port) if not self._showProgress: progressMessage = None return execute(func, progressMessage)
def __log(self, url, response, params, operation="GET"): if getConfigValue(GENERAL, LOG_SERVER_CALLS): msg = "%s: %s\nPARAMS: %s\nRESPONSE: %s" % (operation, url, params, response) QgsMessageLog.logMessage(msg, 'GeoGig', QgsMessageLog.INFO)
def parentReposFolder(): folder = config.getConfigValue(config.GENERAL, config.REPOS_FOLDER) if folder.strip() == "": folder = os.path.join(os.path.expanduser('~'), 'geogig', 'repos') mkdir(folder) return folder