def read_from_ini(cls, ini_file_path):
        translator = CustomTranslator()
        locale = Locale.get_locale()

        dir_path = os.path.abspath(os.path.join(ini_file_path, os.path.pardir))
        ini_file = codecs.open(ini_file_path, 'r', 'utf-8')

        parser = ConfigParser()
        parser.readfp(ini_file)

        ds = DataSourceInfo()

        # Required
        ds.id = ConfigReaderHelper.try_read_config(parser, 'general', 'id', reraise=True)
        ds.type = ConfigReaderHelper.try_read_config(parser, 'general', 'type', reraise=True)

        ds.group = ConfigReaderHelper.try_read_config(parser, 'ui', 'group', reraise=True)
        ds.alias = ConfigReaderHelper.try_read_config(parser, 'ui', 'alias', reraise=True)
        ds.icon = ConfigReaderHelper.try_read_config(parser, 'ui', 'icon')

        # Lic & Terms
        ds.lic_name = ConfigReaderHelper.try_read_config(parser, 'license', 'name')
        ds.lic_link = ConfigReaderHelper.try_read_config(parser, 'license', 'link')
        ds.copyright_text = ConfigReaderHelper.try_read_config(parser, 'license', 'copyright_text')
        ds.copyright_link = ConfigReaderHelper.try_read_config(parser, 'license', 'copyright_link')
        ds.terms_of_use = ConfigReaderHelper.try_read_config(parser, 'license', 'terms_of_use')

        #TMS
        ds.tms_url = ConfigReaderHelper.try_read_config(parser, 'tms', 'url', reraise=(ds.type == KNOWN_DRIVERS.TMS))
        ds.tms_zmin = ConfigReaderHelper.try_read_config_int(parser, 'tms', 'zmin')
        ds.tms_zmax = ConfigReaderHelper.try_read_config_int(parser, 'tms', 'zmax')
        ds.tms_y_origin_top = ConfigReaderHelper.try_read_config_int(parser, 'tms', 'y_origin_top')
        ds.tms_epsg_crs_id = ConfigReaderHelper.try_read_config_int(parser, 'tms', 'epsg_crs_id')
        ds.tms_postgis_crs_id = ConfigReaderHelper.try_read_config_int(parser, 'tms', 'postgis_crs_id')
        ds.tms_custom_proj = ConfigReaderHelper.try_read_config(parser, 'tms', 'custom_proj')

        #WMS
        ds.wms_url = ConfigReaderHelper.try_read_config(parser, 'wms', 'url', reraise=(ds.type == KNOWN_DRIVERS.WMS))
        ds.wms_params = ConfigReaderHelper.try_read_config(parser, 'wms', 'params')
        ds.wms_layers = ConfigReaderHelper.try_read_config(parser, 'wms', 'layers')
        ds.wms_turn_over = ConfigReaderHelper.try_read_config_bool(parser, 'wms', 'turn_over')

        #GDAL
        if ds.type == KNOWN_DRIVERS.GDAL:
            gdal_conf = ConfigReaderHelper.try_read_config(parser, 'gdal', 'source_file', reraise=(ds.type == KNOWN_DRIVERS.GDAL))
            ds.gdal_source_file = os.path.join(dir_path, gdal_conf)

        #try read translations
        posible_trans = parser.items('ui')
        for key, val in posible_trans:
            if type(key) is unicode and key == 'alias[%s]' % locale:
                translator.append(ds.alias, val)
                break

        #internal stuff
        ds.file_path = ini_file_path
        ds.icon_path = os.path.join(dir_path, ds.icon) if ds.icon else None

        return ds
Пример #2
0
class GroupsList:

    def __init__(self, group_paths=ALL_GROUP_PATHS):
        self.locale = Locale.get_locale()
        self.translator = CustomTranslator()
        self.paths = group_paths
        self.groups = {}
        self._fill_groups_list()

    def _fill_groups_list(self):
        self.groups = {}
        for gr_path in self.paths:
            if gr_path in ROOT_MAPPING.keys():
                category = ROOT_MAPPING[gr_path]
            else:
                category = GroupCategory.USER

            for root, dirs, files in os.walk(gr_path):
                for ini_file in [f for f in files if f.endswith('.ini')]:
                    self._read_ini_file(root, ini_file, category)

    def _read_ini_file(self, root, ini_file_path, category):
        try:
            ini_full_path = os.path.join(root, ini_file_path)
            parser = ConfigParser()
            ini_file = codecs.open(ini_full_path, 'r', 'utf-8')
            parser.readfp(ini_file)
            #read config
            group_id = parser.get('general', 'id')
            group_alias = parser.get('ui', 'alias')
            icon_file = ConfigReaderHelper.try_read_config(parser, 'ui', 'icon')
            group_icon_path = os.path.join(root, icon_file) if icon_file else None
            #try read translations
            posible_trans = parser.items('ui')
            for key, val in posible_trans:
                if type(key) is unicode and key == 'alias[%s]' % self.locale:
                    self.translator.append(group_alias, val)
                    break
            #create menu
            group_menu = QMenu(self.tr(group_alias))
            group_menu.setIcon(QIcon(group_icon_path))
            #append to all groups
            # set contrib&user
            self.groups[group_id] = GroupInfo(group_id, group_alias, group_icon_path, ini_full_path, group_menu, category)
        except Exception, e:
            error_message = self.tr('Group INI file can\'t be parsed: ') + e.message
            QgsMessageLog.logMessage(error_message, level=QgsMessageLog.CRITICAL)
Пример #3
0
class GroupsList:

    def __init__(self, group_paths=ALL_GROUP_PATHS):
        self.locale = Locale.get_locale()
        self.translator = CustomTranslator()
        self.paths = group_paths
        self.groups = {}
        self._fill_groups_list()

    def _fill_groups_list(self):
        self.groups = {}
        for gr_path in self.paths:
            if gr_path in ROOT_MAPPING.keys():
                category = ROOT_MAPPING[gr_path]
            else:
                category = GroupCategory.USER

            for root, dirs, files in os.walk(gr_path):
                for ini_file in [f for f in files if f.endswith('.ini')]:
                    self._read_ini_file(root, ini_file, category)

    def _read_ini_file(self, root, ini_file_path, category):
        try:
            ini_full_path = os.path.join(root, ini_file_path)
            parser = ConfigParser()
            ini_file = codecs.open(ini_full_path, 'r', 'utf-8')
            parser.readfp(ini_file)
            #read config
            group_id = parser.get('general', 'id')
            group_alias = parser.get('ui', 'alias')
            icon_file = ConfigReaderHelper.try_read_config(parser, 'ui', 'icon')
            group_icon_path = os.path.join(root, icon_file) if icon_file else None
            #try read translations
            posible_trans = parser.items('ui')
            for key, val in posible_trans:
                if type(key) is unicode and key == 'alias[%s]' % self.locale:
                    self.translator.append(group_alias, val)
                    break
            #create menu
            group_menu = QMenu(self.tr(group_alias))
            group_menu.setIcon(QIcon(group_icon_path))
            #append to all groups
            # set contrib&user
            self.groups[group_id] = GroupInfo(group_id, group_alias, group_icon_path, ini_full_path, group_menu, category)
        except Exception, e:
            error_message = self.tr('Group INI file can\'t be parsed: ') + e.message
            QgsMessageLog.logMessage(error_message, level=QgsMessageLog.CRITICAL)
    def read_from_ini(cls, ini_file_path):
        translator = CustomTranslator()
        locale = Locale.get_locale()

        dir_path = os.path.abspath(os.path.join(ini_file_path, os.path.pardir))
        ini_file = codecs.open(ini_file_path, "r", "utf-8")

        parser = ConfigParser()
        parser.readfp(ini_file)

        ds = DataSourceInfo()

        # Required
        ds.id = ConfigReaderHelper.try_read_config(parser, "general", "id", reraise=True)
        ds.type = ConfigReaderHelper.try_read_config(parser, "general", "type", reraise=True)

        ds.group = ConfigReaderHelper.try_read_config(parser, "ui", "group", reraise=True)
        ds.alias = ConfigReaderHelper.try_read_config(parser, "ui", "alias", reraise=True)
        ds.icon = ConfigReaderHelper.try_read_config(parser, "ui", "icon")

        # Lic & Terms
        ds.lic_name = ConfigReaderHelper.try_read_config(parser, "license", "name")
        ds.lic_link = ConfigReaderHelper.try_read_config(parser, "license", "link")
        ds.copyright_text = ConfigReaderHelper.try_read_config(parser, "license", "copyright_text")
        ds.copyright_link = ConfigReaderHelper.try_read_config(parser, "license", "copyright_link")
        ds.terms_of_use = ConfigReaderHelper.try_read_config(parser, "license", "terms_of_use")

        # TMS
        ds.tms_url = ConfigReaderHelper.try_read_config(parser, "tms", "url", reraise=(ds.type == KNOWN_DRIVERS.TMS))
        ds.tms_zmin = ConfigReaderHelper.try_read_config_int(parser, "tms", "zmin")
        ds.tms_zmax = ConfigReaderHelper.try_read_config_int(parser, "tms", "zmax")
        ds.tms_y_origin_top = ConfigReaderHelper.try_read_config_int(parser, "tms", "y_origin_top")
        ds.tms_epsg_crs_id = ConfigReaderHelper.try_read_config_int(parser, "tms", "epsg_crs_id")
        ds.tms_postgis_crs_id = ConfigReaderHelper.try_read_config_int(parser, "tms", "postgis_crs_id")
        ds.tms_custom_proj = ConfigReaderHelper.try_read_config(parser, "tms", "custom_proj")

        # WMS
        ds.wms_url = ConfigReaderHelper.try_read_config(parser, "wms", "url", reraise=(ds.type == KNOWN_DRIVERS.WMS))
        ds.wms_params = ConfigReaderHelper.try_read_config(parser, "wms", "params")
        ds.wms_layers = ConfigReaderHelper.try_read_config(parser, "wms", "layers")
        ds.wms_turn_over = ConfigReaderHelper.try_read_config_bool(parser, "wms", "turn_over")

        # GDAL
        if ds.type == KNOWN_DRIVERS.GDAL:
            gdal_conf = ConfigReaderHelper.try_read_config(
                parser, "gdal", "source_file", reraise=(ds.type == KNOWN_DRIVERS.GDAL)
            )
            ds.gdal_source_file = os.path.join(dir_path, gdal_conf)

        # WMS
        ds.wfs_url = ConfigReaderHelper.try_read_config(parser, "wfs", "url", reraise=(ds.type == KNOWN_DRIVERS.WFS))
        # ds.wfs_layers = ConfigReaderHelper.try_read_config(parser, 'wfs', 'layers')

        # try read translations
        posible_trans = parser.items("ui")
        for key, val in posible_trans:
            if type(key) is unicode and key == "alias[%s]" % locale:
                translator.append(ds.alias, val)
                break

        # internal stuff
        ds.file_path = ini_file_path
        ds.icon_path = os.path.join(dir_path, ds.icon) if ds.icon else None

        return ds
    def read_from_ini(cls, ini_file_path):
        translator = CustomTranslator()
        locale = Locale.get_locale()

        dir_path = os.path.abspath(os.path.join(ini_file_path, os.path.pardir))
        ini_file = codecs.open(ini_file_path, 'r', 'utf-8')

        parser = ConfigParser()
        parser.readfp(ini_file)

        ds = DataSourceInfo()

        # Required
        ds.id = ConfigReaderHelper.try_read_config(parser,
                                                   'general',
                                                   'id',
                                                   reraise=True)
        ds.type = ConfigReaderHelper.try_read_config(parser,
                                                     'general',
                                                     'type',
                                                     reraise=True)

        ds.group = ConfigReaderHelper.try_read_config(parser,
                                                      'ui',
                                                      'group',
                                                      reraise=True)
        ds.alias = ConfigReaderHelper.try_read_config(parser,
                                                      'ui',
                                                      'alias',
                                                      reraise=True)
        ds.icon = ConfigReaderHelper.try_read_config(parser, 'ui', 'icon')

        # Lic & Terms
        ds.lic_name = ConfigReaderHelper.try_read_config(
            parser, 'license', 'name')
        ds.lic_link = ConfigReaderHelper.try_read_config(
            parser, 'license', 'link')
        ds.copyright_text = ConfigReaderHelper.try_read_config(
            parser, 'license', 'copyright_text')
        ds.copyright_link = ConfigReaderHelper.try_read_config(
            parser, 'license', 'copyright_link')
        ds.terms_of_use = ConfigReaderHelper.try_read_config(
            parser, 'license', 'terms_of_use')

        #TMS
        ds.tms_url = ConfigReaderHelper.try_read_config(
            parser, 'tms', 'url', reraise=(ds.type == KNOWN_DRIVERS.TMS))
        ds.tms_zmin = ConfigReaderHelper.try_read_config_int(
            parser, 'tms', 'zmin')
        ds.tms_zmax = ConfigReaderHelper.try_read_config_int(
            parser, 'tms', 'zmax')
        ds.tms_y_origin_top = ConfigReaderHelper.try_read_config_int(
            parser, 'tms', 'y_origin_top')
        ds.tms_epsg_crs_id = ConfigReaderHelper.try_read_config_int(
            parser, 'tms', 'epsg_crs_id')
        ds.tms_postgis_crs_id = ConfigReaderHelper.try_read_config_int(
            parser, 'tms', 'postgis_crs_id')
        ds.tms_custom_proj = ConfigReaderHelper.try_read_config(
            parser, 'tms', 'custom_proj')

        #WMS
        ds.wms_url = ConfigReaderHelper.try_read_config(
            parser, 'wms', 'url', reraise=(ds.type == KNOWN_DRIVERS.WMS))
        ds.wms_params = ConfigReaderHelper.try_read_config(
            parser, 'wms', 'params')
        ds.wms_layers = ConfigReaderHelper.try_read_config(
            parser, 'wms', 'layers')
        ds.wms_turn_over = ConfigReaderHelper.try_read_config_bool(
            parser, 'wms', 'turn_over')

        #GDAL
        if ds.type == KNOWN_DRIVERS.GDAL:
            gdal_conf = ConfigReaderHelper.try_read_config(
                parser,
                'gdal',
                'source_file',
                reraise=(ds.type == KNOWN_DRIVERS.GDAL))
            ds.gdal_source_file = os.path.join(dir_path, gdal_conf)

        #WMS
        ds.wfs_url = ConfigReaderHelper.try_read_config(
            parser, 'wfs', 'url', reraise=(ds.type == KNOWN_DRIVERS.WFS))
        # ds.wfs_layers = ConfigReaderHelper.try_read_config(parser, 'wfs', 'layers')

        #try read translations
        posible_trans = parser.items('ui')
        for key, val in posible_trans:
            if type(key) is unicode and key == 'alias[%s]' % locale:
                translator.append(ds.alias, val)
                break

        #internal stuff
        ds.file_path = ini_file_path
        ds.icon_path = os.path.join(dir_path, ds.icon) if ds.icon else None

        return ds