From 678f31aa21b3f98a9f7106ab4ef2c3d22b8d6348 Mon Sep 17 00:00:00 2001 From: SJiB Date: Thu, 17 Oct 2024 17:59:18 +0200 Subject: [PATCH 01/15] Add except if geojson_crs_def cannot be defined --- qgepqwat2ili/qgepdss/export.py | 87 ++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 40 deletions(-) diff --git a/qgepqwat2ili/qgepdss/export.py b/qgepqwat2ili/qgepdss/export.py index 7b0c845c..4e1c2630 100644 --- a/qgepqwat2ili/qgepdss/export.py +++ b/qgepqwat2ili/qgepdss/export.py @@ -3795,60 +3795,67 @@ def textpos_common(row, t_type, geojson_crs_def): with open(labels_file) as labels_file_handle: labels = json.load(labels_file_handle) - geojson_crs_def = labels["crs"] - for label in labels["features"]: - layer_name = label["properties"]["Layer"] - obj_id = label["properties"]["qgep_obj_id"] - - print(f"label[properties]: {label['properties']}") + try: + geojson_crs_def = labels["crs"] + except: + logger.warning( + f"No labels available - no labels will be exported" + ) + else: + for label in labels["features"]: + layer_name = label["properties"]["Layer"] + obj_id = label["properties"]["qgep_obj_id"] - if not label["properties"]["LabelText"]: - logger.warning( - f"Label of object '{obj_id}' from layer '{layer_name}' is empty and will not be exported" - ) - continue + print(f"label[properties]: {label['properties']}") - if layer_name == "vw_qgep_reach": - if obj_id not in tid_for_obj_id["haltung"]: + if not label["properties"]["LabelText"]: logger.warning( - f"Label for haltung `{obj_id}` exists, but that object is not part of the export" + f"Label of object '{obj_id}' from layer '{layer_name}' is empty and will not be exported" ) continue - ili_label = ABWASSER.haltung_text( - **textpos_common(label, "haltung_text", geojson_crs_def), - haltungref=tid_for_obj_id["haltung"][obj_id], - ) - elif layer_name == "vw_qgep_wastewater_structure": - if obj_id not in tid_for_obj_id["abwasserbauwerk"]: - logger.warning( - f"Label for abwasserbauwerk `{obj_id}` exists, but that object is not part of the export" + if layer_name == "vw_qgep_reach": + if obj_id not in tid_for_obj_id["haltung"]: + logger.warning( + f"Label for haltung `{obj_id}` exists, but that object is not part of the export" + ) + continue + ili_label = ABWASSER.haltung_text( + **textpos_common(label, "haltung_text", geojson_crs_def), + haltungref=tid_for_obj_id["haltung"][obj_id], + ) + + elif layer_name == "vw_qgep_wastewater_structure": + if obj_id not in tid_for_obj_id["abwasserbauwerk"]: + logger.warning( + f"Label for abwasserbauwerk `{obj_id}` exists, but that object is not part of the export" + ) + continue + ili_label = ABWASSER.abwasserbauwerk_text( + **textpos_common(label, "abwasserbauwerk_text", geojson_crs_def), + abwasserbauwerkref=tid_for_obj_id["abwasserbauwerk"][obj_id], + ) + + elif layer_name == "catchment_area": + if obj_id not in tid_for_obj_id["einzugsgebiet"]: + logger.warning( + f"Label for einzugsgebiet `{obj_id}` exists, but that object is not part of the export" + ) + continue + ili_label = ABWASSER.einzugsgebiet_text( + **textpos_common(label, "einzugsgebiet_text", geojson_crs_def), + einzugsgebietref=tid_for_obj_id["einzugsgebiet"][obj_id], ) - continue - ili_label = ABWASSER.abwasserbauwerk_text( - **textpos_common(label, "abwasserbauwerk_text", geojson_crs_def), - abwasserbauwerkref=tid_for_obj_id["abwasserbauwerk"][obj_id], - ) - elif layer_name == "catchment_area": - if obj_id not in tid_for_obj_id["einzugsgebiet"]: + else: logger.warning( - f"Label for einzugsgebiet `{obj_id}` exists, but that object is not part of the export" + f"Unknown layer for label `{layer_name}`. Label will be ignored", ) continue - ili_label = ABWASSER.einzugsgebiet_text( - **textpos_common(label, "einzugsgebiet_text", geojson_crs_def), - einzugsgebietref=tid_for_obj_id["einzugsgebiet"][obj_id], - ) - else: - logger.warning( - f"Unknown layer for label `{layer_name}`. Label will be ignored", - ) - continue + abwasser_session.add(ili_label) - abwasser_session.add(ili_label) print(".", end="") logger.info("done") abwasser_session.flush() From ecb39fb7cfccf2b94a8919bc7da38d4100b20772 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 17 Oct 2024 19:16:30 +0000 Subject: [PATCH 02/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- qgepqwat2ili/qgepdss/export.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/qgepqwat2ili/qgepdss/export.py b/qgepqwat2ili/qgepdss/export.py index 4e1c2630..d4eb1c92 100644 --- a/qgepqwat2ili/qgepdss/export.py +++ b/qgepqwat2ili/qgepdss/export.py @@ -3795,13 +3795,10 @@ def textpos_common(row, t_type, geojson_crs_def): with open(labels_file) as labels_file_handle: labels = json.load(labels_file_handle) - try: geojson_crs_def = labels["crs"] except: - logger.warning( - f"No labels available - no labels will be exported" - ) + logger.warning(f"No labels available - no labels will be exported") else: for label in labels["features"]: layer_name = label["properties"]["Layer"] From 092eb30679700b71507ae06aa5f2467fc29087e5 Mon Sep 17 00:00:00 2001 From: SJiB Date: Thu, 17 Oct 2024 21:18:53 +0200 Subject: [PATCH 03/15] adaot logger.warning - no f string as no variable in text --- qgepqwat2ili/qgepdss/export.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qgepqwat2ili/qgepdss/export.py b/qgepqwat2ili/qgepdss/export.py index d4eb1c92..7bfa31dd 100644 --- a/qgepqwat2ili/qgepdss/export.py +++ b/qgepqwat2ili/qgepdss/export.py @@ -3798,7 +3798,7 @@ def textpos_common(row, t_type, geojson_crs_def): try: geojson_crs_def = labels["crs"] except: - logger.warning(f"No labels available - no labels will be exported") + logger.warning("No labels available - no labels will be exported") else: for label in labels["features"]: layer_name = label["properties"]["Layer"] From bb46127a1d31330dd4b57f2c81516031cfb5fd7f Mon Sep 17 00:00:00 2001 From: SJiB Date: Thu, 17 Oct 2024 21:31:02 +0200 Subject: [PATCH 04/15] add finally: --- qgepqwat2ili/qgepdss/export.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/qgepqwat2ili/qgepdss/export.py b/qgepqwat2ili/qgepdss/export.py index 7bfa31dd..e5dc9bd2 100644 --- a/qgepqwat2ili/qgepdss/export.py +++ b/qgepqwat2ili/qgepdss/export.py @@ -3797,7 +3797,7 @@ def textpos_common(row, t_type, geojson_crs_def): try: geojson_crs_def = labels["crs"] - except: + except geojson_crs_defError: logger.warning("No labels available - no labels will be exported") else: for label in labels["features"]: @@ -3854,8 +3854,10 @@ def textpos_common(row, t_type, geojson_crs_def): abwasser_session.add(ili_label) print(".", end="") - logger.info("done") - abwasser_session.flush() + + finally: + logger.info("done") + abwasser_session.flush() # -- extra commit abwasser_session.commit() From d275b1f5d82e75a1ea2524a90e0ace54cc300f40 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 17 Oct 2024 19:31:16 +0000 Subject: [PATCH 05/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- qgepqwat2ili/qgepdss/export.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qgepqwat2ili/qgepdss/export.py b/qgepqwat2ili/qgepdss/export.py index e5dc9bd2..9111a8dc 100644 --- a/qgepqwat2ili/qgepdss/export.py +++ b/qgepqwat2ili/qgepdss/export.py @@ -3854,7 +3854,7 @@ def textpos_common(row, t_type, geojson_crs_def): abwasser_session.add(ili_label) print(".", end="") - + finally: logger.info("done") abwasser_session.flush() From bce93661b91fc9ba50fd526b4c9481da3ca60fd3 Mon Sep 17 00:00:00 2001 From: SJiB Date: Thu, 17 Oct 2024 21:39:01 +0200 Subject: [PATCH 06/15] adapt except --- qgepqwat2ili/qgepdss/export.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qgepqwat2ili/qgepdss/export.py b/qgepqwat2ili/qgepdss/export.py index e5dc9bd2..3e44dceb 100644 --- a/qgepqwat2ili/qgepdss/export.py +++ b/qgepqwat2ili/qgepdss/export.py @@ -3797,7 +3797,7 @@ def textpos_common(row, t_type, geojson_crs_def): try: geojson_crs_def = labels["crs"] - except geojson_crs_defError: + except: logger.warning("No labels available - no labels will be exported") else: for label in labels["features"]: From 548fdd57a2fc53fa768e9152b95171fe5e1b6f6f Mon Sep 17 00:00:00 2001 From: Arnaud Poncet-Montanges Date: Fri, 18 Oct 2024 13:25:08 +0200 Subject: [PATCH 07/15] Except Exception to potentially deal with the exception --- qgepqwat2ili/qgepdss/export.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qgepqwat2ili/qgepdss/export.py b/qgepqwat2ili/qgepdss/export.py index 2a8e9cd8..de70b9ef 100644 --- a/qgepqwat2ili/qgepdss/export.py +++ b/qgepqwat2ili/qgepdss/export.py @@ -3797,7 +3797,7 @@ def textpos_common(row, t_type, geojson_crs_def): try: geojson_crs_def = labels["crs"] - except: + except Exception: logger.warning("No labels available - no labels will be exported") else: for label in labels["features"]: From c29f6fa4e637b4456051ecdd4fe5e570bcd95a0a Mon Sep 17 00:00:00 2001 From: SJiB Date: Thu, 17 Oct 2024 17:59:18 +0200 Subject: [PATCH 08/15] Add except if geojson_crs_def cannot be defined --- qgepqwat2ili/qgepdss/export.py | 87 ++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 40 deletions(-) diff --git a/qgepqwat2ili/qgepdss/export.py b/qgepqwat2ili/qgepdss/export.py index 488573a2..f17a8b14 100644 --- a/qgepqwat2ili/qgepdss/export.py +++ b/qgepqwat2ili/qgepdss/export.py @@ -3795,60 +3795,67 @@ def textpos_common(row, t_type, geojson_crs_def): with open(labels_file) as labels_file_handle: labels = json.load(labels_file_handle) - geojson_crs_def = labels["crs"] - for label in labels["features"]: - layer_name = label["properties"]["Layer"] - obj_id = label["properties"]["qgep_obj_id"] + try: + geojson_crs_def = labels["crs"] + except: + logger.warning( + f"No labels available - no labels will be exported" + ) + else: + for label in labels["features"]: + layer_name = label["properties"]["Layer"] + obj_id = label["properties"]["qgep_obj_id"] - print(f"label[properties]: {label['properties']}") + print(f"label[properties]: {label['properties']}") - if not label["properties"]["LabelText"]: - logger.warning( - f"Label of object '{obj_id}' from layer '{layer_name}' is empty and will not be exported" - ) - continue - - if layer_name == "vw_qgep_reach": - if obj_id not in tid_for_obj_id["haltung"]: + if not label["properties"]["LabelText"]: logger.warning( - f"Label for haltung `{obj_id}` exists, but that object is not part of the export" + f"Label of object '{obj_id}' from layer '{layer_name}' is empty and will not be exported" ) continue - ili_label = ABWASSER.haltung_text( - **textpos_common(label, "haltung_text", geojson_crs_def), - haltungref=tid_for_obj_id["haltung"][obj_id], - ) - elif layer_name == "vw_qgep_wastewater_structure": - if obj_id not in tid_for_obj_id["abwasserbauwerk"]: - logger.warning( - f"Label for abwasserbauwerk `{obj_id}` exists, but that object is not part of the export" + if layer_name == "vw_qgep_reach": + if obj_id not in tid_for_obj_id["haltung"]: + logger.warning( + f"Label for haltung `{obj_id}` exists, but that object is not part of the export" + ) + continue + ili_label = ABWASSER.haltung_text( + **textpos_common(label, "haltung_text", geojson_crs_def), + haltungref=tid_for_obj_id["haltung"][obj_id], + ) + + elif layer_name == "vw_qgep_wastewater_structure": + if obj_id not in tid_for_obj_id["abwasserbauwerk"]: + logger.warning( + f"Label for abwasserbauwerk `{obj_id}` exists, but that object is not part of the export" + ) + continue + ili_label = ABWASSER.abwasserbauwerk_text( + **textpos_common(label, "abwasserbauwerk_text", geojson_crs_def), + abwasserbauwerkref=tid_for_obj_id["abwasserbauwerk"][obj_id], + ) + + elif layer_name == "catchment_area": + if obj_id not in tid_for_obj_id["einzugsgebiet"]: + logger.warning( + f"Label for einzugsgebiet `{obj_id}` exists, but that object is not part of the export" + ) + continue + ili_label = ABWASSER.einzugsgebiet_text( + **textpos_common(label, "einzugsgebiet_text", geojson_crs_def), + einzugsgebietref=tid_for_obj_id["einzugsgebiet"][obj_id], ) - continue - ili_label = ABWASSER.abwasserbauwerk_text( - **textpos_common(label, "abwasserbauwerk_text", geojson_crs_def), - abwasserbauwerkref=tid_for_obj_id["abwasserbauwerk"][obj_id], - ) - elif layer_name == "catchment_area": - if obj_id not in tid_for_obj_id["einzugsgebiet"]: + else: logger.warning( - f"Label for einzugsgebiet `{obj_id}` exists, but that object is not part of the export" + f"Unknown layer for label `{layer_name}`. Label will be ignored", ) continue - ili_label = ABWASSER.einzugsgebiet_text( - **textpos_common(label, "einzugsgebiet_text", geojson_crs_def), - einzugsgebietref=tid_for_obj_id["einzugsgebiet"][obj_id], - ) - else: - logger.warning( - f"Unknown layer for label `{layer_name}`. Label will be ignored", - ) - continue + abwasser_session.add(ili_label) - abwasser_session.add(ili_label) print(".", end="") logger.info("done") abwasser_session.flush() From e3202e8084d7605adc3681054ade3deff7f37786 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 17 Oct 2024 19:16:30 +0000 Subject: [PATCH 09/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- qgepqwat2ili/qgepdss/export.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/qgepqwat2ili/qgepdss/export.py b/qgepqwat2ili/qgepdss/export.py index f17a8b14..1e9cc6b2 100644 --- a/qgepqwat2ili/qgepdss/export.py +++ b/qgepqwat2ili/qgepdss/export.py @@ -3795,13 +3795,10 @@ def textpos_common(row, t_type, geojson_crs_def): with open(labels_file) as labels_file_handle: labels = json.load(labels_file_handle) - try: geojson_crs_def = labels["crs"] except: - logger.warning( - f"No labels available - no labels will be exported" - ) + logger.warning(f"No labels available - no labels will be exported") else: for label in labels["features"]: layer_name = label["properties"]["Layer"] From 98dca4a39c89ef928324102e415d2a94491f35a1 Mon Sep 17 00:00:00 2001 From: SJiB Date: Thu, 17 Oct 2024 21:18:53 +0200 Subject: [PATCH 10/15] adaot logger.warning - no f string as no variable in text --- qgepqwat2ili/qgepdss/export.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qgepqwat2ili/qgepdss/export.py b/qgepqwat2ili/qgepdss/export.py index 1e9cc6b2..a06bf798 100644 --- a/qgepqwat2ili/qgepdss/export.py +++ b/qgepqwat2ili/qgepdss/export.py @@ -3798,7 +3798,7 @@ def textpos_common(row, t_type, geojson_crs_def): try: geojson_crs_def = labels["crs"] except: - logger.warning(f"No labels available - no labels will be exported") + logger.warning("No labels available - no labels will be exported") else: for label in labels["features"]: layer_name = label["properties"]["Layer"] From f56972bf0dc190508aa5148e6137e15187e49b25 Mon Sep 17 00:00:00 2001 From: SJiB Date: Thu, 17 Oct 2024 21:31:02 +0200 Subject: [PATCH 11/15] add finally: --- qgepqwat2ili/qgepdss/export.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/qgepqwat2ili/qgepdss/export.py b/qgepqwat2ili/qgepdss/export.py index a06bf798..b7b2df31 100644 --- a/qgepqwat2ili/qgepdss/export.py +++ b/qgepqwat2ili/qgepdss/export.py @@ -3797,7 +3797,7 @@ def textpos_common(row, t_type, geojson_crs_def): try: geojson_crs_def = labels["crs"] - except: + except geojson_crs_defError: logger.warning("No labels available - no labels will be exported") else: for label in labels["features"]: @@ -3854,8 +3854,10 @@ def textpos_common(row, t_type, geojson_crs_def): abwasser_session.add(ili_label) print(".", end="") - logger.info("done") - abwasser_session.flush() + + finally: + logger.info("done") + abwasser_session.flush() # -- extra commit abwasser_session.commit() From d2a8ff61a741f7ea5bd95505f7939bb82b43efd7 Mon Sep 17 00:00:00 2001 From: SJiB Date: Thu, 17 Oct 2024 21:39:01 +0200 Subject: [PATCH 12/15] adapt except --- qgepqwat2ili/qgepdss/export.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qgepqwat2ili/qgepdss/export.py b/qgepqwat2ili/qgepdss/export.py index b7b2df31..06ba6cca 100644 --- a/qgepqwat2ili/qgepdss/export.py +++ b/qgepqwat2ili/qgepdss/export.py @@ -3797,7 +3797,7 @@ def textpos_common(row, t_type, geojson_crs_def): try: geojson_crs_def = labels["crs"] - except geojson_crs_defError: + except: logger.warning("No labels available - no labels will be exported") else: for label in labels["features"]: From 972b590484a31060b49ded737826767e1bf7e2c0 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 17 Oct 2024 19:31:16 +0000 Subject: [PATCH 13/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- qgepqwat2ili/qgepdss/export.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qgepqwat2ili/qgepdss/export.py b/qgepqwat2ili/qgepdss/export.py index 06ba6cca..07f5e4d0 100644 --- a/qgepqwat2ili/qgepdss/export.py +++ b/qgepqwat2ili/qgepdss/export.py @@ -3854,7 +3854,7 @@ def textpos_common(row, t_type, geojson_crs_def): abwasser_session.add(ili_label) print(".", end="") - + finally: logger.info("done") abwasser_session.flush() From ede6f098d3f98c2161ab69e342431557e459f4c0 Mon Sep 17 00:00:00 2001 From: SJiB Date: Fri, 18 Oct 2024 13:55:31 +0200 Subject: [PATCH 14/15] logger.warning add english classnames in messages --- qgepqwat2ili/qgepdss/export.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/qgepqwat2ili/qgepdss/export.py b/qgepqwat2ili/qgepdss/export.py index 07f5e4d0..e5d8eb00 100644 --- a/qgepqwat2ili/qgepdss/export.py +++ b/qgepqwat2ili/qgepdss/export.py @@ -3815,18 +3815,18 @@ def textpos_common(row, t_type, geojson_crs_def): if layer_name == "vw_qgep_reach": if obj_id not in tid_for_obj_id["haltung"]: logger.warning( - f"Label for haltung `{obj_id}` exists, but that object is not part of the export" + f"Label for haltung (reach) `{obj_id}` exists, but that object is not part of the export" ) continue ili_label = ABWASSER.haltung_text( - **textpos_common(label, "haltung_text", geojson_crs_def), + **textpos_common(label, "haltung_text (reach_text)", geojson_crs_def), haltungref=tid_for_obj_id["haltung"][obj_id], ) elif layer_name == "vw_qgep_wastewater_structure": if obj_id not in tid_for_obj_id["abwasserbauwerk"]: logger.warning( - f"Label for abwasserbauwerk `{obj_id}` exists, but that object is not part of the export" + f"Label for abwasserbauwerk (wastewater_structure) `{obj_id}` exists, but that object is not part of the export" ) continue ili_label = ABWASSER.abwasserbauwerk_text( @@ -3837,11 +3837,11 @@ def textpos_common(row, t_type, geojson_crs_def): elif layer_name == "catchment_area": if obj_id not in tid_for_obj_id["einzugsgebiet"]: logger.warning( - f"Label for einzugsgebiet `{obj_id}` exists, but that object is not part of the export" + f"Label for einzugsgebiet (catchment_area) `{obj_id}` exists, but that object is not part of the export" ) continue ili_label = ABWASSER.einzugsgebiet_text( - **textpos_common(label, "einzugsgebiet_text", geojson_crs_def), + **textpos_common(label, "einzugsgebiet_text (catchment_area_text)", geojson_crs_def), einzugsgebietref=tid_for_obj_id["einzugsgebiet"][obj_id], ) From 8a57ad37b6c538799523cc178f96342f9fed7fe7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 18 Oct 2024 12:00:54 +0000 Subject: [PATCH 15/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- qgepqwat2ili/qgepdss/export.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/qgepqwat2ili/qgepdss/export.py b/qgepqwat2ili/qgepdss/export.py index f28d9e0d..0accffd2 100644 --- a/qgepqwat2ili/qgepdss/export.py +++ b/qgepqwat2ili/qgepdss/export.py @@ -3820,7 +3820,6 @@ def textpos_common(row, t_type, geojson_crs_def): continue ili_label = ABWASSER.haltung_text( **textpos_common(label, "haltung_text (reach_text)", geojson_crs_def), - haltungref=tid_for_obj_id["haltung"][obj_id], ) @@ -3842,7 +3841,9 @@ def textpos_common(row, t_type, geojson_crs_def): ) continue ili_label = ABWASSER.einzugsgebiet_text( - **textpos_common(label, "einzugsgebiet_text (catchment_area_text)", geojson_crs_def), + **textpos_common( + label, "einzugsgebiet_text (catchment_area_text)", geojson_crs_def + ), einzugsgebietref=tid_for_obj_id["einzugsgebiet"][obj_id], )