def test_get_all_federal(config_path): Config._config = None Config.init(config_path, 'pyramid_oereb') all_federal = Config.get_all_federal() assert isinstance(all_federal, list) assert len(all_federal) == 2 assert 'ch.BelasteteStandorte' in all_federal
def test_config_wms_url_params(config_path, DummyRenderInfo): Config._config = None Config.init('./tests/contrib.print_proxy.mapfish_print/resources/test_config.yml', 'pyramid_oereb') renderer = Renderer(DummyRenderInfo()) config = renderer.get_wms_url_params() # Restore normal config Config._config = None Config.init(config_path, 'pyramid_oereb') # Do the check for this test. Value should match the one from the YAML configuration. assert config == {'TRANSPARENT': 'true', 'OTHERCUSTOM': 'myvalue'}
def test_bad_config_wms_url_params(config_path, DummyRenderInfo): Config._config = None Config.init('./tests/contrib.print_proxy.mapfish_print/resources/test_bad_config.yml', 'pyramid_oereb') renderer = Renderer(DummyRenderInfo()) config = renderer.get_wms_url_params() # Restore normal config Config._config = None Config.init(config_path, 'pyramid_oereb') # Do the check for this test. Value should be empty. assert config == {}
def test_get_layer_config(config_path): Config._config = None Config.init(config_path, 'pyramid_oereb') layer_index, layer_opacity = Config.get_layer_config('ch.Nutzungsplanung') assert layer_index == 1 assert layer_opacity == 0.25 layer_index, layer_opacity = Config.get_layer_config( 'ch.BelasteteStandorte') assert layer_index is None assert layer_opacity is None
def test_get_oereblex_config(config_path): Config._config = None Config.init(config_path, 'pyramid_oereb') cfg = Config.get_oereblex_config() assert isinstance(cfg, dict) assert cfg == { 'host': 'http://oereblex.example.com', 'language': 'de', 'proxy': { 'http': 'http://my.proxy.org', 'https': None } }
def test_get_real_estate_main_page_config(config_path): Config._config = None Config.init(config_path, 'pyramid_oereb') lang = Config.get('default_language') plan_for_land_register_main_page_config = Config.get_plan_for_land_register_main_page_config( ) assert plan_for_land_register_main_page_config.get( 'reference_wms' )[lang] == ( 'https://wms.geo.admin.ch/?SERVICE=WMS&REQUEST=GetMap&VERSION=1.3.0&' 'STYLES=default&CRS=EPSG:2056&BBOX=2475000,1065000,2850000,1300000&' 'WIDTH=493&HEIGHT=280&FORMAT=image/png&LAYERS=ch.swisstopo-vd.amtliche-vermessung' ) assert plan_for_land_register_main_page_config.get('layer_index') == 2 assert plan_for_land_register_main_page_config.get('layer_opacity') == 0.5
def test_get_logo_config(config_path): Config._config = None Config.init(config_path, 'pyramid_oereb') logo_config = Config.get_logo_config() assert isinstance(logo_config, dict) source = logo_config.get('source') assert isinstance(source, dict) class_config = source.get('class') assert isinstance(class_config, str) params = source.get('params') assert isinstance(params, dict) db_connection = params.get('db_connection') assert isinstance(db_connection, str) model = params.get('model') assert isinstance(model, str)
def test_add_existing_connection(): db_url = Config.get('app_schema').get('db_connection') adapter = DatabaseAdapter() adapter.add_connection(db_url) expected_length = len(adapter.get_connections()) adapter.add_connection(db_url) assert len(adapter.get_connections()) == expected_length
def test_get_custom_wms_params_true(config_path, DummyRenderInfo): Config._config = None Config.init('./tests/contrib.print_proxy.mapfish_print/resources/test_custom_config.yml', 'pyramid_oereb') renderer = Renderer(DummyRenderInfo()) # Define different test cases params1 = { 'TRANSPARENT': ['true'], 'OTHERCUSTOM': ['myvalue'], 'epoch': ['2018-11-29T15:13:31'] } params2 = { 'OTHERCUSTOM': ['myvalue'], 'epoch': ['2018-11-29T15:13:31'] } params3 = { 'epoch': '2018-11-29T15:13:31' } params4 = { 'epoch': ['2018-11-29T15:13:31', '2020-11-29T17:13:50'] } config1 = renderer.get_custom_wms_params(params1) config2 = renderer.get_custom_wms_params(params2) config3 = renderer.get_custom_wms_params(params3) config4 = renderer.get_custom_wms_params(params4) # Restore normal config Config._config = None Config.init(config_path, 'pyramid_oereb') # Do the check for the different test cases. Value should match the ones from the YAML configuration. assert config1 == { 'TRANSPARENT': 'true', 'epoch': '2018-11-29T15:13:31' } assert config2 == { 'epoch': '2018-11-29T15:13:31' } assert config3 == { 'epoch': '2018-11-29T15:13:31' } assert config4 == { 'epoch': '2018-11-29T15:13:31,2020-11-29T17:13:50' }
def plr_tolerance_check(self, extract): """ The function checking if the found plr results exceed the minimal surface or length value defined in the configuration and should therefor be represented in the extract or considered 'false trues' and be removed from the results. Args: extract (pyramid_oereb.lib.records.extract.ExtractRecord): The extract in it's unvalidated form Returns: pyramid_oereb.lib.records.extract.ExtractRecord: Returns the updated extract """ real_estate = extract.real_estate inside_plrs = [] outside_plrs = [] for public_law_restriction in real_estate.public_law_restrictions: if isinstance(public_law_restriction, PlrRecord) and public_law_restriction.published: # Test if the geometries list is now empty - if so remove plr from plr list if public_law_restriction.calculate(real_estate, Config.get('geometry_types')): log.debug("plr_tolerance_check: keeping as potentially concerned plr {}". format(public_law_restriction)) inside_plrs.append(self.filter_published_documents(public_law_restriction)) else: log.debug("plr_tolerance_check: removing from the concerned plrs {}". format(public_law_restriction)) outside_plrs.append(public_law_restriction) # Check if theme is concerned def is_inside_plr(theme_code): for plr in inside_plrs: if plr.theme.code == theme_code: return True return False # Ensure only ConcernedThemes are contained in PLRs themes_to_move = [] for i, theme in enumerate(extract.concerned_theme): if not is_inside_plr(theme.code): themes_to_move.append(i) if len(themes_to_move) > 0: themes_to_move.reverse() for idx in themes_to_move: new_not_concerned_theme = extract.concerned_theme.pop(idx) log.debug("plr_tolerance_check() moving from concerned_theme to not_concerned_theme: {}" .format(new_not_concerned_theme) ) extract.not_concerned_theme.append(new_not_concerned_theme) # Need to reorder, because order must stay exactly as defined in configuration extract.not_concerned_theme = sorted(extract.not_concerned_theme, key=attrgetter('extract_index')) real_estate.public_law_restrictions = self.get_legend_entries(inside_plrs, outside_plrs) return extract
def test_get_custom_wms_params_false(config_path, DummyRenderInfo): Config._config = None Config.init('./tests/contrib.print_proxy.mapfish_print/resources/test_config.yml', 'pyramid_oereb') renderer = Renderer(DummyRenderInfo()) params = { 'TRANSPARENT': ['true'], 'OTHERCUSTOM': ['myvalue'], 'epoch': ['2018-11-29T15:13:31'] } config = renderer.get_custom_wms_params(params) # Restore normal config Config._config = None Config.init(config_path, 'pyramid_oereb') assert config == { 'OTHERCUSTOM': 'myvalue', 'TRANSPARENT': 'true' }
def view_service_handling(real_estate, images, extract_format, language): """ Handles all view service related stuff. In the moment this is: * construction of the correct url (reference_wms, multilingual) depending on the real estate * downloading of the image (if parameter was set) for the requested or default language Args: real_estate (pyramid_oereb.lib.records.real_estate.RealEstateRecord): The real estate record to be updated. images (bool): Switch whether the images should be downloaded or not. extract_format (string): The format currently used. For 'pdf' format, the used map size will be adapted to the pdf format. language (string or None): Which language of the reference WMS should be used Returns: pyramid_oereb.lib.records.real_estate.RealEstateRecord: The updated extract. """ language = language or Config.get('default_language') map_size = Config.get_map_size(extract_format) bbox = Config.get_bbox(real_estate.limit) real_estate.plan_for_land_register.get_full_wms_url( language, map_size[0], map_size[1], bbox ) real_estate.plan_for_land_register_main_page.get_full_wms_url( language, map_size[0], map_size[1], bbox ) if images: real_estate.plan_for_land_register.download_wms_content(language) real_estate.plan_for_land_register_main_page.download_wms_content(language) for public_law_restriction in real_estate.public_law_restrictions: public_law_restriction.view_service.get_full_wms_url(language, map_size[0], map_size[1], bbox) if images: public_law_restriction.view_service.download_wms_content(language) return real_estate
def __init__(self, plr_sources, plr_cadastre_authority): """ Args: plr_sources (list of pyramid_oereb.lib.sources.plr.PlrBaseSource): The list of PLR source instances which the achieved extract should be about. plr_cadastre_authority (pyramid_oereb.lib.records.office.OfficeRecord): The authority responsible for the PLR cadastre. """ self.extract = None self._plr_sources_ = plr_sources self._plr_cadastre_authority_ = plr_cadastre_authority self.law_status = Config.get_law_status_codes()
def test_parse_configuration(config_path): Config._config = None Config.init(config_path, 'section2') assert Config.get('param1') == 1 assert len(Config.get('param2')) == 2 assert Config.get('param2')[0] == 'first' assert Config.get('param2')[1] == 'second'
def __init__(self, configuration, section='pyramid_oereb', c2ctemplate_style=False, directory='sample_data', sql_file=None): """ Args: configuration (str): Path to the configuration yaml file. section (str): The used section within the yaml file. Default is `pyramid_oereb`. c2ctemplate_style (bool): True if the yaml use a c2c template style (vars.[section]). Default is False. directory (str): Location of the sample data. Default is `sample_data`. sql_file (file): The SQL file to be created. Default is None. """ self._configuration = configuration self._section = section self._directory = directory self._sql_file = sql_file Config.init(self._configuration, self._section, c2ctemplate_style)
def create_processor(): """ Creates and returns a processor based on the application configuration. You should use one (and only one) processor per request. Otherwise some results can be mixed or missing. Returns: pyramid_oereb.lib.processor.Processor: A processor. """ real_estate_config = Config.get_real_estate_config() municipality_config = Config.get_municipality_config() disclaimer_config = Config.get_disclaimer_config() glossary_config = Config.get_glossary_config() plr_cadastre_authority = Config.get_plr_cadastre_authority() real_estate_reader = RealEstateReader( real_estate_config.get('source').get('class'), **real_estate_config.get('source').get('params') ) municipality_reader = MunicipalityReader( municipality_config.get('source').get('class'), **municipality_config.get('source').get('params') ) disclaimer_reader = DisclaimerReader( disclaimer_config.get('source').get('class'), **disclaimer_config.get('source').get('params') ) glossary_reader = GlossaryReader( glossary_config.get('source').get('class'), **glossary_config.get('source').get('params') ) plr_sources = [] for plr in Config.get('plrs'): plr_source_class = DottedNameResolver().maybe_resolve(plr.get('source').get('class')) plr_sources.append(plr_source_class(**plr)) extract_reader = ExtractReader( plr_sources, plr_cadastre_authority ) return Processor( real_estate_reader=real_estate_reader, municipality_reader=municipality_reader, disclaimer_reader=disclaimer_reader, glossary_reader=glossary_reader, plr_sources=plr_sources, extract_reader=extract_reader, )
def test_mfp_service(mock_responses, pyramid_test_config, real_estate_data, municipalities, themes, real_estate_types_test_data, logos, general_information ): request = MockRequest() request.matchdict.update({ 'format': 'PDF' }) request.params.update({ # 'GEOMETRY': 'true', 'EGRID': 'TEST', # 'TOPICS': topics }) from pyramid_oereb.core.config import Config pyramid_test_config.add_renderer('pyramid_oereb_extract_print', Config.get('print').get('renderer')) service = PlrWebservice(request) response = service.get_extract_by_id() assert response.status_code == 200
def process(self, real_estate, params, sld_url): """ Central processing method to hook in from webservice. Args: real_estate (pyramid_oereb.lib.records.real_estate.RealEstateRecord): The real estate reader to obtain the real estates record. params (pyramid_oereb.views.webservice.Parameter): The parameters of the extract request. sld_url (str): The URL which provides the sld to style and filter the highlight of the real estate. Returns: pyramid_oereb.lib.records.extract.ExtractRecord: The generated extract record. """ log.debug("process() start") municipality = self._municipality_reader_.read(params, real_estate.fosnr)[0] disclaimers = self._disclaimer_reader_.read(params) glossaries = self._glossary_reader_.read(params) extract_raw = self._extract_reader_.read(params, real_estate, municipality) extract = self.plr_tolerance_check(extract_raw) resolver = DottedNameResolver() sort_within_themes_method_string = Config.get('extract').get('sort_within_themes_method') if sort_within_themes_method_string: sort_within_themes_method = resolver.resolve(sort_within_themes_method_string) extract = sort_within_themes_method(extract) else: log.info("No configuration is provided for extract sort_within_themes_method;" " no further sorting is applied.") # the selection of view services is done after the tolerance check. This enables us to take # care about the circumstance that after tolerance check plrs will be dismissed which were # recognized as intersecting before. To avoid this the tolerance check is gathering all plrs # intersecting and not intersecting and starts the legend entry sorting after. self.view_service_handling(extract.real_estate, params.images, params.format, params.language) extract.disclaimers = disclaimers extract.glossaries = glossaries log.debug("process() done, returning extract.") return extract
def includeme(config): """ By including this in your pyramid web app you can easily provide a running OEREB Server Args: config (Configurator): The pyramid apps config object """ global route_prefix # Set route prefix route_prefix = config.route_prefix # Get settings settings = config.get_settings() # Load configuration file cfg_file = settings.get('pyramid_oereb.cfg.file', None) cfg_c2ctemplate_file = settings.get('pyramid_oereb.cfg.c2ctemplate.file', None) cfg_section = settings.get('pyramid_oereb.cfg.section', None) Config.init(cfg_file or cfg_c2ctemplate_file, cfg_section, cfg_file is None, init_data=True) Config.update_settings(settings) settings.update({'pyramid_oereb': Config.get_config()}) config.add_renderer('pyramid_oereb_extract_json', 'pyramid_oereb.core.renderer.extract.json_.Renderer') config.add_renderer('pyramid_oereb_extract_xml', 'pyramid_oereb.core.renderer.extract.xml_.Renderer') config.add_renderer('pyramid_oereb_extract_print', Config.get('print').get('renderer')) config.add_renderer('pyramid_oereb_versions_xml', 'pyramid_oereb.core.renderer.versions.xml_.Renderer') config.add_renderer( 'pyramid_oereb_capabilities_xml', 'pyramid_oereb.core.renderer.capabilities.xml_.Renderer') config.add_renderer('pyramid_oereb_getegrid_xml', 'pyramid_oereb.core.renderer.getegrid.xml_.Renderer') config.include('pyramid_oereb.core.routes')
def create_tables_from_standard_configuration(configuration_yaml_path, section='pyramid_oereb', c2ctemplate_style=False, tables_only=False, sql_file=None, if_not_exists=False): """ Creates all schemas which are defined in the passed yaml file: <section>.<plrs>.[<plr>.<code>]. The code must be camel case. It will be transformed to snake case and used as schema name. Creates all tables inside the created schemas. This only affects the sqlalchemy models which are defined with the Base class from pyramid_oereb.standard.models. Args: configuration_yaml_path (str): The absolute path to the yaml file which contains the plr definitions. section (str): The section in yaml file where the plrs are configured in. Default is 'pyramid_oereb'. c2ctemplate_style (bool): True if the yaml use a c2c template style (vars.[section]). Default is False. tables_only (bool): True to skip creation of schema. Default is False. sql_file (file): the file to generate. Default is None (in the database). """ if Config.get_config() is None: Config.init(configuration_yaml_path, section, c2ctemplate_style) main_base_class = DottedNameResolver().maybe_resolve( '{package}.Base'.format( package=Config.get('app_schema').get('models'))) main_schema_name = Config.get('app_schema').get('name') main_tables = tables(main_base_class) if tables_only: sql = create_tables_sql(main_tables, if_not_exists) else: sql = create_sql(main_schema_name, main_tables, if_not_exists) sql_file.write(sql) for theme_config in Config.get('plrs'): if theme_config.get('standard'): create_theme_tables_(theme_config, tables_only=tables_only, sql_file=sql_file, if_not_exists=if_not_exists)
def test_get_plr_cadastre_authority(config_path): Config._config = None Config.init(config_path, 'pyramid_oereb') plr_cadastre_authority = Config.get_plr_cadastre_authority() assert isinstance(plr_cadastre_authority, OfficeRecord)
def test_configuration_file_not_found(): Config._config = None with pytest.raises(IOError) as excinfo: Config.init('not_existing_config.yml', 'invalidsection') assert ', Current working directory is ' in str(excinfo.value)
def test_wrong_configuration_section(config_path): Config._config = None with pytest.raises(ConfigurationError): Config.init(config_path, 'invalidsection')
def test_missing_configuration_section(): Config._config = None with pytest.raises(ConfigurationError): Config.init('myconfig.yml', None)
def test_missing_configuration_file(): Config._config = None with pytest.raises(ConfigurationError): Config.init(None, None)
def test_get_localized_text_from_string(DummyRenderInfo): renderer = Renderer(DummyRenderInfo()) localized_text = renderer.get_localized_text('Test') assert isinstance(localized_text, dict) assert localized_text.get('Text') == 'Test' assert localized_text.get('Language') == Config.get('default_language')
def create_legend_entries_in_standard_db(config, topic_code, temp_creation_path='/tmp/pyconizer', language='de', section='pyramid_oereb', c2ctemplate_style=False, image_format='image/png', image_height=36, image_width=72, encoding=None, replace_host=None, replace_layer=None, string_keys=False, by_type_code=False): """ Uses the pyconizer core to create images out of the OEREB server configuration. It is creating symbols for a dedicated topic. This function will clean all previously created icons from database. Args: config (str): The path to the used OEREB server configuration YAML file. topic_code (str): The topic code for which the symbols should be created. It must be configured in the passed yml. temp_creation_path: The path where the images are created in. language: The language which is used to produce the WMS rules. This is a tricky part. You must provide the language your WMS is using. section: The section which the config can be found in the yml. c2ctemplate_style (bool): True if the yaml use a c2c template style (vars.[section]). Default is False. image_format: The image format. This is passed throug to the WMS request. You need to provide a format your WMS is supporting here. image_height: The height of the produced image. image_width: The width of the produced image. encoding (str or unicode): The encoding which is used to encode the XML. Standard is None. This means the encoding is taken from the XML content itself. Only use this parameter if your XML content has no encoding set. replace_host (str or None): The host which should be used instead of the one which is in the data. This is only recommended on deploy process when your WMS might be already available on a DEV instance but not on the production system which is linked in the data. Then you can create legend entries by obtaining them from this DEV instance. replace_layer (str or None): The layer which should be used instead of the one which is in the data. This is only recommended on deploy process when your WMS might be already available on a DEV instance serving a special legend layer but not on the production system which is linked in the data. Then you can create legend entries by obtaining them from this DEV instances special legend layer. string_keys (bool): Switch for setting primary key for legend entries whether to string or integer by_type_code (bool): If set the process will use the type_code instead of name for obtaining the legend icons. This needs a WMS layer to be configured with the type_code in its name property. It prevents the legend entry creation process to be broken for case sensitive class names in MAPSERVER. Because the "RULE" parameter of the GetLegendGraphics request on MAPSERVER seems to be case insensitive. """ # config object parsed from oereb configuration yml Config.init(config, section, c2ctemplate_style) db_connection = None found = False # try to find the topic in config and create the orm models for further processing for topic in Config.get('plrs'): if topic.get('code') == topic_code: db_connection = topic.get('source').get('params').get( 'db_connection') Plr = DottedNameResolver().maybe_resolve( '{models_path}.PublicLawRestriction'.format( models_path=topic.get('source').get('params').get( 'models'))) LegendEntry = DottedNameResolver().maybe_resolve( '{models_path}.LegendEntry'.format(models_path=topic.get( 'source').get('params').get('models'))) found = True break if not found: # at this point it was not possible to find the topic in configuration log.error( 'The topic with code "{0}" was not found in passed configuration!'. format(topic_code)) return # we can start process now... engine = create_engine(db_connection, echo=True) Session = orm.scoped_session(orm.sessionmaker(bind=engine)) session = Session() # clean up table first session.execute( '''TRUNCATE TABLE {schema}.{table} RESTART IDENTITY'''.format( schema=LegendEntry.__table__.schema, table=LegendEntry.__table__.name)) # select all plrs from distinct on information, view_service_id and type_code unique_plrs = session.query(Plr).distinct(Plr.view_service_id, Plr.type_code).all() pyconizer_config = [] type_code_list = [] # first create the configuration for the pyconizer package for unique_plr in unique_plrs: if unique_plr.type_code not in type_code_list: type_code_list.append(unique_plr.type_code) url, params = parse_url(unique_plr.view_service.reference_wms) layer_existent = False service_url = urlunsplit((url.scheme, url.netloc, url.path, '', '')) \ if replace_host is None else replace_host layer = params.get( 'LAYERS')[0] if replace_layer is None else replace_layer for layer_config in pyconizer_config: if layer_config.get('url') == service_url and \ layer_config.get('layer') == layer: layer_existent = True if not layer_existent: pyconizer_config.append({ 'url': service_url, 'layer': layer, 'get_styles': { 'request': 'GetStyles', 'service': 'WMS', 'srs': params.get('SRS'), 'version': params.get('VERSION') }, 'get_legend': { 'image_format': image_format, 'request': 'GetLegendGraphic', 'service': 'WMS', 'version': params.get('VERSION'), 'width': image_width, 'height': image_height } }) # create the icons with pyconizer package create_icons_from_scratch(pyconizer_config, temp_creation_path, images=True, encoding=encoding) # reuse plr legend text to build legend entries and assign the symbol i = 1 for unique_plr in unique_plrs: url, params = parse_url(unique_plr.view_service.reference_wms) layer = params.get( 'LAYERS')[0] if replace_layer is None else replace_layer # obtain symbol from pyconizer structure. if by_type_code: class_name = unique_plr.type_code else: if isinstance(unique_plr.legend_text, dict): class_name = unique_plr.legend_text.get(language) else: class_name = unique_plr.legend_text symbol = get_icon(temp_creation_path, layer, class_name) if symbol: session.add( LegendEntry(id=str(i) if string_keys else i, symbol=symbol, legend_text=unique_plr.legend_text, type_code=unique_plr.type_code, topic=unique_plr.topic, type_code_list=''.join(type_code_list), view_service_id=unique_plr.view_service_id)) session.flush() i += 1 else: log.warn('It was not possible to find a symbol for the class: {0}'. format(class_name)) session.commit() session.close()
the behaviour of the ORM's here. This means the names class variables as well as the types of these variables. """ from pyramid_oereb.contrib.data_sources.standard.models import get_office, get_document from sqlalchemy import Column, PrimaryKeyConstraint, ForeignKey, UniqueConstraint from sqlalchemy import Unicode, String, text, Integer, Boolean, Float from geoalchemy2 import Geometry from sqlalchemy.ext.declarative import declarative_base from sqlalchemy_utils import JSONType from sqlalchemy.orm import relationship from pyramid_oereb.core.config import Config Base = declarative_base() app_schema_name = Config.get('app_schema').get('name') srid = Config.get('srid') class RealEstate(Base): """ The container where you can throw in all the real estates this application should have access to, for creating extracts. Attributes: id (int): The identifier. This is used in the database only and must not be set manually. If you don't like it - don't care about. identdn (str): The identifier on cantonal level. number (str): The identifier on municipality level. egrid (str): The identifier on federal level (the all unique one...) type (str): The type of the real estate (This must base on DM01)
def pyramid_oereb_test_config(config_path, dbsession): del dbsession # Reload the standard test configuration and now initialize it Config._config = None # needed to force reload due to internal assertion Config.init(config_path, configsection='pyramid_oereb', init_data=True) return Config
def create_theme_tables(): parser = optparse.OptionParser( usage='usage: %prog [options]', description='Create all content for the standard database') parser.add_option('-c', '--configuration', dest='configuration', metavar='YAML', type='string', help='The absolute path to the configuration yaml file.') parser.add_option( '-s', '--section', dest='section', metavar='SECTION', type='string', default='pyramid_oereb', help= 'The section which contains configuration (default is: pyramid_oereb).' ) parser.add_option('-t', '--theme', dest='theme', metavar='CODE', type='string', help='The code of the theme to be created.') parser.add_option('-T', '--tables-only', dest='tables_only', action='store_true', default=False, help='Use this flag to skip the creation of the schema.') parser.add_option('--sql-file', type='string', help='Generate an SQL file.') parser.add_option( '--c2ctemplate-style', dest='c2ctemplate_style', action='store_true', default=False, help='Is the yaml file using a c2ctemplate style (starting with vars)') options, args = parser.parse_args() if not options.configuration: parser.error('No configuration file set.') if not options.theme: parser.error('No theme code specified.') if Config.get_config() is None: Config.init(options.configuration, options.section, options.c2ctemplate_style) theme_config = Config.get_theme_config_by_code(options.theme) if theme_config is None: parser.error('Specified theme not found in configuration.') if options.sql_file is None: create_theme_tables_(theme_config, tables_only=options.tables_only) else: with open(options.sql_file, 'w') as sql_file: create_theme_tables_(theme_config, tables_only=options.tables_only, sql_file=sql_file)