def _read_ini_file(self, root, ini_file_path): try: ini_file = codecs.open(os.path.join(root, ini_file_path), 'r', 'utf-8') parser = ConfigParser() parser.readfp(ini_file) ds = DataSourceInfo() # Required ds.id = self.try_read_config(parser, 'general', 'id', reraise=True) ds.type = self.try_read_config(parser, 'general', 'type', reraise=True) ds.is_contrib = self.try_read_config(parser, 'general', 'is_contrib', reraise=True) ds.group = self.try_read_config(parser, 'ui', 'group', reraise=True) ds.alias = self.try_read_config(parser, 'ui', 'alias', reraise=True) ds.icon = self.try_read_config(parser, 'ui', 'icon', reraise=True) # Lic & Terms ds.lic_name = self.try_read_config(parser, 'license', 'name') ds.lic_link = self.try_read_config(parser, 'license', 'link') ds.copyright_text = self.try_read_config(parser, 'license', 'copyright_text') ds.copyright_link = self.try_read_config(parser, 'license', 'copyright_link') ds.terms_of_use = self.try_read_config(parser, 'license', 'terms_of_use') #TMS ds.tms_url = self.try_read_config(parser, 'tms', 'url', reraise=(ds.type == KNOWN_DRIVERS.TMS)) ds.tms_zmin = self.try_read_config_int(parser, 'tms', 'zmin') ds.tms_zmax = self.try_read_config_int(parser, 'tms', 'zmax') ds.tms_crs = self.try_read_config_int(parser, 'tms', 'crs') ds.tms_proj = self.try_read_config(parser, 'tms', 'proj') ds.tms_y_origin_top = self.try_read_config_int(parser, 'tms', 'y_origin_top') #WMS ds.wms_url = self.try_read_config(parser, 'wms', 'url', reraise=(ds.type == KNOWN_DRIVERS.WMS)) ds.wms_params = self.try_read_config(parser, 'wms', 'params') ds.wms_layers = self.try_read_config(parser, 'wms', 'layers') ds.wms_turn_over = self.try_read_config_bool(parser, 'wms', 'turn_over') #GDAL if ds.type == KNOWN_DRIVERS.GDAL: gdal_conf = self.try_read_config(parser, 'gdal', 'source_file', reraise=(ds.type == KNOWN_DRIVERS.GDAL)) ds.gdal_source_file = os.path.join(root, 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]' % self.locale: self.translator.append(ds.alias, val) break #Action stuff ds.icon_path = os.path.join(root, ds.icon) ds.action = QAction(QIcon(ds.icon_path), self.tr(ds.alias), None) ds.action.setData(ds) #append to array self.data_sources[ds.id] = ds except Exception, e: error_message = 'metadata.ini file in %s can\'t be parsed: %s' % (root, e.message) QgsMessageLog.logMessage(error_message, level=QgsMessageLog.CRITICAL)