Exemple #1
0
    def __init__(self, configuration, parent=None):
        QDialog.__init__(self, parent)
        self.setupUi(self)
        self.configuration = configuration
        self.db_simple_factory = DbSimpleFactory()

        self.pg_user_line_edit.setText(configuration.super_pg_user)
        self.pg_password_line_edit.setText(configuration.super_pg_password)

        self.custom_model_directories_line_edit.setText(
            configuration.custom_model_directories)
        self.custom_model_directories_box.setChecked(
            configuration.custom_model_directories_enabled)
        self.java_path_line_edit.setText(configuration.java_path)
        self.java_path_search_button.clicked.connect(
            qt_utils.make_file_selector(self.java_path_line_edit,
                                        self.tr('Select Java application'),
                                        self.tr('java (*)')))
        self.java_path_line_edit.setValidator(
            FileValidator(is_executable=True, allow_empty=True))
        self.validators = Validators()
        self.java_path_line_edit.textChanged.connect(
            self.validators.validate_line_edits)
        self.ili2db_logfile_path.setText(configuration.logfile_path)
        self.ili2db_logfile_search_button.clicked.connect(
            qt_utils.make_save_file_selector(self.ili2db_logfile_path,
                                             self.tr('Select log file'),
                                             self.tr('Text files (*.txt)')))
        self.ili2db_enable_debugging.setChecked(
            self.configuration.debugging_enabled)
        self.buttonBox.accepted.connect(self.accepted)
        self.buttonBox.helpRequested.connect(self.help_requested)
        self.custom_models_dir_button.clicked.connect(
            self.show_custom_model_dir)

        for db_id in self.db_simple_factory.get_db_list(False):
            db_id |= DbIliMode.ili
            self.ili2db_tool_combobox.addItem(db_id.name, db_id)

        self.ili2db_action_combobox.addItem(self.tr('Schema Import'),
                                            'schemaimport')
        self.ili2db_action_combobox.addItem(self.tr('Data Import'), 'import')
        self.ili2db_action_combobox.addItem(self.tr('Data Export'), 'export')

        self.ili2db_tool_combobox.currentIndexChanged.connect(
            self.ili2db_command_reload)
        self.ili2db_action_combobox.currentIndexChanged.connect(
            self.ili2db_command_reload)

        self.ili2db_command_reload()

        settings = QSettings()
        drop_mode = DropMode[settings.value('QgisModelBaker/drop_mode',
                                            DropMode.ASK.name, str)]
        self.chk_dontask_to_handle_dropped_files.setEnabled(
            drop_mode != DropMode.ASK)
        self.chk_dontask_to_handle_dropped_files.setChecked(
            drop_mode != DropMode.ASK)
    def _args(self, hide_password):
        """Gets the list of ili2db arguments from configuration.

        :param bool hide_password: *True* to mask the password, *False* otherwise.
        :return: ili2db arguments list.
        :rtype: list
        """
        self.configuration.tool = self.tool
        db_simple_factory = DbSimpleFactory()
        db_factory = db_simple_factory.create_factory(self.tool)

        config_manager = db_factory.get_db_command_config_manager(self.configuration)

        return config_manager.get_ili2db_args(hide_password)
Exemple #3
0
    def run(self):
        ili2db_bin = get_ili2db_bin(self.tool, self.stdout, self.stderr)
        if not ili2db_bin:
            return

        ili2db_jar_arg = ["-jar", ili2db_bin]

        self.configuration.tool = self.tool
        db_simple_factory = DbSimpleFactory()
        db_factory = db_simple_factory.create_factory(self.tool)

        config_manager = db_factory.get_db_command_config_manager(
            self.configuration)

        args = config_manager.get_ili2db_args(False)
        args_hide_password = config_manager.get_ili2db_args(True)

        java_path = get_java_path(self.configuration.base_configuration)

        proc = QProcess()
        proc.readyReadStandardError.connect(
            functools.partial(self.stderr_ready, proc=proc))
        proc.readyReadStandardOutput.connect(
            functools.partial(self.stdout_ready, proc=proc))

        proc.start(java_path, ili2db_jar_arg + args)

        if not proc.waitForStarted():
            proc = None

        if not proc:
            raise JavaNotFoundError()

        safe_args = ili2db_jar_arg + args_hide_password
        safe_command = java_path + ' ' + ' '.join(safe_args)
        self.process_started.emit(safe_command)

        self.__result = Importer.ERROR

        loop = QEventLoop()
        proc.finished.connect(loop.exit)
        loop.exec()

        self.process_finished.emit(proc.exitCode(), self.__result)
        return self.__result
Exemple #4
0
class OptionsDialog(QDialog, DIALOG_UI):
    def __init__(self, configuration, parent=None):
        QDialog.__init__(self, parent)
        self.setupUi(self)
        self.configuration = configuration
        self.db_simple_factory = DbSimpleFactory()

        self.pg_user_line_edit.setText(configuration.super_pg_user)
        self.pg_password_line_edit.setText(configuration.super_pg_password)

        self.custom_model_directories_line_edit.setText(
            configuration.custom_model_directories)
        self.custom_model_directories_box.setChecked(
            configuration.custom_model_directories_enabled)
        self.java_path_line_edit.setText(configuration.java_path)
        self.java_path_search_button.clicked.connect(
            qt_utils.make_file_selector(self.java_path_line_edit,
                                        self.tr('Select Java application'),
                                        self.tr('java (*)')))
        self.java_path_line_edit.setValidator(
            FileValidator(is_executable=True, allow_empty=True))
        self.validators = Validators()
        self.java_path_line_edit.textChanged.connect(
            self.validators.validate_line_edits)
        self.ili2db_logfile_path.setText(configuration.logfile_path)
        self.ili2db_logfile_search_button.clicked.connect(
            qt_utils.make_save_file_selector(self.ili2db_logfile_path,
                                             self.tr('Select log file'),
                                             self.tr('Text files (*.txt)')))
        self.ili2db_enable_debugging.setChecked(
            self.configuration.debugging_enabled)
        self.buttonBox.accepted.connect(self.accepted)
        self.buttonBox.helpRequested.connect(self.help_requested)
        self.custom_models_dir_button.clicked.connect(
            self.show_custom_model_dir)

        for db_id in self.db_simple_factory.get_db_list(False):
            db_id |= DbIliMode.ili
            self.ili2db_tool_combobox.addItem(db_id.name, db_id)

        self.ili2db_action_combobox.addItem(self.tr('Schema Import'),
                                            'schemaimport')
        self.ili2db_action_combobox.addItem(self.tr('Data Import'), 'import')
        self.ili2db_action_combobox.addItem(self.tr('Data Export'), 'export')

        self.ili2db_tool_combobox.currentIndexChanged.connect(
            self.ili2db_command_reload)
        self.ili2db_action_combobox.currentIndexChanged.connect(
            self.ili2db_command_reload)

        self.ili2db_command_reload()

    def accepted(self):
        self.configuration.custom_model_directories = self.custom_model_directories_line_edit.text(
        )
        self.configuration.custom_model_directories_enabled = self.custom_model_directories_box.isChecked(
        )
        self.configuration.java_path = self.java_path_line_edit.text().strip()
        self.configuration.logfile_path = self.ili2db_logfile_path.text()
        self.configuration.debugging_enabled = self.ili2db_enable_debugging.isChecked(
        )

        self.configuration.super_pg_user = self.pg_user_line_edit.text()
        self.configuration.super_pg_password = self.pg_password_line_edit.text(
        )

    def show_custom_model_dir(self):
        dlg = CustomModelDirDialog(
            self.custom_model_directories_line_edit.text(), self)
        dlg.exec_()

    def help_requested(self):
        os_language = QLocale(
            QSettings().value('locale/userLocale')).name()[:2]
        if os_language in ['es', 'de']:
            webbrowser.open(
                "https://opengisch.github.io/QgisModelBaker/docs/{}/user-guide.html#plugin-configuration"
                .format(os_language))
        else:
            webbrowser.open(
                "https://opengisch.github.io/QgisModelBaker/docs/user-guide.html#plugin-configuration"
            )

    def ili2db_command_reload(self):
        config = None

        if self.ili2db_action_combobox.currentData() == 'schemaimport':
            config = SchemaImportConfiguration()
        elif self.ili2db_action_combobox.currentData() == 'import':
            config = ImportDataConfiguration()
        elif self.ili2db_action_combobox.currentData() == 'export':
            config = ExportConfiguration()

        executable = 'java -jar {}.jar'.format(
            self.ili2db_tool_combobox.currentData().name)
        command = '\n  '.join([executable] + config.to_ili2db_args())

        self.ili2db_options_textedit.setText(command)
Exemple #5
0
def get_ili2db_bin(tool, stdout, stderr):
    from QgisModelBaker.libqgsprojectgen.db_factory.db_simple_factory import DbSimpleFactory

    if tool not in DbIliMode or tool == DbIliMode.ili:
        return None

    tool |= DbIliMode.ili  # Regardlless of the incoming form (i.e., pg or ili2pg), we need its corresponding ili tool
    tool_name = tool.name  # in fact, we need the name of the ili tool

    db_simple_factory = DbSimpleFactory()
    db_factory = db_simple_factory.create_factory(tool)

    ili_tool_version = db_factory.get_tool_version()
    ili_tool_url = db_factory.get_tool_url()

    dir_path = os.path.dirname(os.path.realpath(__file__))
    ili2db_dir = '{}-{}'.format(tool_name, ili_tool_version)

    ili2db_file = os.path.join(dir_path, 'bin', ili2db_dir,
                               '{}.jar'.format(tool_name))
    if not os.path.isfile(ili2db_file):
        try:
            os.mkdir(os.path.join(dir_path, 'bin'))
        except FileExistsError:
            pass

        tmpfile = tempfile.NamedTemporaryFile(suffix='.zip', delete=False)

        stdout.emit(
            QCoreApplication.translate(
                'ili2dbutils',
                'Downloading {} version {}…'.format(tool_name,
                                                    ili_tool_version)))

        try:
            download_file(ili_tool_url,
                          tmpfile.name,
                          on_progress=lambda received, total: stdout.emit('.'))
        except NetworkError as e:
            stderr.emit(
                QCoreApplication.translate(
                    'ili2dbutils',
                    'Could not download {tool_name}\n\n  Error: {error}\n\nFile "{file}" not found. Please download and extract <a href="{ili2db_url}">{tool_name}</a>'
                    .format(tool_name=tool_name,
                            ili2db_url=ili_tool_url,
                            error=e.msg,
                            file=ili2db_file)))
            return None

        try:
            with zipfile.ZipFile(tmpfile.name, "r") as z:
                z.extractall(os.path.join(dir_path, 'bin'))
        except zipfile.BadZipFile:
            # We will realize soon enough that the files were not extracted
            pass

        if not os.path.isfile(ili2db_file):
            stderr.emit(
                QCoreApplication.translate(
                    'ili2dbutils',
                    'File "{file}" not found. Please download and extract <a href="{ili2db_url}">{tool_name}</a>.'
                    .format(tool_name=tool_name,
                            file=ili2db_file,
                            ili2db_url=ili_tool_url)))
            return None

    return ili2db_file
Exemple #6
0
def get_ili2db_bin(tool, db_ili_version, stdout, stderr):
    from QgisModelBaker.libqgsprojectgen.db_factory.db_simple_factory import (
        DbSimpleFactory, )

    if tool not in DbIliMode or tool == DbIliMode.ili:
        raise RuntimeError("Tool {} not found".format(tool))

    tool |= (
        DbIliMode.ili
    )  # Regardless of the incoming form (i.e., pg or ili2pg), we need its corresponding ili tool
    tool_name = tool.name  # in fact, we need the name of the ili tool

    db_simple_factory = DbSimpleFactory()
    db_factory = db_simple_factory.create_factory(tool)

    ili_tool_version = db_factory.get_tool_version(db_ili_version)
    ili_tool_url = db_factory.get_tool_url(db_ili_version)

    dir_path = os.path.dirname(os.path.realpath(__file__))
    ili2db_dir = "{}-{}".format(tool_name, ili_tool_version)

    # the structure changed since 3.12.2
    if version.Version(ili_tool_version) < version.Version("3.12.2"):
        ili2db_file = os.path.join(
            dir_path,
            "bin",
            ili2db_dir,
            "{tool}-{version}/{tool}.jar".format(tool=tool_name,
                                                 version=ili_tool_version),
        )
    else:
        ili2db_file = os.path.join(
            dir_path,
            "bin",
            ili2db_dir,
            "{tool}-{version}.jar".format(tool=tool_name,
                                          version=ili_tool_version),
        )

    if not os.path.isfile(ili2db_file):
        try:
            os.makedirs(os.path.join(dir_path, "bin", ili2db_dir),
                        exist_ok=True)
        except FileExistsError:
            pass

        tmpfile = tempfile.NamedTemporaryFile(suffix=".zip", delete=False)

        stdout.emit(
            QCoreApplication.translate(
                "ili2dbutils",
                "Downloading {} version {}…".format(tool_name,
                                                    ili_tool_version),
            ))

        try:
            download_file(
                ili_tool_url,
                tmpfile.name,
                on_progress=lambda received, total: stdout.emit("."),
            )
        except NetworkError as e:
            stderr.emit(
                QCoreApplication.translate(
                    "ili2dbutils",
                    'Could not download {tool_name}\n\n  Error: {error}\n\nFile "{file}" not found. Please download and extract <a href="{ili2db_url}">{tool_name}</a>'
                    .format(
                        tool_name=tool_name,
                        ili2db_url=ili_tool_url,
                        error=e.msg,
                        file=ili2db_file,
                    ),
                ))
            return None

        try:
            with zipfile.ZipFile(tmpfile.name, "r") as z:
                z.extractall(os.path.join(dir_path, "bin", ili2db_dir))
        except zipfile.BadZipFile:
            # We will realize soon enough that the files were not extracted
            pass

        if not os.path.isfile(ili2db_file):
            stderr.emit(
                QCoreApplication.translate(
                    "ili2dbutils",
                    'File "{file}" not found. Please download and extract <a href="{ili2db_url}">{tool_name}</a>.'
                    .format(tool_name=tool_name,
                            file=ili2db_file,
                            ili2db_url=ili_tool_url),
                ))
            return None

    return ili2db_file