Skip to content

Commit

Permalink
refacto(deadcode): remove legacy utils became unused recently (#301)
Browse files Browse the repository at this point in the history
  • Loading branch information
Guts authored Jun 6, 2024
2 parents 1a5aaf8 + 00c4164 commit 9191965
Showing 1 changed file with 0 additions and 112 deletions.
112 changes: 0 additions & 112 deletions dicogis/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,19 @@

# Standard library
import logging
import subprocess
import sys
from importlib import resources
from pathlib import Path
from sys import platform as opersys
from tkinter import ACTIVE, DISABLED
from tkinter.filedialog import asksaveasfilename # dialogs
from tkinter.messagebox import showerror as avert

# Imports depending on operating system
if opersys == "win32":
"""windows"""
from os import startfile # to open a folder/file


# package
from dicogis.__about__ import __package_name__
from dicogis.utils.check_path import check_path

# ##############################################################################
# ############ Globals ############
Expand Down Expand Up @@ -69,113 +64,6 @@ def resolve_internal_path(cls, internal_path: Path) -> Path:

return internal_path

@classmethod
def open_dir_file(cls, target: str | Path) -> subprocess.Popen | None:
"""Open a file or directory in the explorer of the operating system.
Args:
target (str | Path): file or folder path to open
Returns:
subprocess.Popen: subprocess instance
"""

check_path(
input_path=target,
must_be_a_file=False,
must_be_a_folder=False,
must_be_readable=True,
must_exists=True,
)

if isinstance(target, Path):
target = str(target.resolve())

# Windows
if opersys == "win32":
proc = startfile(target)
# Linux
elif opersys.startswith("linux"):
proc = subprocess.Popen(
["xdg-open", target], stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
# Mac
elif opersys == "darwin":
proc = subprocess.Popen(
["open", "--", target], stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
else:
logger.error(
NotImplementedError(
"Your `%s` isn't a supported operating system`." % opersys
)
)
proc = None

return proc

@classmethod
def safe_save(
cls,
output_object,
dest_dir: str = r".",
dest_filename: str = "DicoGIS.xlsx",
ftype: str = "Excel Workbook",
dlg_title: str | None = "DicoGIS - Save output Excel Workbook",
gui: bool = True,
):
"""Safe save output file."""
# Prompt of folder where save the file
if gui:
out_name = asksaveasfilename(
initialdir=dest_dir,
initialfile=dest_filename,
defaultextension=".xlsx",
filetypes=[(ftype, "*.xlsx")],
title=dlg_title,
)
else:
out_name = dest_filename

if not isinstance(out_name, (str, Path)) and len(str(out_name)):
logger.warning(f"No output file selected: {out_name}")
return None

# convert into Path object
out_path = Path(dest_dir).joinpath(out_name)

# check if the extension is correctly indicated
if out_path.suffix != ".xlsx":
out_path = out_path.with_suffix(".xlsx")

# save
if out_path.name != ".xlsx":
try:
output_object.workbook.save(filename=out_path)
except OSError:
if gui:
avert(
title="Concurrent access",
message="Please close Microsoft Excel before saving.",
)
logger.error(
"Unable to save the file. Is the file already opened in a software?"
)
return out_name
except Exception as err:
logger.critical(
"Something happened during workbook saving operations. Trace: {}".format(
err
)
)
else:
if gui:
avert(title="Not saved", message="You cancelled saving operation")
sys.exit()

# End of function
return out_name, out_path

@classmethod
def ui_switch(cls, cb_value, parent):
"""Change state of all children widgets within a parent class.
Expand Down

0 comments on commit 9191965

Please sign in to comment.