Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For toppings avoid issues with backslashes #120

Merged
merged 2 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion modelbaker/ilitoppingmaker/ilitarget.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ 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 = os.path.join(relative_filedir_path, name).replace("\\", "/")
type = type
toppingfile = {"id": id, "path": path, "type": type}
target.toppingfileinfo_list.append(toppingfile)
Expand Down
13 changes: 7 additions & 6 deletions modelbaker/iliwrapper/ilicache.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,20 +685,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 = file_url.replace("\\", "/")
download_file(
file_url,
file_path,
Expand Down
Loading