예제 #1
0
 def test_yaml_load_file(self):
     file_path = os.path.join(get_modules_dir(), 'veriso_ee', 'module.yml')
     expected = {
         u'displayname': u'VeriSO (EE/EN)',
         u'ilimodels': [{
             u'epsg': u'21781',
             u'ilimodel': u'DM01AVCH24D',
             u'referenceframe': u'LV03'
         },
             {
                 u'epsg': u'2056',
                 u'ilimodel': u'DM01AVCH24LV95D',
                 u'referenceframe': u'LV95'
             },
             {
                 u'epsg': u'21781',
                 u'ilimodel': u'DM01AVBE11D',
                 u'referenceframe': u'LV03'
             },
             {
                 u'epsg': u'2056',
                 u'ilimodel': u'DM01AVBE11LV95D',
                 u'referenceframe': u'LV95'
             }]
     }
     loaded_dict = yaml_load_file(file_path)
     loaded_dict = json.loads(json.dumps(loaded_dict))
     self.assertDictEqual(loaded_dict, expected)
예제 #2
0
def get_info_from_yaml(path):
    try:
        data = yaml_load_file(path)
        name = data['name']
    except Exception as e:
        raise VerisoError('error parsing %s' % path, e)
    try:
        shortcut = data['shortcut']
    except KeyError:
        shortcut = ''

    return name, shortcut
예제 #3
0
    def init_gui(self):
        """Initialize the dialog:
        Set the current date.
        Accept only lower characters as project name (= database schema).
        Fill modules combobox.
        """
        today = QDateTime.currentDateTime()
        self.dateTimeEdit.setDateTime(today)
        self.dateTimeEdit.setCalendarPopup(True)

        # You are only allowed to use lower case characters as project name (
        # = database schema).
        self.lineEditDbSchema.setValidator(
            QRegExpValidator(QRegExp("^[a-z][a-z0-9_]+"),
                             self.lineEditDbSchema))

        # Fill out the modules combobox.
        try:
            modules_dir = os.path.join(get_modules_dir())
            modules = []

            for module_name in get_subdirs(modules_dir):
                module_file = os.path.join(modules_dir, module_name,
                                           'module.yml')
                if os.path.isfile(module_file):
                    module = yaml_load_file(module_file)
                    module['dirname'] = module_name
                    modules.append(module)

            if modules:
                sorted_modules_list = sorted(modules,
                                             key=lambda k: k['displayname'])
                self.cmbBoxAppModule.clear()
                for module in sorted_modules_list:
                    self.cmbBoxAppModule.addItem(str(module["displayname"]),
                                                 module)
                self.cmbBoxAppModule.insertItem(0, "", None)
                self.cmbBoxAppModule.setCurrentIndex(0)
        except Exception as e:
            message = "Error while parsing the available modules."
            self.message_bar.pushMessage("VeriSO",
                                         tr(message),
                                         QgsMessageBar.CRITICAL,
                                         duration=0)
            QgsMessageLog.logMessage(str(e), "VeriSO", QgsMessageLog.CRITICAL)
            return

        self.cmbBoxIliModelName.insertItem(0, "", None)

        return True
예제 #4
0
def get_baselayers(module_name):
    """Reads all baselayer definitions from a yaml file.

    Returns
      A list of dictionaries with all baselayer definitions. Otherwise
      False.
    """
    filename = os.path.join(get_modules_dir(), module_name, "baselayer",
                            "baselayer.yml")
    try:
        baselayers = yaml_load_file(filename)
        return baselayers
    except Exception as e:
        QgsMessageLog.logMessage(str(e), module_name, Qgis.Critical)
        return
    def get_extended_module_name(self):
        """
        # Read into module.yml to see if the module extends another module
        :return: the name of the extended module
        """
        modules_dir = os.path.join(get_modules_dir())
        module_file = os.path.join(modules_dir, self.module_name.lower(),
                                   'module.yml')

        if os.path.isfile(module_file):
            module_yaml = yaml_load_file(module_file)

            if 'extends' in module_yaml:
                return module_yaml['extends']

        return None
예제 #6
0
def get_check_topics(module_name):
    """Get all check topics (aka groups).

    Different languages are support. See the yaml file how to deal with it.

    Returns:
      A ordered dictionary with the topic name and corresponding check
      files (python). False if something went wrong.
    """

    topics_dir = os.path.join(get_modules_dir(), module_name, 'checks')

    checks = []
    for topic_dir in get_subdirs(topics_dir):
        topic_file = os.path.join(topics_dir, topic_dir, 'topic.yml')
        if os.path.isfile(topic_file):
            try:
                topic = yaml_load_file(topic_file)
                topic['topic_dir'] = topic_dir
                checks.append(topic)
            except VerisoError:
                raise
    try:
        locale = QSettings().value('locale/userLocale')[0:2]
    except TypeError:
        locale = 'de'
    try:
        topics = OrderedDict()
        checks = sorted(checks, key=lambda k: k['topic'][locale])
        for check in checks:
            topic = check["topic"]
            topic_dir = check["topic_dir"]

            # Check, if yaml file is multilingual.
            try:
                if topic in topics:
                    continue
                topics[topic] = check
                # TODO control this whe using checks_from_files
                # yaml is *not* multilingual.
            except:
                # yaml is multilingual.
                # If the language set in QGIS is not available in the
                # yaml file, the first language will be chosen

                # dinamically get the checks based on the available files
                checks_from_files = get_checks_from_files(
                    module_name, topic_dir)
                try:
                    my_topic = topic[locale]
                    my_check = OrderedDict()
                    my_check["topic"] = my_topic
                    # my_check["checks"] = check["checks"]
                    my_check["checks"] = checks_from_files
                    my_check["topic_dir"] = topic_dir
                    topics[my_topic] = my_check
                    # language found

                except:
                    # language *not* found
                    my_check = OrderedDict()
                    my_check["topic"] = list(topic.values())[0]
                    # my_check["checks"] = check["checks"]
                    my_check["checks"] = checks_from_files
                    my_check["topic_dir"] = topic_dir
                    topics[my_check["topic"]] = my_check
        return topics
    except Exception as e:
        print(str(e))
        raise VerisoError(str(e), e, tag=module_name)