示例#1
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')))
示例#2
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')))