コード例 #1
0
 def update_auth(self, authcfg):
     """update the auth config."""
     conf = QgsAuthMethodConfig()
     QgsApplication.authManager().loadAuthenticationConfig(
         authcfg, conf, True)
     if conf.uri():
         self.gws_url = QUrl(conf.uri())
         self.authcfg = authcfg
         self.config.update({'authcfg': authcfg})
         with open(self.config_path, 'w') as fp:
             json.dump(self.config, fp)
     else:
         self.gws_url = None
         self.authcfg = None
コード例 #2
0
ファイル: qgisauth.py プロジェクト: nstoykov/g3w-admin
def sync(model):
    """Syncs the model with the QGIS data base"""

    kwargs = {
        'signal': post_delete,
        'receiver': sync_auth_delete,
        'sender': QgisAuth,
        'dispatch_uid': None
    }

    with temp_disconnect_signal(**kwargs):
        kwargs = {
        'signal': pre_delete,
        'receiver': check_layer_dependencies,
        'sender': QgisAuth,
        'dispatch_uid': None
        }
        with temp_disconnect_signal(**kwargs):
            model._objects.all().delete()

    am = QgsApplication.instance().authManager()

    kwargs = {
        'signal': post_save,
        'receiver': sync_auth_save,
        'sender': QgisAuth,
        'dispatch_uid': None
    }

    with temp_disconnect_signal(**kwargs):
        for authcfg in sorted(am.configIds()):
            c = QgsAuthMethodConfig()
            am.loadAuthenticationConfig(authcfg, c, True)
            model._objects.create(id=c.id(), name=c.name(), config=c.configMap(
            ), uri=c.uri(), version=c.version(), method=c.method())
コード例 #3
0
    def getConfig(self, auth_method_id):

        auth_cfg = QgsAuthMethodConfig()
        auth_mgr = QgsApplication.authManager()
        auth_mgr.loadAuthenticationConfig(auth_method_id, auth_cfg, True)

        # Default values
        username = None,
        password = None,
        url = "https://openapi-test.kartverket.no/v1/"

        if auth_cfg.id():
            username = auth_cfg.config('username', '')
            password = auth_cfg.config('password', '')

        if auth_cfg.uri():
            url = auth_cfg.uri()

        return url, username, password
コード例 #4
0
def get_mergin_auth():
    settings = QSettings()
    save_credentials = settings.value('Mergin/saveCredentials', 'false').lower() == 'true'
    mergin_url = settings.value('Mergin/server', MERGIN_URL)
    auth_manager = QgsApplication.authManager()
    if not save_credentials or not auth_manager.masterPasswordHashInDatabase():
        return mergin_url, '', ''

    authcfg = settings.value('Mergin/authcfg', None)
    cfg = QgsAuthMethodConfig()
    auth_manager.loadAuthenticationConfig(authcfg, cfg, True)
    url = cfg.uri()
    username = cfg.config('username')
    password = cfg.config('password')
    return url, username, password
コード例 #5
0
    def run(self):
        QgsMessageLog.logMessage(f"GeoRectifyTask.run, process: %s" %
                                 self.name,
                                 tag="OAW",
                                 level=Qgis.Info)
        try:
            self.set_status('running', 'started')

            input_tif = os.path.join(self.options["staging_folder"],
                                     self.name + ".tif")
            scripts_folder = os.path.join(QgsApplication.prefixPath(), "..",
                                          "Python37/Scripts")
            geo_rectify = GeoRectifyFactory.create(
                input=input_tif,
                qgis_scripts=scripts_folder,
                min_points=self.options["min_points"],
                gdal_threads=self.options["gdal_threads"])
            geo_rectify.on_progress += self.on_progress
            geo_rectify.process()

            auth_id = self.options["remote_authid"]
            auth_manager = QgsApplication.authManager()
            auth_cfg = QgsAuthMethodConfig()
            auth_manager.loadAuthenticationConfig(auth_id, auth_cfg, True)
            if auth_cfg.id():
                username = auth_cfg.config('username', '')
                password = auth_cfg.config('password', '')
                uri = auth_cfg.uri()
                # call FTP task
                QgsMessageLog.logMessage(f"GeoRectifyTask.run, URI: %s" %
                                         str(uri),
                                         tag="OAW",
                                         level=Qgis.Info)
                QgsMessageLog.logMessage(f"GeoRectifyTask.run, username: %s" %
                                         str(username),
                                         tag="OAW",
                                         level=Qgis.Info)
                QgsMessageLog.logMessage(f"GeoRectifyTask.run, password: %s" %
                                         "***********",
                                         tag="OAW",
                                         level=Qgis.Info)
                # upload file via SFTP
                output_tif = input_tif.replace(".tif", "_grf_fin.tif")
                remote_folder = self.options[
                    "remote_folder"] if "remote_folder" in self.options else "public"
                cnopts = pysftp.CnOpts()
                cnopts.hostkeys = None
                with pysftp.Connection(uri,
                                       username=username,
                                       password=password,
                                       cnopts=cnopts) as sftp:
                    with sftp.cd(remote_folder):
                        sftp.put(output_tif, remotepath=self.name + ".tif")

                # Remove intermediate file (if requested)
                if self.options["remove_file_after"] == Qt.Checked:
                    os.remove(output_tif)
                    QgsMessageLog.logMessage(
                        f"GeoRectifyTask.run, removing intermediate file: %s" %
                        output_tif,
                        tag="OAW",
                        level=Qgis.Info)
            else:
                raise Exception(
                    "Failed to extract information from the QGIS authentication manager using authid: %s"
                    % auth_id)
            self.set_status('completed', 'done')
        except Exception as e:
            self.exception = e
            self.set_status('failed', str(e))
            QgsMessageLog.logMessage(f"GeoRectifyTask.run, exception: %s" %
                                     str(e),
                                     tag="OAW",
                                     level=Qgis.Warning)
        self.handlers["on_completed"](self)
        QgsMessageLog.logMessage(f"GeoRectifyTask.run, result: %s" %
                                 self.status,
                                 tag="OAW",
                                 level=Qgis.Info)
        return self.status == 'completed'