Skip to content

Commit

Permalink
Merge pull request #46 from opengisch/metaconfig-lib
Browse files Browse the repository at this point in the history
Metaconfigurations on ili2db command
  • Loading branch information
signedav authored Jan 6, 2023
2 parents d16af72 + d24d66c commit a8e53fa
Show file tree
Hide file tree
Showing 5 changed files with 442 additions and 23 deletions.
7 changes: 6 additions & 1 deletion modelbaker/ilitoppingmaker/metaconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
class MetaConfig(object):
"""
Class containing all the data needed to create the metaconfiguration file.
Having the section [CONFIGURATION] containing the links to the referencedata nd the projecttoppingfile.
Having the section [CONFIGURATION] containing the links to the referencedata and the projecttoppingfile as well as the setting to consider only the metaconfig params for ili2db.
And the section [ch.ehi.ili2db] containing all the ili2db settings.
"""

Expand All @@ -42,6 +42,7 @@ class MetaConfig(object):
def __init__(self):
self.referencedata_paths = []
self.projecttopping_path = None
self.metaconfigparamsonly = False
self.ili2db_settings = Ili2dbSettings()

def update_referencedata_paths(self, value: Union[list, bool]):
Expand All @@ -59,6 +60,7 @@ def generate_files(self, target: Target):
[CONFIGURATION]
qgis.modelbaker.projecttopping=ilidata:ch.opengis.config.KbS_LV95_V1_4_projecttopping
ch.interlis.referenceData=ilidata:ch.opengis.config.KbS_Codetexte_V1_4
qgis.modelbaker.metaConfigParamsOnly = true
[ch.ehi.ili2db]
defaultSrsCode = 2056
Expand Down Expand Up @@ -95,6 +97,9 @@ def generate_files(self, target: Target):
)
configuration_section["ch.interlis.referenceData"] = referencedata_links

if self.metaconfigparamsonly:
configuration_section["qgis.modelbaker.metaConfigParamsOnly"] = True

ili2db_section = {}

# append models and the ili2db parameters
Expand Down
64 changes: 42 additions & 22 deletions modelbaker/iliwrapper/ili2dbconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,19 @@ def __init__(self):
self.disable_validation = False
self.metaconfig = None
self.metaconfig_id = None
self.metaconfig_params_only = False
self.db_ili_version = None

def append_args(self, args, values, consider_metaconfig=False):
def append_args(self, args, values, consider_metaconfig=False, force_append=False):

if consider_metaconfig and self.metaconfig and values:
if "ch.ehi.ili2db" in self.metaconfig.sections():
if not force_append and self.metaconfig and self.metaconfig_id and values:
if self.metaconfig_params_only:
return
if consider_metaconfig and "ch.ehi.ili2db" in self.metaconfig.sections():
metaconfig_ili2db_params = self.metaconfig["ch.ehi.ili2db"]
if values[0][2:] in metaconfig_ili2db_params.keys():
# since passing metaconfig is not supported yet. see https://github.com/claeis/ili2db/issues/392 we do not avoid adding the value to the args
print(
"Value {} from metaconfiguration file not considered. ".format(
values[0][2:]
)
)
# if the value is set in the metaconfig, then we do consider it instead
return
args += values

def to_ili2db_args(self):
Expand All @@ -152,15 +151,28 @@ def to_ili2db_args(self):

proxy = QgsNetworkAccessManager.instance().fallbackProxy()
if proxy.type() == QNetworkProxy.HttpProxy:
self.append_args(args, ["--proxy", proxy.hostName()])
self.append_args(args, ["--proxyPort", str(proxy.port())])
self.append_args(args, ["--proxy", proxy.hostName()], force_append=True)
self.append_args(
args, ["--proxyPort", str(proxy.port())], force_append=True
)

if self.ilimodels:
self.append_args(args, ["--models", self.ilimodels])

if self.tomlfile:
self.append_args(args, ["--iliMetaAttrs", self.tomlfile])

elif self.db_ili_version is None or self.db_ili_version > 3:
self.append_args(args, ["--iliMetaAttrs", "NULL"])

# needs to start with "ilidata:" or should be a local file path
if self.metaconfig_id:
self.append_args(
args,
["--metaConfig", self.metaconfig_id],
force_append=True,
)

return args


Expand Down Expand Up @@ -226,20 +238,19 @@ def to_ili2db_args(self, extra_args=[], with_action=True):
args = list()

if with_action:
self.append_args(args, ["--schemaimport"])
self.append_args(args, ["--schemaimport"], force_append=True)

self.append_args(args, extra_args)
self.append_args(args, extra_args, force_append=True)

self.append_args(args, ["--coalesceCatalogueRef"], True)
self.append_args(args, ["--createEnumTabs"], True)

if self.disable_validation:
self.append_args(args, ["--sqlEnableNull"])

self.append_args(args, ["--sqlEnableNull"], force_append=True)
else:
self.append_args(args, ["--createNumChecks"])
self.append_args(args, ["--createUnique"])
self.append_args(args, ["--createFk"])
self.append_args(args, ["--createNumChecks"], True)
self.append_args(args, ["--createUnique"], True)
self.append_args(args, ["--createFk"], True)

self.append_args(args, ["--createFkIdx"], True)
self.append_args(args, ["--coalesceMultiSurface"], True)
Expand Down Expand Up @@ -269,25 +280,34 @@ def to_ili2db_args(self, extra_args=[], with_action=True):

if self.stroke_arcs:
self.append_args(args, ["--strokeArcs"])
elif self.db_ili_version is None or self.db_ili_version > 3:
self.append_args(args, ["--strokeArcs=False"])

if self.create_basket_col:
self.append_args(args, ["--createBasketCol"])
elif self.db_ili_version is None or self.db_ili_version > 3:
self.append_args(args, ["--createBasketCol=False"])

if self.srs_auth != "EPSG":
self.append_args(args, ["--defaultSrsAuth", self.srs_auth])
self.append_args(args, ["--defaultSrsAuth", self.srs_auth])

self.append_args(args, ["--defaultSrsCode", "{}".format(self.srs_code)])

if self.pre_script:
self.append_args(args, ["--preScript", self.pre_script])
elif self.db_ili_version is None or self.db_ili_version > 3:
self.append_args(args, ["--preScript", "NULL"])

if self.post_script:
self.append_args(args, ["--postScript", self.post_script])
elif self.db_ili_version is None or self.db_ili_version > 3:
self.append_args(args, ["--postScript", "NULL"])

self.append_args(args, Ili2DbCommandConfiguration.to_ili2db_args(self))
self.append_args(
args, Ili2DbCommandConfiguration.to_ili2db_args(self), force_append=True
)

if self.ilifile:
self.append_args(args, [self.ilifile])
self.append_args(args, [self.ilifile], force_append=True)

return args

Expand Down
Loading

0 comments on commit a8e53fa

Please sign in to comment.