Skip to content

Commit

Permalink
Merge pull request #120 from opengisch/slash-vs-backslash
Browse files Browse the repository at this point in the history
For toppings avoid issues with backslashes
  • Loading branch information
signedav authored Nov 15, 2024
2 parents 8240c1e + 21f64d6 commit 3929f37
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
4 changes: 3 additions & 1 deletion modelbaker/dbconnector/gpkg_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,9 @@ def rename_dataset(self, tid, datasetname):
return False, self.tr('Could not rename dataset to "{}".').format(datasetname)

def get_topics_info(self):
if self._table_exists("T_ILI2DB_CLASSNAME"):
if self._table_exists("T_ILI2DB_CLASSNAME") and self._table_exists(
GPKG_METAATTRS_TABLE
):
cursor = self.conn.cursor()
cursor.execute(
"""
Expand Down
6 changes: 5 additions & 1 deletion modelbaker/dbconnector/mssql_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,11 @@ def rename_dataset(self, tid, datasetname):

def get_topics_info(self):
result = {}
if self.schema and self._table_exists("t_ili2db_classname"):
if (
self.schema
and self._table_exists("t_ili2db_classname")
and self._table_exists(METAATTRS_TABLE)
):
cur = self.conn.cursor()
cur.execute(
"""
Expand Down
6 changes: 5 additions & 1 deletion modelbaker/dbconnector/pg_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,11 @@ def rename_dataset(self, tid, datasetname):
return False, self.tr('Could not rename dataset "{}".').format(datasetname)

def get_topics_info(self):
if self.schema and self._table_exists("t_ili2db_classname"):
if (
self.schema
and self._table_exists("t_ili2db_classname")
and self._table_exists(PG_METAATTRS_TABLE)
):
cur = self.conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
cur.execute(
sql.SQL(
Expand Down
5 changes: 4 additions & 1 deletion modelbaker/ilitoppingmaker/ilitarget.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import datetime
import os
import pathlib

from ..libs.toppingmaker import Target
from ..libs.toppingmaker.utils import slugify
Expand Down Expand Up @@ -62,7 +63,9 @@ def ilidata_path_resolver(target, name, type):
_, relative_filedir_path = target.filedir_path(type)

id = target.unique_id_in_target_scope(target, slugify(f"{type}_{name}_001"))
path = os.path.join(relative_filedir_path, name)
path = pathlib.PureWindowsPath(
os.path.join(relative_filedir_path, name)
).as_posix()
type = type
toppingfile = {"id": id, "path": path, "type": type}
target.toppingfileinfo_list.append(toppingfile)
Expand Down
14 changes: 8 additions & 6 deletions modelbaker/iliwrapper/ilicache.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import glob
import logging
import os
import pathlib
import re
import shutil
import urllib.parse
Expand Down Expand Up @@ -685,20 +686,21 @@ def download_file(self, netloc, url, file, dataset_id=None):
file_url = self.file_url(url, file)

if url is None or os.path.isdir(url):
file_path = file_url
file_path = os.path.normpath(file_url)
# continue with the local file
if os.path.exists(file_url):
self.file_download_succeeded.emit(dataset_id, file_url)
if os.path.exists(file_path):
self.file_download_succeeded.emit(dataset_id, file_path)
else:
self.file_download_failed.emit(
dataset_id,
self.tr("Could not find local file {}").format(file_url),
self.tr("Could not find local file {}").format(file_path),
)
else:
file_path = os.path.join(self.CACHE_PATH, netloc, file)
file_path = os.path.normpath(os.path.join(self.CACHE_PATH, netloc, file))
file_dir = os.path.dirname(file_path)
os.makedirs(file_dir, exist_ok=True)

# in case there are backslashes in the url, remove them
file_url = pathlib.PureWindowsPath(file_url).as_posix()
download_file(
file_url,
file_path,
Expand Down

0 comments on commit 3929f37

Please sign in to comment.