Exemplo n.º 1
0
 def initAlgorithm(self, config=None):
     db_param = QgsProcessingParameterProviderConnection(
         self.DATABASE, self.tr('Database (connection name)'), 'postgres')
     self.addParameter(db_param)
     self.addParameter(
         QgsProcessingParameterString(self.SQL,
                                      self.tr('SQL query'),
                                      multiLine=True))
Exemplo n.º 2
0
    def initAlgorithm(self, config):
        # LizSync config file from ini
        ls = lizsyncConfig()

        # INPUTS

        # Central database connection name
        connection_name = ls.variable('postgresql:central/name')
        label = tr('PostgreSQL connection to the central database')
        if Qgis.QGIS_VERSION_INT >= 31400:
            param = QgsProcessingParameterProviderConnection(
                self.CONNECTION_NAME,
                label,
                "postgres",
                defaultValue=connection_name,
                optional=False,
            )
        else:
            param = QgsProcessingParameterString(self.CONNECTION_NAME,
                                                 label,
                                                 defaultValue=connection_name,
                                                 optional=False)
            param.setMetadata({
                'widget_wrapper': {
                    'class':
                    'processing.gui.wrappers_postgis.ConnectionWidgetWrapper'
                }
            })
        tooltip = tr('The PostgreSQL connection to the central database.')
        tooltip += tr(
            ' You need to have the right to create a new schema in this database,'
            ' as a schema lizsync will be created and filled with the needed tables and functions'
        )
        if Qgis.QGIS_VERSION_INT >= 31600:
            param.setHelp(tooltip)
        else:
            param.tooltip_3liz = tooltip
        self.addParameter(param)

        # Checkbox needed to be check to run the upgrade
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.RUNIT,
                tr('Check this box to upgrade. No action will be done otherwise'
                   ),
                defaultValue=False,
                optional=False))

        # OUTPUTS
        # Add output for status (integer) and message (string)
        self.addOutput(
            QgsProcessingOutputNumber(self.OUTPUT_STATUS, tr('Output status')))
        self.addOutput(
            QgsProcessingOutputString(self.OUTPUT_STRING,
                                      tr('Output message')))
    def initAlgorithm(self, config=None):
        # Database Connection
        if qgs_version < 31400:
            db_param = QgsProcessingParameterString(
                self.DATABASE,
                self.tr('Database Connection'))
            db_param.setMetadata({
                'widget_wrapper': {
                    'class': 'processing.gui.wrappers_postgis.ConnectionWidgetWrapper'}})
        else:
            db_param = QgsProcessingParameterProviderConnection(
                self.DATABASE,
                self.tr('Database Connection'),
                'postgres')

        self.addParameter(db_param)

        # Schema
        if qgs_version < 31400:
            schema_param = QgsProcessingParameterString(
                self.SCHEMA,
                self.tr('Schema'), 'bc250_base')
            schema_param.setMetadata({
                'widget_wrapper': {
                    'class': 'processing.gui.wrappers_postgis.SchemaWidgetWrapper',
                    'connection_param': self.DATABASE}})
        else:
            schema_param = QgsProcessingParameterDatabaseSchema(
                self.SCHEMA,
                self.tr('Schema'), 
                defaultValue='bc250_base', 
                connectionParameterName=self.DATABASE)

        self.addParameter(schema_param) 
        
        # Prefixo (nome do projeto)
        prefix_param = QgsProcessingParameterString(
            self.PREFIX,
            'Prefixo (nome do projeto)', '', False, True)
        self.addParameter(prefix_param)

        # featuretypes URL
        self.addParameter(QgsProcessingParameterString(
            self.URL,
            "URL"))

        # Geoserver user            
        self.addParameter(QgsProcessingParameterString(
            self.USER,
            "User",
            "admin"))    

        # Geoserver password
        self.addParameter(QgsProcessingParameterString(
            self.PASSWORD,
            "Password",
            "geoserver"))
    def initAlgorithm(self, config):
        connection_name = QgsExpressionContextUtils.globalScope().variable(
            "veloroutes_connection_name")
        label = tr("Connexion PostgreSQL vers la base de données")
        tooltip = 'Nom de la connexion dans QGIS pour se connecter à la base de données'
        if Qgis.QGIS_VERSION_INT >= 31400:
            param = QgsProcessingParameterProviderConnection(
                self.CONNECTION_NAME,
                label,
                "postgres",
                defaultValue=connection_name,
                optional=False,
            )
        else:
            param = QgsProcessingParameterString(
                self.CONNECTION_NAME,
                label,
                defaultValue=connection_name,
                optional=False,
            )
            param.setMetadata({
                "widget_wrapper": {
                    "class":
                    "processing.gui.wrappers_postgis.ConnectionWidgetWrapper"
                }
            })
        if Qgis.QGIS_VERSION_INT >= 31600:
            param.setHelp(tooltip)
        else:
            param.tooltip_3liz = tooltip
        self.addParameter(param)

        self.addParameter(
            QgsProcessingParameterBoolean(
                self.OVERRIDE,
                tr("Écraser le schéma {} ? ** ATTENTION ** "
                   "Cela supprimera toutes les données !").format(SCHEMA),
                defaultValue=False,
                optional=False,
            ))
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.ADD_TEST_DATA,
                tr("Ajouter des données de test ?"),
                defaultValue=False,
                optional=False,
            ))

        self.addOutput(
            QgsProcessingOutputString(self.DATABASE_VERSION,
                                      "Version de la base de données"))
Exemplo n.º 5
0
    def initAlgorithm(self, config=None):
        # Database Connection
        if qgs_version < 31400:
            db_param = QgsProcessingParameterString(
                self.DATABASE, self.tr('Database Connection'))
            db_param.setMetadata({
                'widget_wrapper': {
                    'class':
                    'processing.gui.wrappers_postgis.ConnectionWidgetWrapper'
                }
            })
        else:
            db_param = QgsProcessingParameterProviderConnection(
                self.DATABASE, self.tr('Database Connection'), 'postgres')

        self.addParameter(db_param)

        # Schema
        if qgs_version < 31400:
            schema_param = QgsProcessingParameterString(
                self.SCHEMA, self.tr('Schema'), 'bc250_base')
            schema_param.setMetadata({
                'widget_wrapper': {
                    'class':
                    'processing.gui.wrappers_postgis.SchemaWidgetWrapper',
                    'connection_param': self.DATABASE
                }
            })
        else:
            schema_param = QgsProcessingParameterDatabaseSchema(
                self.SCHEMA,
                self.tr('Schema'),
                defaultValue='bc250_base',
                connectionParameterName=self.DATABASE)

        self.addParameter(schema_param)

        # Shapefile used to clip
        self.addParameter(
            QgsProcessingParameterFile(self.SHAPEFILE_CLIP,
                                       self.tr('Clip Shapefile'),
                                       extension='shp',
                                       optional=True))

        # Shapefile folder
        self.addParameter(
            QgsProcessingParameterFile(self.SHAPEFILE_FOLDER,
                                       self.tr('Shapefile Folder'),
                                       1,
                                       'shp',
                                       optional=False))
Exemplo n.º 6
0
    def initAlgorithm(self, config):
        label = tr("Connexion à la base de données")
        tooltip = 'Nom de la connexion dans QGIS pour se connecter à la base de données'
        default = QgsExpressionContextUtils.globalScope().variable(
            "veloroutes_connection_name")
        if Qgis.QGIS_VERSION_INT >= 31400:
            param = QgsProcessingParameterProviderConnection(
                self.CONNECTION_NAME,
                label,
                "postgres",
                optional=False,
                defaultValue=default)
        else:
            param = QgsProcessingParameterString(self.CONNECTION_NAME,
                                                 label,
                                                 optional=False,
                                                 defaultValue=default)
            param.setMetadata({
                "widget_wrapper": {
                    "class":
                    "processing.gui.wrappers_postgis.ConnectionWidgetWrapper"
                }
            })
        if Qgis.QGIS_VERSION_INT >= 31600:
            param.setHelp(tooltip)
        else:
            param.tooltip_3liz = tooltip
        self.addParameter(param)

        self.addParameter(
            QgsProcessingParameterBoolean(
                self.RUN_MIGRATIONS,
                tr("Cocher cette option pour lancer la mise-à-jour."),
                defaultValue=False,
                optional=False,
            ))
        # OUTPUTS
        self.addOutput(
            QgsProcessingOutputNumber(self.OUTPUT_STATUS, tr("Output status")))
        self.addOutput(
            QgsProcessingOutputString(self.OUTPUT_STRING,
                                      tr("Output message")))
Exemplo n.º 7
0
    def initAlgorithm(self, config):
        # Database connection parameters
        label = "Connexion PostgreSQL vers la base de données"
        tooltip = "Base de données de destination"
        default = QgsExpressionContextUtils.globalScope().variable(
            'veloroutes_connection_name')
        if Qgis.QGIS_VERSION_INT >= 31400:
            param = QgsProcessingParameterProviderConnection(
                self.CONNECTION_NAME,
                label,
                "postgres",
                optional=False,
                defaultValue=default)
        else:
            param = QgsProcessingParameterString(self.CONNECTION_NAME,
                                                 label,
                                                 defaultValue=default)
            param.setMetadata({
                "widget_wrapper": {
                    "class":
                    "processing.gui.wrappers_postgis.ConnectionWidgetWrapper"
                }
            })
        if Qgis.QGIS_VERSION_INT >= 31600:
            param.setHelp(tooltip)
        else:
            param.tooltip_3liz = tooltip
        self.addParameter(param)

        # OUTPUTS
        # Add output for status (integer)
        output = QgsProcessingOutputNumber(self.OUTPUT_STATUS,
                                           'Statut de sortie')
        output.tooltip_3liz = output.description()
        self.addOutput(output)

        # Add output for message
        output = QgsProcessingOutputString(self.OUTPUT_STRING,
                                           'Message de sortie')
        output.tooltip_3liz = output.description()
        self.addOutput(output)
Exemplo n.º 8
0
    def initAlgorithm(self, config=None):
        # Database Connection
        if qgs_version < 31400:
            db_param = QgsProcessingParameterString(
                self.DATABASE,
                self.tr('Database Connection'))
            db_param.setMetadata({
                'widget_wrapper': {
                    'class': 'processing.gui.wrappers_postgis.ConnectionWidgetWrapper'}})
        else:
            db_param = QgsProcessingParameterProviderConnection(
                self.DATABASE,
                self.tr('Database Connection'),
                'postgres')

        self.addParameter(db_param)

        # Schema
        if qgs_version < 31400:
            schema_param = QgsProcessingParameterString(
                self.SCHEMA,
                self.tr('Schema'), 'bc250_reamb')
            schema_param.setMetadata({
                'widget_wrapper': {
                    'class': 'processing.gui.wrappers_postgis.SchemaWidgetWrapper',
                    'connection_param': self.DATABASE}})
        else:
            schema_param = QgsProcessingParameterDatabaseSchema(
                self.SCHEMA,
                self.tr('Schema'), 
                defaultValue='bc250_reamb', 
                connectionParameterName=self.DATABASE)

        self.addParameter(schema_param) 
        
      
        # Geopackage
        self.addParameter(QgsProcessingParameterFile(self.GEOPACKAGE, 'Geopackage', 0, 'gpkg'))
        
        # Clean Schema
        '''
Exemplo n.º 9
0
    def initAlgorithm(self, config=None):
        self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT,
                                                              self.tr('Layer to import'),
                                                              types=[QgsProcessing.TypeVector]))

        db_param = QgsProcessingParameterProviderConnection(
            self.DATABASE,
            self.tr('Database (connection name)'), 'postgres'
        )
        self.addParameter(db_param)

        schema_param = QgsProcessingParameterDatabaseSchema(
            self.SCHEMA,
            self.tr('Schema (schema name)'), connectionParameterName=self.DATABASE, defaultValue='public', optional=True)
        self.addParameter(schema_param)

        table_param = QgsProcessingParameterDatabaseTable(
            self.TABLENAME,
            self.tr('Table to import to (leave blank to use layer name)'), defaultValue=None, connectionParameterName=self.DATABASE,
            schemaParameterName=self.SCHEMA, optional=True, allowNewTableNames=True)
        self.addParameter(table_param)

        self.addParameter(QgsProcessingParameterField(self.PRIMARY_KEY,
                                                      self.tr('Primary key field'), None, self.INPUT,
                                                      QgsProcessingParameterField.Any, False, True))
        self.addParameter(QgsProcessingParameterString(self.GEOMETRY_COLUMN,
                                                       self.tr('Geometry column'), 'geom'))
        self.addParameter(QgsProcessingParameterString(self.ENCODING,
                                                       self.tr('Encoding'), 'UTF-8',
                                                       False, True))
        self.addParameter(QgsProcessingParameterBoolean(self.OVERWRITE,
                                                        self.tr('Overwrite'), True))
        self.addParameter(QgsProcessingParameterBoolean(self.CREATEINDEX,
                                                        self.tr('Create spatial index'), True))
        self.addParameter(QgsProcessingParameterBoolean(self.LOWERCASE_NAMES,
                                                        self.tr('Convert field names to lowercase'), True))
        self.addParameter(QgsProcessingParameterBoolean(self.DROP_STRING_LENGTH,
                                                        self.tr('Drop length constraints on character fields'), False))
        self.addParameter(QgsProcessingParameterBoolean(self.FORCE_SINGLEPART,
                                                        self.tr('Create single-part geometries instead of multi-part'),
                                                        False))
Exemplo n.º 10
0
 def initAlgorithm(self, config=None):
     db_param = QgsProcessingParameterProviderConnection(
         self.DATABASE, self.tr('Database (connection name)'), 'postgres')
     self.addParameter(db_param)
     self.addParameter(
         QgsProcessingParameterString(self.SQL,
                                      self.tr('SQL query'),
                                      multiLine=True))
     self.addParameter(
         QgsProcessingParameterString(self.ID_FIELD,
                                      self.tr('Unique ID field name'),
                                      defaultValue='id'))
     self.addParameter(
         QgsProcessingParameterString(self.GEOMETRY_FIELD,
                                      self.tr('Geometry field name'),
                                      defaultValue='geom',
                                      optional=True))
     self.addOutput(
         QgsProcessingOutputVectorLayer(
             self.OUTPUT, self.tr("Output layer"),
             QgsProcessing.TypeVectorAnyGeometry))
Exemplo n.º 11
0
    def initAlgorithm(self, config=None):

        db_param = QgsProcessingParameterProviderConnection(
            self.DATABASE, self.tr('Database (connection name)'), 'postgres')
        self.addParameter(db_param)
        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.INPUT,
                self.tr('Input layer'),
                types=[QgsProcessing.TypeVector]))
        self.addParameter(
            QgsProcessingParameterString(self.SHAPE_ENCODING,
                                         self.tr('Shape encoding'),
                                         "",
                                         optional=True))
        self.addParameter(
            QgsProcessingParameterEnum(self.GTYPE,
                                       self.tr('Output geometry type'),
                                       options=self.GEOMTYPE,
                                       defaultValue=0))
        self.addParameter(
            QgsProcessingParameterCrs(self.A_SRS,
                                      self.tr('Assign an output CRS'),
                                      defaultValue='',
                                      optional=True))
        self.addParameter(
            QgsProcessingParameterCrs(
                self.T_SRS,
                self.tr('Reproject to this CRS on output '),
                defaultValue='',
                optional=True))
        self.addParameter(
            QgsProcessingParameterCrs(self.S_SRS,
                                      self.tr('Override source CRS'),
                                      defaultValue='',
                                      optional=True))

        schema_param = QgsProcessingParameterDatabaseSchema(
            self.SCHEMA,
            self.tr('Schema (schema name)'),
            defaultValue='public',
            connectionParameterName=self.DATABASE,
            optional=True)
        self.addParameter(schema_param)

        table_param = QgsProcessingParameterDatabaseTable(
            self.TABLE,
            self.tr('Table to import to (leave blank to use layer name)'),
            defaultValue=None,
            connectionParameterName=self.DATABASE,
            schemaParameterName=self.SCHEMA,
            optional=True,
            allowNewTableNames=True)
        self.addParameter(table_param)

        self.addParameter(
            QgsProcessingParameterString(self.PK,
                                         self.tr('Primary key (new field)'),
                                         defaultValue='id',
                                         optional=True))
        self.addParameter(
            QgsProcessingParameterField(
                self.PRIMARY_KEY,
                self.
                tr('Primary key (existing field, used if the above option is left empty)'
                   ),
                parentLayerParameterName=self.INPUT,
                optional=True))
        self.addParameter(
            QgsProcessingParameterString(self.GEOCOLUMN,
                                         self.tr('Geometry column name'),
                                         defaultValue='geom',
                                         optional=True))
        self.addParameter(
            QgsProcessingParameterEnum(self.DIM,
                                       self.tr('Vector dimensions'),
                                       options=self.DIMLIST,
                                       defaultValue=0))
        self.addParameter(
            QgsProcessingParameterString(
                self.SIMPLIFY,
                self.tr('Distance tolerance for simplification'),
                defaultValue='',
                optional=True))
        self.addParameter(
            QgsProcessingParameterString(
                self.SEGMENTIZE,
                self.tr('Maximum distance between 2 nodes (densification)'),
                defaultValue='',
                optional=True))
        self.addParameter(
            QgsProcessingParameterExtent(
                self.SPAT,
                self.tr(
                    'Select features by extent (defined in input layer CRS)'),
                optional=True))
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.CLIP,
                self.tr(
                    'Clip the input layer using the above (rectangle) extent'),
                defaultValue=False))
        self.addParameter(
            QgsProcessingParameterString(
                self.WHERE,
                self.
                tr('Select features using a SQL "WHERE" statement (Ex: column=\'value\')'
                   ),
                defaultValue='',
                optional=True))
        self.addParameter(
            QgsProcessingParameterString(
                self.GT,
                self.tr('Group N features per transaction (Default: 20000)'),
                defaultValue='',
                optional=True))
        self.addParameter(
            QgsProcessingParameterBoolean(self.OVERWRITE,
                                          self.tr('Overwrite existing table'),
                                          defaultValue=True))
        self.addParameter(
            QgsProcessingParameterBoolean(self.APPEND,
                                          self.tr('Append to existing table'),
                                          defaultValue=False))
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.ADDFIELDS,
                self.tr('Append and add new fields to existing table'),
                defaultValue=False))
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.LAUNDER,
                self.tr('Do not launder columns/table names'),
                defaultValue=False))
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.INDEX,
                self.tr('Do not create spatial index'),
                defaultValue=False))
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.SKIPFAILURES,
                self.tr(
                    'Continue after a failure, skipping the failed feature'),
                defaultValue=False))
        self.addParameter(
            QgsProcessingParameterBoolean(self.PROMOTETOMULTI,
                                          self.tr('Promote to Multipart'),
                                          defaultValue=True))
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.PRECISION,
                self.tr('Keep width and precision of input attributes'),
                defaultValue=True))
        self.addParameter(
            QgsProcessingParameterString(
                self.OPTIONS,
                self.tr('Additional creation options'),
                defaultValue='',
                optional=True))
Exemplo n.º 12
0
    def initAlgorithm(self, config):
        connections, _ = connections_list()
        if connections:
            connection_name = connections[0]
        else:
            connection_name = ''

        label = tr("Connection to the PostgreSQL database")
        tooltip = tr("The database where the schema '{}' will be installed.").format(SCHEMA)
        if Qgis.QGIS_VERSION_INT >= 31400:
            param = QgsProcessingParameterProviderConnection(
                self.CONNECTION_NAME,
                label,
                "postgres",
                defaultValue=connection_name,
                optional=False,
            )
        else:
            param = QgsProcessingParameterString(
                self.CONNECTION_NAME,
                label,
                defaultValue=connection_name,
                optional=False,
            )
            param.setMetadata(
                {
                    "widget_wrapper": {
                        "class": "processing.gui.wrappers_postgis.ConnectionWidgetWrapper"
                    }
                }
            )
        if Qgis.QGIS_VERSION_INT >= 31600:
            param.setHelp(tooltip)
        else:
            param.tooltip_3liz = tooltip
        self.addParameter(param)

        param = QgsProcessingParameterBoolean(
            self.OVERRIDE,
            tr("Erase the schema {} ?").format(SCHEMA),
            defaultValue=False,
        )
        tooltip = tr("** Be careful ** This will remove data in the schema !")
        if Qgis.QGIS_VERSION_INT >= 31600:
            param.setHelp(tooltip)
        else:
            param.tooltip_3liz = tooltip
        self.addParameter(param)

        self.addOutput(
            QgsProcessingOutputString(self.DATABASE_VERSION, tr("Database version"))
        )
Exemplo n.º 13
0
    def initAlgorithm(self, config):
        label = tr("Connexion PostgreSQL vers la base de données")
        tooltip = tr("Base de données de destination")
        if Qgis.QGIS_VERSION_INT >= 31400:
            param = QgsProcessingParameterProviderConnection(
                self.DATABASE,
                label,
                "postgres",
                optional=False,
            )
        else:
            param = QgsProcessingParameterString(self.DATABASE, label)
            param.setMetadata({
                "widget_wrapper": {
                    "class":
                    "processing.gui.wrappers_postgis.ConnectionWidgetWrapper"
                }
            })
        if Qgis.QGIS_VERSION_INT >= 31600:
            param.setHelp(tooltip)
        else:
            param.tooltip_3liz = tooltip
        self.addParameter(param)

        # Schéma de destination
        label = tr("Schéma")
        tooltip = 'Nom du schéma où importer les données'
        default = 'veloroutes'
        if Qgis.QGIS_VERSION_INT >= 31400:
            param = QgsProcessingParameterDatabaseSchema(
                self.SCHEMA,
                label,
                self.DATABASE,
                defaultValue=default,
                optional=False,
            )
        else:
            param = QgsProcessingParameterString(self.SCHEMA, label, default,
                                                 False, True)
            param.setMetadata({
                "widget_wrapper": {
                    "class":
                    "processing.gui.wrappers_postgis.SchemaWidgetWrapper",
                    "connection_param": self.DATABASE,
                }
            })
        if Qgis.QGIS_VERSION_INT >= 31600:
            param.setHelp(tooltip)
        else:
            param.tooltip_3liz = tooltip
        self.addParameter(param)

        # Table de destination
        label = tr("Table de destination")
        tooltip = 'Nom du schéma où importer les données'
        default = 'portion'
        if Qgis.QGIS_VERSION_INT >= 31400:
            param = QgsProcessingParameterDatabaseTable(
                self.TABLE,
                label,
                self.DATABASE,
                self.SCHEMA,
                defaultValue=default,
                optional=False,
            )
        else:
            param = QgsProcessingParameterString(self.TABLE, label, default,
                                                 False)
            param.setMetadata({
                "widget_wrapper": {
                    "class":
                    "processing.gui.wrappers_postgis.TableWidgetWrapper",
                    "schema_param": self.SCHEMA
                }
            })
        if Qgis.QGIS_VERSION_INT >= 31600:
            param.setHelp(tooltip)
        else:
            param.tooltip_3liz = tooltip
        self.addParameter(param)

        # Couche à importer
        couche = QgsProcessingParameterVectorLayer(
            self.INPUT,
            'Couche à importer',
            types=[QgsProcessing.TypeVector],
        )
        self.addParameter(couche)

        # Paramètre pour le mapping de champs
        table = QgsProcessingParameterMatrix(
            self.MATRIX,
            'matrix',
            headers=['Champs source', 'Champs destination'],
            defaultValue=[
                "TYPE_PORTION_COVADIS", "type_portion", "MONTANT_SUBVENTION",
                "mont_subv", "ANNE_SUBVENTION", "annee_subv", "fid",
                "id_import", "LIEN_ITIN", "lien_itin", "LIEN_CYCLO",
                "lien_segm"
            ])
        self.addParameter(table)

        # OUTPUTS
        self.addOutput(
            QgsProcessingOutputString(self.OUTPUT_MSG,
                                      tr("Message de sortie")))
Exemplo n.º 14
0
    def initAlgorithm(self, config=None):
        # LizSync config file from ini
        ls = lizsyncConfig()

        # INPUTS

        # Central database connection
        # Needed because we need to check we can connect to central database
        connection_name_central = ls.variable('postgresql:central/name')
        label = tr('PostgreSQL connection to the central database')
        if Qgis.QGIS_VERSION_INT >= 31400:
            param = QgsProcessingParameterProviderConnection(
                self.CONNECTION_NAME_CENTRAL,
                label,
                "postgres",
                defaultValue=connection_name_central,
                optional=False,
            )
        else:
            param = QgsProcessingParameterString(
                self.CONNECTION_NAME_CENTRAL,
                label,
                defaultValue=connection_name_central,
                optional=False)
            param.setMetadata({
                'widget_wrapper': {
                    'class':
                    'processing.gui.wrappers_postgis.ConnectionWidgetWrapper'
                }
            })
        tooltip = tr('The PostgreSQL connection to the central database.')
        tooltip += tr(
            ' Needed to be able to search & replace the database connection parameters in the QGIS project'
            ' to make it usable in the clone (Termux or Geopoppy).')
        if Qgis.QGIS_VERSION_INT >= 31600:
            param.setHelp(tooltip)
        else:
            param.tooltip_3liz = tooltip
        self.addParameter(param)

        # PostgreSQL layers
        param = QgsProcessingParameterMultipleLayers(
            self.PG_LAYERS,
            tr('PostgreSQL Layers to edit in the field'),
            QgsProcessing.TypeVector,
            optional=False,
        )
        tooltip = tr(
            'Select the PostgreSQL layers you want to edit in the clone.'
            ' The connection parameters of these layers will be adapted for the clone PostgreSQL datatabase'
        )
        if Qgis.QGIS_VERSION_INT >= 31600:
            param.setHelp(tooltip)
        else:
            param.tooltip_3liz = tooltip
        self.addParameter(param)

        # Layers to export to Geopackage
        param = QgsProcessingParameterMultipleLayers(
            self.GPKG_LAYERS,
            tr('Layers to convert into Geopackage'),
            QgsProcessing.TypeVector,
            optional=False,
        )
        tooltip = tr(
            'Select the vector layers you have exported (or you will export) to a Geopackage file '
            ' The datasource of these layers will be changed to reference the Geopackage layer'
            ' instead of the initial source')
        if Qgis.QGIS_VERSION_INT >= 31600:
            param.setHelp(tooltip)
        else:
            param.tooltip_3liz = tooltip
        self.addParameter(param)

        # OUTPUTS
        # Add output for message
        self.addOutput(
            QgsProcessingOutputNumber(self.OUTPUT_STATUS, tr('Output status')))
        self.addOutput(
            QgsProcessingOutputString(self.OUTPUT_STRING,
                                      tr('Output message')))
Exemplo n.º 15
0
    def initAlgorithm(self, config):
        """
        Here we define the inputs and output of the algorithm, along
        with some other properties.
        """
        # LizSync config file from ini
        ls = lizsyncConfig()

        # INPUTS
        connection_name_central = ls.variable('postgresql:central/name')
        label = tr('PostgreSQL connection to the central database')
        if Qgis.QGIS_VERSION_INT >= 31400:
            param = QgsProcessingParameterProviderConnection(
                self.CONNECTION_NAME_CENTRAL,
                label,
                "postgres",
                defaultValue=connection_name_central,
                optional=False,
            )
        else:
            param = QgsProcessingParameterString(
                self.CONNECTION_NAME_CENTRAL,
                label,
                defaultValue=connection_name_central,
                optional=False)
            param.setMetadata({
                'widget_wrapper': {
                    'class':
                    'processing.gui.wrappers_postgis.ConnectionWidgetWrapper'
                }
            })
        tooltip = tr('The PostgreSQL connection to the central database.')
        if Qgis.QGIS_VERSION_INT >= 31600:
            param.setHelp(tooltip)
        else:
            param.tooltip_3liz = tooltip
        self.addParameter(param)

        # PostgreSQL binary path (with psql pg_restore, etc.)
        postgresql_binary_path = ls.variable('binaries/postgresql')
        self.addParameter(
            QgsProcessingParameterFile(
                self.POSTGRESQL_BINARY_PATH,
                tr('PostgreSQL binary path'),
                defaultValue=postgresql_binary_path,
                behavior=QgsProcessingParameterFile.Folder,
                optional=False))

        # PostgreSQL layers
        self.addParameter(
            QgsProcessingParameterMultipleLayers(
                self.PG_LAYERS,
                tr('PostgreSQL Layers to edit in the field'),
                QgsProcessing.TypeVector,
                optional=False,
            ))

        # Add uid columns in all the tables of the synchronized schemas
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.ADD_UID_COLUMNS,
                tr('Add unique identifiers in all tables'),
                defaultValue=True,
                optional=False))

        # Add audit trigger for all tables in the synchronized schemas
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.ADD_AUDIT_TRIGGERS,
                tr('Add audit triggers in all tables'),
                defaultValue=True,
                optional=False))

        # Additionnal SQL file to run on the clone
        additional_sql_file = ls.variable('general/additional_sql_file')
        self.addParameter(
            QgsProcessingParameterFile(
                self.ADDITIONAL_SQL_FILE,
                tr('Additionnal SQL file to run in the clone after the ZIP deployement'
                   ),
                defaultValue=additional_sql_file,
                behavior=QgsProcessingParameterFile.File,
                optional=True,
                extension='sql'))

        # Output zip file destination
        database_archive_file = ls.variable('general/database_archive_file')
        if not database_archive_file:
            database_archive_file = os.path.join(
                tempfile.gettempdir(), 'central_database_package.zip')
        self.addParameter(
            QgsProcessingParameterFileDestination(
                self.ZIP_FILE,
                tr('Output archive file (ZIP)'),
                fileFilter='*.zip',
                optional=False,
                defaultValue=database_archive_file))

        # OUTPUTS
        # Add output for message
        self.addOutput(
            QgsProcessingOutputNumber(self.OUTPUT_STATUS, tr('Output status')))
        self.addOutput(
            QgsProcessingOutputString(self.OUTPUT_STRING,
                                      tr('Output message')))
Exemplo n.º 16
0
    def initAlgorithm(self, config):
        label = tr("Connexion à la base de données")
        tooltip = 'Nom de la connexion dans QGIS pour se connecter à la base de données'
        if Qgis.QGIS_VERSION_INT >= 31400:
            param = QgsProcessingParameterProviderConnection(
                self.DATABASE,
                label,
                "postgres",
                optional=False,
            )
        else:
            param = QgsProcessingParameterString(self.DATABASE, label)
            param.setMetadata({
                "widget_wrapper": {
                    "class":
                    "processing.gui.wrappers_postgis.ConnectionWidgetWrapper"
                }
            })
        if Qgis.QGIS_VERSION_INT >= 31600:
            param.setHelp(tooltip)
        else:
            param.tooltip_3liz = tooltip
        self.addParameter(param)

        label = tr("Schéma")
        tooltip = 'Nom du schéma pour importer les couches'
        default = 'veloroutes'
        if Qgis.QGIS_VERSION_INT >= 31400:
            param = QgsProcessingParameterDatabaseSchema(
                self.SCHEMA,
                label,
                self.DATABASE,
                defaultValue=default,
                optional=False,
            )
        else:
            param = QgsProcessingParameterString(self.SCHEMA, label, default,
                                                 False, True)
            param.setMetadata({
                "widget_wrapper": {
                    "class":
                    "processing.gui.wrappers_postgis.SchemaWidgetWrapper",
                    "connection_param": self.DATABASE,
                }
            })
        if Qgis.QGIS_VERSION_INT >= 31600:
            param.setHelp(tooltip)
        else:
            param.tooltip_3liz = tooltip
        self.addParameter(param)

        self.addParameter(
            QgsProcessingParameterBoolean(
                self.RASTER,
                tr("Ajouter un fond raster OpenStreetMap ?"),
                defaultValue=False,
                optional=False,
            ))

        # OUTPUTS
        output = QgsProcessingOutputMultipleLayers(self.OUTPUT,
                                                   tr("Couches de sortie"))
        output.tooltip_3liz = 'Les différentes couches de l\'extension véloroutes et voies vertes'
        self.addOutput(output)

        output = QgsProcessingOutputString(self.OUTPUT_MSG,
                                           tr("Message de sortie"))
        output.tooltip_3liz = output.description()
        self.addOutput(output)
Exemplo n.º 17
0
    def initAlgorithm(self, config):
        connections, _ = connections_list()
        if connections:
            connection_name = connections[0]
        else:
            connection_name = ''

        label = tr("Connection to the PostgreSQL database")
        tooltip = tr(
            "The database where the schema '{}' is installed.").format(SCHEMA)
        if Qgis.QGIS_VERSION_INT >= 31400:
            param = QgsProcessingParameterProviderConnection(
                self.CONNECTION_NAME,
                label,
                "postgres",
                defaultValue=connection_name,
                optional=False,
            )
        else:
            param = QgsProcessingParameterString(
                self.CONNECTION_NAME,
                label,
                defaultValue=connection_name,
                optional=False,
            )
            param.setMetadata({
                "widget_wrapper": {
                    "class":
                    "processing.gui.wrappers_postgis.ConnectionWidgetWrapper"
                }
            })
        if Qgis.QGIS_VERSION_INT >= 31600:
            param.setHelp(tooltip)
        else:
            param.tooltip_3liz = tooltip
        self.addParameter(param)

        param = QgsProcessingParameterBoolean(
            self.RUN_MIGRATIONS,
            tr("Use this checkbox to upgrade."),
            defaultValue=False,
        )
        tooltip = tr(
            "For security reason, we ask that you explicitly use this checkbox."
        )
        if Qgis.QGIS_VERSION_INT >= 31600:
            param.setHelp(tooltip)
        else:
            param.tooltip_3liz = tooltip
        self.addParameter(param)

        self.addOutput(
            QgsProcessingOutputString(self.DATABASE_VERSION,
                                      tr("Database version")))
Exemplo n.º 18
0
    def initAlgorithm(self, config):

        label = tr("Connexion à la base de données")
        tooltip = 'Nom de la connexion dans QGIS pour se connecter à la base de données'
        if Qgis.QGIS_VERSION_INT >= 31400:
            param = QgsProcessingParameterProviderConnection(
                self.DATABASE,
                label,
                "postgres",
                optional=False,
            )
        else:
            param = QgsProcessingParameterString(self.DATABASE, label)
            param.setMetadata(
                {
                    "widget_wrapper": {
                        "class": "processing.gui.wrappers_postgis.ConnectionWidgetWrapper"
                    }
                }
            )
        if Qgis.QGIS_VERSION_INT >= 31600:
            param.setHelp(tooltip)
        else:
            param.tooltip_3liz = tooltip
        self.addParameter(param)

        # Schema de destination
        label = tr("Schéma")
        tooltip = 'Nom du schéma où importer les données'
        default = 'veloroutes'
        if Qgis.QGIS_VERSION_INT >= 31400:
            param = QgsProcessingParameterDatabaseSchema(
                self.SCHEMA,
                label,
                self.DATABASE,
                defaultValue=default,
                optional=False,
            )
        else:
            param = QgsProcessingParameterString(self.SCHEMA, label, default, False, True)
            param.setMetadata(
                {
                    "widget_wrapper": {
                        "class": "processing.gui.wrappers_postgis.SchemaWidgetWrapper",
                        "connection_param": self.DATABASE,
                    }
                }
            )
        if Qgis.QGIS_VERSION_INT >= 31600:
            param.setHelp(tooltip)
        else:
            param.tooltip_3liz = tooltip
        self.addParameter(param)

        # Table à exporter
        table_param = QgsProcessingParameterEnum(
            self.TABLE,
            tr("Donnée à exporter"),
            options=self.EXPORTABLES,
            defaultValue="",
        )
        table_param.tooltip_3liz = 'Nom de la table à exporter'
        self.addParameter(table_param)

        # Nom du département pour le fichier d'export
        depparam = QgsProcessingParameterString(
            self.DPT,
            tr("Département au format XXX"),
            '066',
            optional=False
        )
        depparam.tooltip_3liz = 'Pour le département de l\'Ain, mettre 001'
        self.addParameter(depparam)

        # Chemin du dossier de destination
        outparam = QgsProcessingParameterFolderDestination(
            self.PROJECTS_FOLDER,
            description=tr("Chemin de destination")
        )
        outparam.tooltip_3liz = 'Chemin de destination pour enregistrer les exports Shapefile'
        self.addParameter(outparam)

        param = QgsProcessingParameterBoolean(
            self.CHARGER,
            tr("Charger le fichier d'export dans le projet"),
            defaultValue=False,
            optional=False,
        )
        param.tooltip_3liz = 'Si le traitement doit charger la couche Shapefile dans le projet'
        self.addParameter(param)

        output = QgsProcessingOutputVectorLayer(self.OUTPUT, tr("Couches de sortie"))
        output.tooltip_3liz = 'Les couches de l\'export'
        self.addOutput(output)
    def initAlgorithm(self, config):
        connections, _ = connections_list()
        if connections:
            connection_name = connections[0]
        else:
            connection_name = ''

        label = tr("Connection to the PostgreSQL database")
        tooltip = tr("The database where the schema '{}' is installed.").format(SCHEMA)
        if Qgis.QGIS_VERSION_INT >= 31400:
            param = QgsProcessingParameterProviderConnection(
                self.CONNECTION_NAME,
                label,
                "postgres",
                defaultValue=connection_name,
                optional=False,
            )
        else:
            param = QgsProcessingParameterString(
                self.CONNECTION_NAME,
                label,
                defaultValue=connection_name,
                optional=False,
            )
            param.setMetadata(
                {
                    "widget_wrapper": {
                        "class": "processing.gui.wrappers_postgis.ConnectionWidgetWrapper"
                    }
                }
            )
        if Qgis.QGIS_VERSION_INT >= 31600:
            param.setHelp(tooltip)
        else:
            param.tooltip_3liz = tooltip
        self.addParameter(param)

        # target project file
        param = QgsProcessingParameterFileDestination(
            self.PROJECT_FILE,
            tr('QGIS project file to create'),
            defaultValue='',
            optional=False,
            fileFilter='QGS project (*.qgs)',
        )
        tooltip = tr("The destination file where to create the QGIS project.").format(SCHEMA)
        if Qgis.QGIS_VERSION_INT >= 31600:
            param.setHelp(tooltip)
        else:
            param.tooltip_3liz = tooltip
        self.addParameter(param)
Exemplo n.º 20
0
    def initAlgorithm(self, config=None):
        # LizSync config file from ini
        ls = lizsyncConfig()

        # INPUTS

        # Central database connection
        # Needed because we need to check we can connect to central database
        # Central database connection name
        connection_name_central = ls.variable('postgresql:central/name')
        label = tr('PostgreSQL connection to the central database')
        if Qgis.QGIS_VERSION_INT >= 31400:
            param = QgsProcessingParameterProviderConnection(
                self.CONNECTION_NAME_CENTRAL,
                label,
                "postgres",
                defaultValue=connection_name_central,
                optional=False,
            )
        else:
            param = QgsProcessingParameterString(
                self.CONNECTION_NAME_CENTRAL,
                label,
                defaultValue=connection_name_central,
                optional=False)
            param.setMetadata({
                'widget_wrapper': {
                    'class':
                    'processing.gui.wrappers_postgis.ConnectionWidgetWrapper'
                }
            })
        tooltip = tr('The PostgreSQL connection to the central database.')
        if Qgis.QGIS_VERSION_INT >= 31600:
            param.setHelp(tooltip)
        else:
            param.tooltip_3liz = tooltip
        self.addParameter(param)

        # PostgreSQL binary path (with psql pg_restore, etc.)
        postgresql_binary_path = ls.variable('binaries/postgresql')
        param = QgsProcessingParameterFile(
            self.POSTGRESQL_BINARY_PATH,
            tr('PostgreSQL binary path'),
            defaultValue=postgresql_binary_path,
            behavior=QgsProcessingParameterFile.Folder,
            optional=False)
        param.setFlags(param.flags()
                       | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(param)

        # PostgreSQL layers
        param = QgsProcessingParameterMultipleLayers(
            self.PG_LAYERS,
            tr('PostgreSQL Layers to edit in the field'),
            QgsProcessing.TypeVector,
            optional=False,
        )
        self.addParameter(param)

        # Add uid columns in all the tables of the synchronized schemas
        param = QgsProcessingParameterBoolean(
            self.ADD_UID_COLUMNS,
            tr('Add unique identifiers in all tables'),
            defaultValue=True,
            optional=False)
        param.setFlags(param.flags()
                       | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(param)

        # Add audit trigger for all tables in the synchronized schemas
        param = QgsProcessingParameterBoolean(
            self.ADD_AUDIT_TRIGGERS,
            tr('Add audit triggers in all tables'),
            defaultValue=True,
            optional=False)
        param.setFlags(param.flags()
                       | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(param)

        # Additionnal SQL file to run on the clone
        additional_sql_file = ls.variable('general/additional_sql_file')
        param = QgsProcessingParameterFile(
            self.ADDITIONAL_SQL_FILE,
            tr('Additionnal SQL file to run in the clone after the ZIP deployement'
               ),
            defaultValue=additional_sql_file,
            behavior=QgsProcessingParameterFile.File,
            optional=True,
            extension='sql')
        param.setFlags(param.flags()
                       | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(param)

        # Layers to export to Geopackage
        param = QgsProcessingParameterMultipleLayers(
            self.GPKG_LAYERS,
            tr('Layers to convert into Geopackage'),
            QgsProcessing.TypeVector,
            optional=False,
        )
        self.addParameter(param)

        # Override existing Geopackage file
        param = QgsProcessingParameterBoolean(
            self.OVERWRITE_GPKG,
            tr('Overwrite the Geopackage file if it exists ?'),
            defaultValue=True,
        )
        param.setFlags(param.flags()
                       | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(param)

        # OUTPUTS
        # Add output for message
        self.addOutput(
            QgsProcessingOutputNumber(self.OUTPUT_STATUS, tr('Output status')))
        self.addOutput(
            QgsProcessingOutputString(self.OUTPUT_STRING,
                                      tr('Output message')))
Exemplo n.º 21
0
    def initAlgorithm(self, config=None):
        # LizSync config file from ini
        ls = lizsyncConfig()

        # INPUTS

        # Central database connection name
        connection_name_central = ls.variable('postgresql:central/name')
        label = tr('PostgreSQL connection to the central database')
        if Qgis.QGIS_VERSION_INT >= 31400:
            param = QgsProcessingParameterProviderConnection(
                self.CONNECTION_NAME_CENTRAL,
                label,
                "postgres",
                defaultValue=connection_name_central,
                optional=False,
            )
        else:
            param = QgsProcessingParameterString(
                self.CONNECTION_NAME_CENTRAL,
                label,
                defaultValue=connection_name_central,
                optional=False)
            param.setMetadata({
                'widget_wrapper': {
                    'class':
                    'processing.gui.wrappers_postgis.ConnectionWidgetWrapper'
                }
            })
        tooltip = tr('The PostgreSQL connection to the central database.')
        if Qgis.QGIS_VERSION_INT >= 31600:
            param.setHelp(tooltip)
        else:
            param.tooltip_3liz = tooltip
        self.addParameter(param)

        # Clone database connection parameters
        connection_name_clone = ls.variable('postgresql:clone/name')
        label = tr('PostgreSQL connection to the clone database')
        if Qgis.QGIS_VERSION_INT >= 31400:
            param = QgsProcessingParameterProviderConnection(
                self.CONNECTION_NAME_CLONE,
                label,
                "postgres",
                defaultValue=connection_name_clone,
                optional=False,
            )
        else:
            param = QgsProcessingParameterString(
                self.CONNECTION_NAME_CLONE,
                label,
                defaultValue=connection_name_clone,
                optional=False)
            param.setMetadata({
                'widget_wrapper': {
                    'class':
                    'processing.gui.wrappers_postgis.ConnectionWidgetWrapper'
                }
            })
        tooltip = tr('The PostgreSQL connection to the clone database.')
        if Qgis.QGIS_VERSION_INT >= 31600:
            param.setHelp(tooltip)
        else:
            param.tooltip_3liz = tooltip
        self.addParameter(param)

        # OUTPUTS
        # Add output for message
        self.addOutput(
            QgsProcessingOutputNumber(self.OUTPUT_STATUS, tr('Output status')))
        self.addOutput(
            QgsProcessingOutputString(self.OUTPUT_STRING,
                                      tr('Output message')))
Exemplo n.º 22
0
    def initAlgorithm(self, config):
        """
        Here we define the inputs and output of the algorithm, along
        with some other properties.
        """
        # LizSync config file from ini
        ls = lizsyncConfig()

        # INPUTS
        # Central database connection name
        connection_name_central = ls.variable('postgresql:central/name')
        label = tr('PostgreSQL connection to the central database')
        if Qgis.QGIS_VERSION_INT >= 31400:
            param = QgsProcessingParameterProviderConnection(
                self.CONNECTION_NAME_CENTRAL,
                label,
                "postgres",
                defaultValue=connection_name_central,
                optional=False,
            )
        else:
            param = QgsProcessingParameterString(
                self.CONNECTION_NAME_CENTRAL,
                label,
                defaultValue=connection_name_central,
                optional=False
            )
            param.setMetadata({
                'widget_wrapper': {
                    'class': 'processing.gui.wrappers_postgis.ConnectionWidgetWrapper'
                }
            })
        tooltip = tr(
            'The PostgreSQL connection to the central database.'
        )
        if Qgis.QGIS_VERSION_INT >= 31600:
            param.setHelp(tooltip)
        else:
            param.tooltip_3liz = tooltip
        self.addParameter(param)

        # Clone database connection parameters
        connection_name_clone = ls.variable('postgresql:clone/name')
        label = tr('PostgreSQL connection to the clone database')
        if Qgis.QGIS_VERSION_INT >= 31400:
            param = QgsProcessingParameterProviderConnection(
                self.CONNECTION_NAME_CLONE,
                label,
                "postgres",
                defaultValue=connection_name_clone,
                optional=False,
            )
        else:
            param = QgsProcessingParameterString(
                self.CONNECTION_NAME_CLONE,
                label,
                defaultValue=connection_name_clone,
                optional=False
            )
            param.setMetadata({
                'widget_wrapper': {
                    'class': 'processing.gui.wrappers_postgis.ConnectionWidgetWrapper'
                }
            })
        tooltip = tr(
            'The PostgreSQL connection to the clone database.'
        )
        if Qgis.QGIS_VERSION_INT >= 31600:
            param.setHelp(tooltip)
        else:
            param.tooltip_3liz = tooltip
        self.addParameter(param)

        # PostgreSQL binary path (with psql, pg_dump, pg_restore)
        postgresql_binary_path = ls.variable('binaries/postgresql')
        self.addParameter(
            QgsProcessingParameterFile(
                self.POSTGRESQL_BINARY_PATH,
                tr('PostgreSQL binary path'),
                defaultValue=postgresql_binary_path,
                behavior=QgsProcessingParameterFile.Folder,
                optional=False
            )
        )

        # Database ZIP archive file
        database_archive_file = ls.variable('general/database_archive_file')
        if not database_archive_file:
            database_archive_file = os.path.join(
                tempfile.gettempdir(),
                'central_database_package.zip'
            )
        # ZIP file
        self.addParameter(
            QgsProcessingParameterFile(
                self.ZIP_FILE,
                tr('Database ZIP archive path'),
                defaultValue=database_archive_file,
                behavior=QgsProcessingParameterFile.File,
                optional=True,
                extension='zip'
            )
        )

        # Recreate clone server id
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.RECREATE_CLONE_SERVER_ID,
                tr('Recreate clone server id. Do it only to fully reset the clone ID !'),
                defaultValue=False,
                optional=False
            )
        )

        # OUTPUTS
        # Add output for message
        self.addOutput(
            QgsProcessingOutputNumber(
                self.OUTPUT_STATUS, tr('Output status')
            )
        )
        self.addOutput(
            QgsProcessingOutputString(
                self.OUTPUT_STRING, tr('Output message')
            )
        )
Exemplo n.º 23
0
    def initAlgorithm(self, config):
        """
        Here we define the inputs and output of the algorithm, along
        with some other properties.
        """
        # LizSync config file from ini
        ls = lizsyncConfig()

        # INPUTS

        # Central database connection name
        connection_name_central = ls.variable('postgresql:central/name')
        label = tr('PostgreSQL connection to the central database')
        if Qgis.QGIS_VERSION_INT >= 31400:
            param = QgsProcessingParameterProviderConnection(
                self.CONNECTION_NAME_CENTRAL,
                label,
                "postgres",
                defaultValue=connection_name_central,
                optional=False,
            )
        else:
            param = QgsProcessingParameterString(
                self.CONNECTION_NAME_CENTRAL,
                label,
                defaultValue=connection_name_central,
                optional=False)
            param.setMetadata({
                'widget_wrapper': {
                    'class':
                    'processing.gui.wrappers_postgis.ConnectionWidgetWrapper'
                }
            })
        tooltip = tr('The PostgreSQL connection to the central database.')
        if Qgis.QGIS_VERSION_INT >= 31600:
            param.setHelp(tooltip)
        else:
            param.tooltip_3liz = tooltip
        self.addParameter(param)

        # Clone database connection parameters
        connection_name_clone = ls.variable('postgresql:clone/name')
        label = tr('PostgreSQL connection to the clone database')
        if Qgis.QGIS_VERSION_INT >= 31400:
            param = QgsProcessingParameterProviderConnection(
                self.CONNECTION_NAME_CLONE,
                label,
                "postgres",
                defaultValue=connection_name_clone,
                optional=False,
            )
        else:
            param = QgsProcessingParameterString(
                self.CONNECTION_NAME_CLONE,
                label,
                defaultValue=connection_name_clone,
                optional=False)
            param.setMetadata({
                'widget_wrapper': {
                    'class':
                    'processing.gui.wrappers_postgis.ConnectionWidgetWrapper'
                }
            })
        tooltip = tr('The PostgreSQL connection to the clone database.')
        if Qgis.QGIS_VERSION_INT >= 31600:
            param.setHelp(tooltip)
        else:
            param.tooltip_3liz = tooltip
        self.addParameter(param)

        # PostgreSQL binary path (with psql, pg_dump, pg_restore)
        postgresql_binary_path = ls.variable('binaries/postgresql')
        param = QgsProcessingParameterFile(
            self.POSTGRESQL_BINARY_PATH,
            tr('PostgreSQL binary path'),
            defaultValue=postgresql_binary_path,
            behavior=QgsProcessingParameterFile.Folder,
            optional=False)
        param.setFlags(param.flags()
                       | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(param)

        # Local directory containing the files to send to the clone by FTP
        local_qgis_project_folder = ls.variable('local/qgis_project_folder')
        param = QgsProcessingParameterFile(
            self.LOCAL_QGIS_PROJECT_FOLDER,
            tr('Local desktop QGIS project folder'),
            defaultValue=local_qgis_project_folder,
            behavior=QgsProcessingParameterFile.Folder,
            optional=False)
        self.addParameter(param)

        # Database ZIP archive file
        database_archive_file = ls.variable('general/database_archive_file')
        if not database_archive_file:
            database_archive_file = os.path.join(
                tempfile.gettempdir(), 'central_database_package.zip')
        param = QgsProcessingParameterFile(
            self.ZIP_FILE,
            tr('Database ZIP archive path'),
            defaultValue=database_archive_file,
            behavior=QgsProcessingParameterFile.File,
            optional=True,
            extension='zip')
        self.addParameter(param)

        # Recreate clone server id
        param = QgsProcessingParameterBoolean(
            self.RECREATE_CLONE_SERVER_ID,
            tr('Recreate clone server id. Do it only to fully reset the clone ID !'
               ),
            defaultValue=False,
            optional=False)
        param.setFlags(param.flags()
                       | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(param)

        # Clone FTP connection parameters
        # method
        self.CLONE_FTP_PROTOCOLS = ['SFTP', 'FTP']
        param = QgsProcessingParameterEnum(
            self.CLONE_FTP_PROTOCOL,
            tr('Clone (S)FTP protocol'),
            options=self.CLONE_FTP_PROTOCOLS,
            defaultValue=0,
            optional=False,
        )
        self.addParameter(param)

        # host
        clone_ftp_host = ls.variable('ftp:clone/host')
        param = QgsProcessingParameterString(self.CLONE_FTP_HOST,
                                             tr('Clone FTP Server host'),
                                             defaultValue=clone_ftp_host,
                                             optional=False)
        self.addParameter(param)

        # port
        clone_ftp_port = ls.variable('ftp:clone/port')
        param = QgsProcessingParameterNumber(self.CLONE_FTP_PORT,
                                             tr('Clone FTP Server port'),
                                             defaultValue=clone_ftp_port,
                                             optional=False)
        self.addParameter(param)

        # login
        clone_ftp_login = ls.variable('ftp:clone/user')
        param = QgsProcessingParameterString(self.CLONE_FTP_LOGIN,
                                             tr('Clone FTP Server login'),
                                             defaultValue=clone_ftp_login,
                                             optional=False)
        self.addParameter(param)

        # password
        param = QgsProcessingParameterString(self.CLONE_FTP_PASSWORD,
                                             tr('Clone FTP Server password'),
                                             optional=True)
        self.addParameter(param)

        # remote directory
        clone_ftp_remote_dir = ls.variable('ftp:clone/remote_directory')
        param = QgsProcessingParameterString(
            self.CLONE_FTP_REMOTE_DIR,
            tr('Clone FTP Server remote directory'),
            defaultValue=clone_ftp_remote_dir,
            optional=False)
        self.addParameter(param)

        # Exclude some directories from sync
        excluded_directories = ls.variable('local/excluded_directories')
        if not excluded_directories:
            excluded_directories = 'data'
        param = QgsProcessingParameterString(
            self.FTP_EXCLUDE_REMOTE_SUBDIRS,
            tr('List of sub-directory to exclude from synchro, separated by commas.'
               ),
            defaultValue=excluded_directories,
            optional=True)
        param.setFlags(param.flags()
                       | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(param)

        # OUTPUTS
        # Add output for message
        self.addOutput(
            QgsProcessingOutputNumber(self.OUTPUT_STATUS, tr('Output status')))
        self.addOutput(
            QgsProcessingOutputString(self.OUTPUT_STRING,
                                      tr('Output message')))
    def initAlgorithm(self, config):
        # LizSync config file from ini
        ls = lizsyncConfig()
        connection_name = ls.variable('postgresql:central/name')

        label = tr('PostgreSQL connection to the central database')
        tooltip = tr('The PostgreSQL connection to the central database.')
        tooltip += tr(
            ' You need to have the right to create a new schema in this database,'
            ' as a schema lizsync will be created and filled with the needed tables and functions'
        )
        if Qgis.QGIS_VERSION_INT >= 31400:
            param = QgsProcessingParameterProviderConnection(
                self.CONNECTION_NAME,
                label,
                "postgres",
                defaultValue=connection_name,
                optional=False,
            )
        else:
            param = QgsProcessingParameterString(
                self.CONNECTION_NAME,
                label,
                defaultValue=connection_name,
                optional=False,
            )
            param.setMetadata({
                "widget_wrapper": {
                    "class":
                    "processing.gui.wrappers_postgis.ConnectionWidgetWrapper"
                }
            })
        if Qgis.QGIS_VERSION_INT >= 31600:
            param.setHelp(tooltip)
        else:
            param.tooltip_3liz = tooltip
        self.addParameter(param)

        param = QgsProcessingParameterBoolean(
            self.OVERRIDE,
            tr("Erase the schema {} ?").format(SCHEMA),
            defaultValue=False,
        )
        tooltip = tr("** Be careful ** This will remove data in the schema !")
        if Qgis.QGIS_VERSION_INT >= 31600:
            param.setHelp(tooltip)
        else:
            param.tooltip_3liz = tooltip
        self.addParameter(param)

        self.addOutput(
            QgsProcessingOutputString(self.DATABASE_VERSION,
                                      tr("Database version")))
Exemplo n.º 25
0
    def initAlgorithm(self, config):
        connections, _ = connections_list()
        if connections:
            connection_name = connections[0]
        else:
            connection_name = ''

        label = tr("Connection to the PostgreSQL database")
        tooltip = tr("The database where the schema '{}' has been installed."
                     ).format(SCHEMA)
        if Qgis.QGIS_VERSION_INT >= 31400:
            param = QgsProcessingParameterProviderConnection(
                self.CONNECTION_NAME,
                label,
                "postgres",
                defaultValue=connection_name,
                optional=False,
            )
        else:
            param = QgsProcessingParameterString(
                self.CONNECTION_NAME,
                label,
                defaultValue=connection_name,
                optional=False,
            )
            param.setMetadata({
                "widget_wrapper": {
                    "class":
                    "processing.gui.wrappers_postgis.ConnectionWidgetWrapper"
                }
            })
        if Qgis.QGIS_VERSION_INT >= 31600:
            param.setHelp(tooltip)
        else:
            param.tooltip_3liz = tooltip
        self.addParameter(param)

        param = QgsProcessingParameterBoolean(
            self.RESET,
            tr("Recompute values in the dataset table"),
            defaultValue=False,
        )
        tooltip = tr("** Be careful ** This will recompute default values.")
        if Qgis.QGIS_VERSION_INT >= 31600:
            param.setHelp(tooltip)
        else:
            param.tooltip_3liz = tooltip
        self.addParameter(param)
 def initAlgorithm(self, config):
     """Initialize algorithm with inputs and output parameters."""
     if HAS_DB_PROCESSING_PARAMETER:
         db_param = QgsProcessingParameterProviderConnection(
             self.DATABASE,
             self.tr('PostgreSQL database (connection name)'),
             'postgres',
         )
         schema_param = QgsProcessingParameterDatabaseSchema(
             self.SCHEMA,
             self.tr('PostgreSQL schema name'),
             connectionParameterName=self.DATABASE,
             defaultValue='public',
         )
         table_param = QgsProcessingParameterDatabaseTable(
             self.TABLENAME,
             self.tr('PostgreSQL original table name'),
             connectionParameterName=self.DATABASE,
             schemaParameterName=self.SCHEMA)
     else:
         db_param = QgsProcessingParameterString(
             self.DATABASE,
             self.tr('PostgreSQL database (connection name)'),
         )
         db_param.setMetadata({
             'widget_wrapper': {
                 'class':
                 'processing.gui.wrappers_postgis.ConnectionWidgetWrapper'
             }
         })
         schema_param = QgsProcessingParameterString(
             self.SCHEMA,
             self.tr('PostgreSQL schema name'),
             'public',
             False,
             True,
         )
         schema_param.setMetadata({
             'widget_wrapper': {
                 'class':
                 'processing.gui.wrappers_postgis.SchemaWidgetWrapper',
                 'connection_param': self.DATABASE,
             }
         })
         table_param = QgsProcessingParameterString(
             self.TABLENAME,
             self.tr('PostgreSQL original table name'),
             '',
             False,
             True,
         )
         table_param.setMetadata({
             'widget_wrapper': {
                 'class':
                 'processing.gui.wrappers_postgis.TableWidgetWrapper',
                 'schema_param': self.SCHEMA,
             }
         })
     self.addParameter(db_param)
     self.addParameter(schema_param)
     self.addParameter(table_param)
     self.addParameter(
         QgsProcessingParameterFeatureSource(
             self.NEW_INPUT,
             self.tr('New layer'),
             types=[QgsProcessing.TypeVector],
         ))
     self.addParameter(
         QgsProcessingParameterField(
             self.FIELDS_TO_COMPARE,
             self.tr('Fields to compare'),
             None,
             self.NEW_INPUT,
             allowMultiple=True,
         ))
     self.addParameter(
         QgsProcessingParameterEnum(
             self.HIGHLIGHT_METHOD,
             self.tr('Highlight method'),
             options=[
                 self.tr('Only highlight different lines'),
                 self.
                 tr('Highligt different lines and inta-line character changes (Slower on '
                    'large layers)'),
             ],
             defaultValue=0,
         ))
     self.addParameter(
         QgsProcessingParameterExpression(
             self.SORT_EXPRESSION,
             self.tr('Sort expression (put in ORDER BY clause)'),
             parentLayerParameterName=self.NEW_INPUT,
             defaultValue='',
         ))
     self.addParameter(
         QgsProcessingParameterFileDestination(
             self.OUTPUT_HTML_FILE, self.tr('HTML report'),
             self.tr('HTML files (*.html)'), None, True))
    def initAlgorithm(self, config):
        # LizSync config file from ini
        ls = lizsyncConfig()

        # INPUTS
        connection_name = ls.variable('postgresql:central/name')
        label = tr('PostgreSQL connection to the central database')
        if Qgis.QGIS_VERSION_INT >= 31400:
            param = QgsProcessingParameterProviderConnection(
                self.CONNECTION_NAME,
                label,
                "postgres",
                defaultValue=connection_name,
                optional=False,
            )
        else:
            param = QgsProcessingParameterString(self.CONNECTION_NAME,
                                                 label,
                                                 defaultValue=connection_name,
                                                 optional=False)
            param.setMetadata({
                'widget_wrapper': {
                    'class':
                    'processing.gui.wrappers_postgis.ConnectionWidgetWrapper'
                }
            })
        tooltip = tr('The PostgreSQL connection to the central database.')
        tooltip += tr(
            ' You need to have the right to create a new schema in this database,'
            ' as a schema lizsync will be created and filled with the needed tables and functions'
        )
        if Qgis.QGIS_VERSION_INT >= 31600:
            param.setHelp(tooltip)
        else:
            param.tooltip_3liz = tooltip
        self.addParameter(param)

        # Hidden parameters which allow to drop the schemas
        # Hidden to avoid misuse and data loss
        # Drop schema audit
        p = QgsProcessingParameterBoolean(
            self.OVERRIDE_AUDIT,
            tr('Drop audit schema and all data ?'),
            defaultValue=False,
        )
        p.setFlags(QgsProcessingParameterDefinition.FlagHidden)
        self.addParameter(p)

        # Drop schema lizsync
        p = QgsProcessingParameterBoolean(
            self.OVERRIDE_LIZSYNC,
            tr('Drop lizsync schema and all data ?'),
            defaultValue=False,
        )
        p.setFlags(QgsProcessingParameterDefinition.FlagHidden)
        self.addParameter(p)

        # OUTPUTS
        # Add output for status (integer)
        self.addOutput(
            QgsProcessingOutputNumber(self.OUTPUT_STATUS, tr('Output status')))
        self.addOutput(
            QgsProcessingOutputString(self.OUTPUT_STRING,
                                      tr('Output message')))
    def initAlgorithm(self, config):
        """
        Here we define the inputs and output of the algorithm, along
        with some other properties.
        """
        # LizSync config file from ini
        ls = lizsyncConfig()

        # INPUTS
        # Central database connection name
        connection_name_central = ls.variable('postgresql:central/name')
        label = tr('PostgreSQL connection to the central database')
        if Qgis.QGIS_VERSION_INT >= 31400:
            param = QgsProcessingParameterProviderConnection(
                self.CONNECTION_NAME_CENTRAL,
                label,
                "postgres",
                defaultValue=connection_name_central,
                optional=False,
            )
        else:
            param = QgsProcessingParameterString(
                self.CONNECTION_NAME_CENTRAL,
                label,
                defaultValue=connection_name_central,
                optional=False)
            param.setMetadata({
                'widget_wrapper': {
                    'class':
                    'processing.gui.wrappers_postgis.ConnectionWidgetWrapper'
                }
            })
        tooltip = tr('The PostgreSQL connection to the central database.')
        if Qgis.QGIS_VERSION_INT >= 31600:
            param.setHelp(tooltip)
        else:
            param.tooltip_3liz = tooltip
        self.addParameter(param)

        # Add server id in metadata
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.ADD_SERVER_ID,
                tr('Add server id in metadata table'),
                defaultValue=True,
                optional=False))

        # Add uid columns in all the tables of the synchronized schemas
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.ADD_UID_COLUMNS,
                tr('Add unique identifiers in all tables'),
                defaultValue=False,
                optional=False))

        # Add audit trigger for all tables in the synchronized schemas
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.ADD_AUDIT_TRIGGERS,
                tr('Add audit triggers in all tables'),
                defaultValue=False,
                optional=False))

        # Schemas to synchronize
        synchronized_schemas = ls.variable(
            'postgresql:central/schemas').strip()
        if not synchronized_schemas:
            synchronized_schemas = ''
        self.addParameter(
            QgsProcessingParameterString(
                self.SCHEMAS,
                tr('Restrict to comma separated schema names. NB: schemas public & lizsync are never processed'
                   ),
                defaultValue=synchronized_schemas,
                optional=True))

        # OUTPUTS
        # Add output for status (integer)
        self.addOutput(
            QgsProcessingOutputNumber(self.OUTPUT_STATUS, tr('Output status')))
        self.addOutput(
            QgsProcessingOutputString(self.OUTPUT_STRING,
                                      tr('Output message')))
Exemplo n.º 29
0
 def initAlgorithm(self, config):
     """Initialize algorithm with inputs and output parameters."""
     if HAS_DB_PROCESSING_PARAMETER:
         db_param = QgsProcessingParameterProviderConnection(
             self.DATABASE,
             self.tr('Database (connection name)'),
             'postgres',
         )
     else:
         db_param = QgsProcessingParameterString(
             self.DATABASE,
             self.tr('Database (connection name)'),
         )
         db_param.setMetadata({
             'widget_wrapper': {
                 'class': ('processing.gui.wrappers_postgis'
                           '.ConnectionWidgetWrapper')
             }
         })
     self.addParameter(db_param)
     self.addParameter(
         QgsProcessingParameterString(
             self.SELECT_SQL,
             self.tr('SELECT SQL query'),
             multiLine=True,
         ))
     self.addParameter(
         QgsProcessingParameterEnum(
             self.SEPARATOR,
             self.tr('Separator'),
             options=[
                 '{name} ("{char}")'.format(name=name, char=char)
                 for name, char in _SEPARATORS
             ],
             defaultValue=0,
         ))
     self.addParameter(
         QgsProcessingParameterEnum(
             self.QUOTING,
             self.tr('Quoting'),
             options=[
                 '{name}'.format(name=name)
                 for name, _ in _QUOTING_STRATEGIES
             ],
             defaultValue=0,
         ))
     self.addParameter(
         QgsProcessingParameterEnum(
             self.LINE_TERMINATOR,
             self.tr('End-line character'),
             options=[
                 '{name} ("{char}")'.format(name=name, char=char)
                 for name, char in _LINE_TERMINATORS
             ],
             defaultValue=0,
         ))
     self.addParameter(
         QgsProcessingParameterFileDestination(
             self.OUTPUT,
             self.tr('CSV file'),
             'CSV files (*.csv)',
         ))