Skip to content

Commit

Permalink
System versus platform naming, config_dir -> gistim_dir
Browse files Browse the repository at this point in the history
  • Loading branch information
Huite committed Dec 19, 2023
1 parent 1ba60d1 commit 755a390
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 28 deletions.
38 changes: 18 additions & 20 deletions plugin/qgistim/core/install_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,16 @@
import os


GITHUB_URL = "https://api.github.com/repos/deltares/qgis-tim/releases"
PLATFORMS = {
"Windows": "Windows",
"Darwin": "macOS",
"Linux": "Linux",
}


def get_configdir() -> Path:
def get_gistim_dir() -> Path:
if platform.system() == "Windows":
configdir = Path(os.environ["APPDATA"]) / "qgis-tim"
gistim_dir = Path(os.environ["APPDATA"]) / "qgis-tim"
else:
configdir = Path(os.environ["HOME"]) / ".qgis-tim"
return configdir
gistim_dir = Path(os.environ["HOME"]) / ".qgis-tim"
return gistim_dir


def get_release_assets() -> Dict[str, str]:
GITHUB_URL = "https://api.github.com/repos/deltares/qgis-tim/releases"
response = requests.get(GITHUB_URL)
json_content = json.loads(response.content)
last_release = json_content[0]
Expand All @@ -37,18 +30,23 @@ def get_release_assets() -> Dict[str, str]:


def download_assets(assets: Dict[str, str]) -> ZipFile:
platform = platform.system()
github_platform = PLATFORMS.get(platform)
if github_platform is None:
SYSTEMS = {
"Windows": "Windows",
"Darwin": "macOS",
"Linux": "Linux",
}
user_system = platform.system()
github_system = SYSTEMS.get(user_system)
if github_system is None:
raise ValueError(
f"Unsupported platform: {platform}. "
f"Only {', '.join(PLATFORMS.keys())} are supported."
f"Unsupported OS: {user_system}. "
f"Only {', '.join(SYSTEMS.keys())} are supported."
)
# Get checksum
checksum_url = assets[f"sha256-checksum-{github_platform}.txt"]
checksum_url = assets[f"sha256-checksum-{github_system}.txt"]
checksum_github = requests.get(checksum_url).content.decode("utf-8")
# Get zipfile content
zip_url = assets[f"gistim-{github_platform}.zip"]
zip_url = assets[f"gistim-{github_system}.zip"]
zipfile_content = requests.get(zip_url).content
# Compare checksums
sha = hashlib.sha256()
Expand All @@ -60,7 +58,7 @@ def download_assets(assets: Dict[str, str]) -> ZipFile:


def create_destination() -> Path:
gistim_dir = get_configdir()
gistim_dir = get_gistim_dir()
if gistim_dir.exists():
shutil.rmtree(gistim_dir)
gistim_dir.mkdir()
Expand Down
16 changes: 8 additions & 8 deletions plugin/qgistim/core/server_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,32 @@ def alive(self):
return self.process is not None and self.process.poll() is None

@staticmethod
def get_configdir() -> Path:
def get_gistim_dir() -> Path:
"""
Get the location of the qgis-tim PyInstaller executable.
The location differs per OS.
Returns
-------
configdir: pathlib.Path
gistim_dir: pathlib.Path
"""
if platform.system() == "Windows":
configdir = Path(os.environ["APPDATA"]) / "qgis-tim"
gistim_dir = Path(os.environ["APPDATA"]) / "qgis-tim"
else:
configdir = Path(os.environ["HOME"]) / ".qgis-tim"
return configdir
gistim_dir = Path(os.environ["HOME"]) / ".qgis-tim"
return gistim_dir

@staticmethod
def get_interpreter() -> Path:
if platform.system() == "Windows":
return ServerHandler.get_configdir() / "gistim.exe"
return ServerHandler.get_gistim_dir() / "gistim.exe"
else:
return ServerHandler.get_configdir() / "gistim"
return ServerHandler.get_gistim_dir() / "gistim"

@staticmethod
def versions():
path = ServerHandler.get_configdir() / "versions.json"
path = ServerHandler.get_gistim_dir() / "versions.json"
if path.exists():
with open(path, "r") as f:
versions = json.loads(f.read())
Expand Down

0 comments on commit 755a390

Please sign in to comment.