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

feature(processing): add option to quick fail (without try/except) #280

Merged
merged 1 commit into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 11 additions & 1 deletion dicogis/cli/cmd_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,19 @@ def inventory(
"Example: 1 ko instead of 1024.",
),
] = False,
opt_quick_fail: Annotated[
bool,
typer.Option(
envvar="DICOGIS_QUICK_FAIL",
is_flag=True,
help="Enable quick fail instead of passing errors. Useful for debug.",
),
] = False,
opt_raw_path: Annotated[
bool,
typer.Option(
envvar="DICOGIS_EXPORT_RAW_PATH",
is_flag=False,
is_flag=True,
help="Enable raw path instead of hyperlink in formats which support it.",
),
] = False,
Expand Down Expand Up @@ -296,6 +304,8 @@ def inventory(
),
opt_analyze_shapefiles="esri_shapefile" in formats,
opt_analyze_spatialite="file_geodatabase_spatialite" in formats,
# misc
opt_quick_fail=opt_quick_fail,
)

# sheets and progress bar
Expand Down
43 changes: 42 additions & 1 deletion dicogis/georeaders/process_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ def __init__(
progress_message_displayer: Optional[StringVar] = None,
progress_counter: Optional[IntVar] = None,
progress_callback_cmd: Optional[Callable] = None,
# misc
opt_quick_fail: bool = False,
) -> None:
# -- STORE PARAMETERS AS ATTRIBUTES --
self.serializer = self.serializer_from_output_format(format_or_serializer)
Expand Down Expand Up @@ -159,6 +161,7 @@ def __init__(
self.opt_analyze_geopackage = opt_analyze_geopackage

# others
self.opt_quick_fail = opt_quick_fail
self.total_files: Optional[int] = None
self.li_files_to_process: list[Optional[DatasetToProcess]] = []
self.localized_strings = localized_strings
Expand Down Expand Up @@ -210,8 +213,31 @@ def process_datasets_in_queue(self):
def read_dataset(
self, dataset_to_process: DatasetToProcess
) -> tuple[DatasetToProcess, MetaDataset | None]:
"""Read dataset and store into metadataset.

Args:
dataset_to_process: dataset path or URI to read

Returns:
dataset and metadataset, None if an error occurs
"""
metadataset = None

if self.opt_quick_fail:
self.update_progress(
message_to_display=f"Reading {dataset_to_process.file_path}..."
)
metadataset = dataset_to_process.georeader().infos_dataset(
source_path=path.abspath(dataset_to_process.file_path),
)
logger.debug(f"Reading {dataset_to_process} succeeded.")
self.update_progress(
message_to_display=f"Reading {dataset_to_process.file_path}: OK",
increment_counter=True,
)
dataset_to_process.processed = True
return dataset_to_process, metadataset

try:
self.update_progress(
message_to_display=f"Reading {dataset_to_process.file_path}..."
Expand Down Expand Up @@ -243,13 +269,28 @@ def export_metadataset(
dataset_to_process: DatasetToProcess,
metadataset_to_serialize: MetaDataset,
) -> tuple[DatasetToProcess, MetaDataset | None]:
self.serializer.serialize_metadaset(metadataset=metadataset_to_serialize)
if self.opt_quick_fail:
self.update_progress(
message_to_display="Exporting metadata of "
f"{dataset_to_process.file_path}..."
)
# writing to the Excel file
self.update_progress(
message_to_display="Exporting metadata of "
f"{dataset_to_process.file_path}: OK",
increment_counter=True,
)
logger.debug(f"Exporting metadata of {dataset_to_process.file_path}: OK")
dataset_to_process.exported = True
return dataset_to_process, metadataset_to_serialize

try:
self.update_progress(
message_to_display="Exporting metadata of "
f"{dataset_to_process.file_path}..."
)
# writing to the Excel file
self.serializer.serialize_metadaset(metadataset=metadataset_to_serialize)
self.update_progress(
message_to_display="Exporting metadata of "
f"{dataset_to_process.file_path}: OK",
Expand Down
2 changes: 2 additions & 0 deletions dicogis/ui/main_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,8 @@ def process_files(self):
progress_counter=self.progress,
progress_message_displayer=self.status,
progress_callback_cmd=self.update,
# misc
opt_quick_fail=self.tab_options.opt_quick_fail.get(),
)

# sheets and progress bar
Expand Down
12 changes: 11 additions & 1 deletion dicogis/ui/tab_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def __init__(self, parent, txt: dict, switcher: Callable = None):
)

self.opt_export_raw_path = BooleanVar(
master=self, value=getenv("DICOGIS_EXPORT_RAW_PATH", True)
master=self, value=getenv("DICOGIS_EXPORT_RAW_PATH", False)
)
caz_opt_export_raw_path = Checkbutton(
self.FrOptExport,
Expand All @@ -138,6 +138,16 @@ def __init__(self, parent, txt: dict, switcher: Callable = None):
)
caz_opt_export_raw_path.grid(row=3, column=0, sticky="NSWE", padx=2, pady=2)

self.opt_quick_fail = BooleanVar(
master=self, value=getenv("DICOGIS_QUICK_FAIL", False)
)
caz_opt_quick_fail = Checkbutton(
self.FrOptExport,
text="Quick fail",
variable=self.opt_quick_fail,
)
caz_opt_quick_fail.grid(row=3, column=0, sticky="NSWE", padx=2, pady=2)

self.opt_end_process_notification_sound = BooleanVar(
master=self, value=getenv("DICOGIS_ENABLE_NOTIFICATION_SOUND", True)
)
Expand Down