Skip to content

Commit

Permalink
refacto(deadcode): remove check_gdal since environment does the job (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Guts authored Jun 6, 2024
2 parents 4bb0049 + d03c0f2 commit 52c9313
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 62 deletions.
5 changes: 1 addition & 4 deletions dicogis/ui/main_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,7 @@ def __init__(self, theme: str = "radiance"):
self.resizable(width=False, height=False)
self.focus_force()

# GDAL settings
checker.check_gdal()

# # Variables
# -- Variables --
# settings
self.num_folders = 0
self.def_rep = "" # default folder to search for
Expand Down
64 changes: 6 additions & 58 deletions dicogis/utils/checknorris.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import logging
import socket
from os import environ as env
from os import path
from urllib.request import (
ProxyHandler,
build_opener,
Expand All @@ -39,59 +38,16 @@
class CheckNorris:
"""Check Norris never fails, always tests."""

def __init__(self):
"""Check Norris welcomes you."""
super().__init__()
def check_internet_connection(self, remote_server: str = "www.google.com") -> bool:
"""Check if an internet connection is operational.
# -- 1 method, 1 check ----------------------------------------------------
Source: http://stackoverflow.com/a/20913928/2556577
def check_gdal(self):
"""Check if OSGeo libs work and if GDAL_DATA is well refrenced.
Args:
remote_server: internet address to try. Defaults to "www.google.com".
Returns:
-- 1: GDAL_DATA already exists as environment variable
-- 2: GDAL_DATA didn't exist as env variable then has been added
-- 3: GDAL_DATA didn't exist as env variable and could'nt be added
"""
# GDAL install
try:
try:
from osgeo import gdal
except ImportError:
import gdal
logger.info(f"GDAL version: {gdal.__version__}")
except Exception as err:
logger.error(
"GDAL is not installed or not reachable."
" DicoGIS is going to close. Trace: {}".format(err)
)
return 1

# GDAL_DATA variable
if "GDAL_DATA" not in env.keys():
try:
gdal.SetConfigOption("GDAL_DATA", str(path.abspath(r"data/gdal")))
logger.info(
"GDAL_DATA path not found in environment variable."
" DicoGIS'll use its own: " + path.abspath(r"data/gdal")
)
return 2
except Exception as err:
logger.error(f"Oups! Something's wrong with GDAL_DATA path: {err}")
return 3
else:
logger.info(
"GDAL_DATA path found in environment variable: {}."
" DicoGIS'll use it.".format(env.get("GDAL_DATA"))
)
return 4
# end of method
return

def check_internet_connection(self, remote_server: str = "www.google.com"):
"""Check if an internet connection is operational.
source: http://stackoverflow.com/a/20913928/2556577
True if connection works
"""
try:
# see if we can resolve the host name -- tells us if there is
Expand Down Expand Up @@ -136,11 +92,3 @@ def check_proxy(self, specific: dict = {}):
install_opener(opener)
urlopen("http://www.google.com")
return 3, os_proxies


# ##############################################################################
# ##### Stand alone program ########
# ##################################
if __name__ == "__main__":
"""Standalone execution."""
pass

0 comments on commit 52c9313

Please sign in to comment.