Skip to content

Commit

Permalink
renaming metaconfigcache and it's variables to ilidata / ilidatafile …
Browse files Browse the repository at this point in the history
…because it's not only used for metaconfig files but as well for referenceData and (in future) projecttoppings

getting datasource from preferredDataSource category
  • Loading branch information
signedav committed Nov 30, 2023
1 parent 60f260f commit a5e8249
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 42 deletions.
6 changes: 3 additions & 3 deletions modelbaker/iliwrapper/ili2dbconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def model_directories(self):
return dirs

@property
def metaconfig_directories(self):
def ilidata_directories(self):
dirs = list()
if self.custom_model_directories_enabled and self.custom_model_directories:
dirs = self.custom_model_directories.split(";")
Expand Down Expand Up @@ -451,7 +451,7 @@ def to_ili2db_args(self, extra_args=[], with_action=True):

if self.db_ili_version == 3:
self.append_args(args, ["--export3"])

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

Expand All @@ -461,7 +461,7 @@ def to_ili2db_args(self, extra_args=[], with_action=True):

if self.valid_config:
self.append_args(args, ["--validConfig", self.valid_config])

if self.db_ili_version == 3:
self.append_args(args, [self.xtffile])

Expand Down
80 changes: 41 additions & 39 deletions modelbaker/iliwrapper/ilicache.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ class IliDataCache(IliCache):
file_download_failed = pyqtSignal(str, str)
model_refreshed = pyqtSignal(int)

CACHE_PATH = os.path.expanduser("~/.ilimetaconfigcache")
CACHE_PATH = os.path.expanduser("~/.ilidatacache")

def __init__(self, configuration, type="metaconfig", models=None):
IliCache.__init__(self, configuration)
Expand All @@ -450,7 +450,7 @@ def __init__(self, configuration, type="metaconfig", models=None):
self.filter_models = models.split(";") if models else []
self.type = type
self.directories = (
self.base_configuration.metaconfig_directories
self.base_configuration.ilidata_directories
if self.base_configuration
else []
)
Expand Down Expand Up @@ -478,22 +478,23 @@ def _process_informationfile(self, file, netloc, url):

model_code_regex = re.compile("http://codes.interlis.ch/model/(.*)")
type_code_regex = re.compile("http://codes.interlis.ch/type/(.*)")
tool_code_regex = re.compile("http://codes.opengis.ch/(.*)")
datasource_code_regex = re.compile(
"http://codes.modelbaker.ch/preferredDataSource/(.*)"
)

self.repositories[netloc] = list()
repo_metaconfigs = list()
repo_ilidatafiles = list()
for repo in root.iter(
"{http://www.interlis.ch/INTERLIS2.3}DatasetIdx16.DataIndex"
):
for metaconfig_metadata in repo.findall(
for ilidata_metadata in repo.findall(
"ili23:DatasetIdx16.DataIndex.DatasetMetadata", self.ns
):
categories_element = metaconfig_metadata.find(
"ili23:categories", self.ns
)
categories_element = ilidata_metadata.find("ili23:categories", self.ns)
if categories_element is not None:
models = []
type = ""
datasource = ""
for category in categories_element.findall(
"ili23:DatasetIdx16.Code_", self.ns
):
Expand All @@ -507,15 +508,17 @@ def _process_informationfile(self, file, netloc, url):
)
if type_code_regex.search(category_value):
type = type_code_regex.search(category_value).group(1)
if tool_code_regex.search(category_value):
tool_code_regex.search(category_value).group(1)
if datasource_code_regex.search(category_value):
datasource = datasource_code_regex.search(
category_value
).group(1)
if (
not any(model in models for model in self.filter_models)
or type != self.type
):
continue
title = list()
for title_element in metaconfig_metadata.findall(
for title_element in ilidata_metadata.findall(
"ili23:title", self.ns
):
for multilingual_text_element in title_element.findall(
Expand Down Expand Up @@ -547,7 +550,7 @@ def _process_informationfile(self, file, netloc, url):

short_description = list()

for short_description_element in metaconfig_metadata.findall(
for short_description_element in ilidata_metadata.findall(
"ili23:shortDescription", self.ns
):
for (
Expand Down Expand Up @@ -582,7 +585,7 @@ def _process_informationfile(self, file, netloc, url):
)

model_link_names = []
for basket_element in metaconfig_metadata.findall(
for basket_element in ilidata_metadata.findall(
"ili23:baskets", self.ns
):
for basket_metadata in basket_element.findall(
Expand All @@ -600,7 +603,7 @@ def _process_informationfile(self, file, netloc, url):
)
)

for files_element in metaconfig_metadata.findall(
for files_element in ilidata_metadata.findall(
"ili23:files", self.ns
):
for data_file in files_element.findall(
Expand All @@ -616,40 +619,39 @@ def _process_informationfile(self, file, netloc, url):
file.find("ili23:path", self.ns)
)

metaconfig = dict()
metaconfig["id"] = self.get_element_text(
metaconfig_metadata.find("ili23:id", self.ns)
ilidatafile = dict()
ilidatafile["id"] = self.get_element_text(
ilidata_metadata.find("ili23:id", self.ns)
)

metaconfig["version"] = self.get_element_text(
metaconfig_metadata.find(
"ili23:version", self.ns
)
ilidatafile["version"] = self.get_element_text(
ilidata_metadata.find("ili23:version", self.ns)
)
metaconfig["owner"] = self.get_element_text(
metaconfig_metadata.find("ili23:owner", self.ns)
ilidatafile["owner"] = self.get_element_text(
ilidata_metadata.find("ili23:owner", self.ns)
)

metaconfig["repository"] = netloc
metaconfig["url"] = url
metaconfig["models"] = models
metaconfig["relative_file_path"] = path
ilidatafile["repository"] = netloc
ilidatafile["url"] = url
ilidatafile["models"] = models
ilidatafile["datasource"] = datasource
ilidatafile["relative_file_path"] = path
if title is not None:
metaconfig["title"] = title
ilidatafile["title"] = title
else:
metaconfig["title"] = None
ilidatafile["title"] = None
if short_description is not None:
metaconfig[
ilidatafile[
"short_description"
] = short_description
else:
metaconfig["short_description"] = None
ilidatafile["short_description"] = None

metaconfig["model_link_names"] = model_link_names
repo_metaconfigs.append(metaconfig)
ilidatafile["model_link_names"] = model_link_names
repo_ilidatafiles.append(ilidatafile)

self.repositories[netloc] = sorted(
repo_metaconfigs,
repo_ilidatafiles,
key=lambda m: m["version"] if m["version"] else "0",
reverse=True,
)
Expand Down Expand Up @@ -770,7 +772,7 @@ def set_repositories(self, repositories):
self.endResetModel()


class MetaConfigCompleterDelegate(QItemDelegate):
class IliDataFileCompleterDelegate(QItemDelegate):
"""
A item delegate for the autocompleter of metaconfig / topping dialogs.
It shows the source repository (including model) next to the metaconfig id and the owner.
Expand All @@ -781,11 +783,11 @@ def __init__(self):
self.widget = QWidget()
self.widget.setLayout(QGridLayout())
self.widget.layout().setContentsMargins(2, 0, 0, 0)
self.metaconfig_label = QLabel()
self.metaconfig_label.setAttribute(Qt.WA_TranslucentBackground)
self.ilidatafile_label = QLabel()
self.ilidatafile_label.setAttribute(Qt.WA_TranslucentBackground)
self.repository_label = QLabel()
self.repository_label.setAlignment(Qt.AlignRight)
self.widget.layout().addWidget(self.metaconfig_label, 0, 0)
self.widget.layout().addWidget(self.ilidatafile_label, 0, 0)
self.widget.layout().addWidget(self.repository_label, 0, 1)

def paint(self, painter, option, index):
Expand All @@ -801,7 +803,7 @@ def drawDisplay(self, painter, option, rect, text):
repository=repository
)
)
self.metaconfig_label.setText(
self.ilidatafile_label.setText(
"{display_text}".format(display_text=display_text)
)
self.widget.setMinimumSize(rect.size())
Expand Down

0 comments on commit a5e8249

Please sign in to comment.