mirror of
https://github.com/blw1138/Zordon.git
synced 2025-12-17 16:58:12 +00:00
Fix py2app (#69)
* Initial commit of py2app code * Use environment variable RESOURCE_PATH when running as a bundle * Move config files to system config location
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import os
|
||||
import yaml
|
||||
from src.utilities.misc_helper import current_system_os, copy_directory_contents
|
||||
|
||||
|
||||
class Config:
|
||||
@@ -34,3 +35,40 @@ class Config:
|
||||
cls.port_number = cfg.get('port_number', cls.port_number)
|
||||
cls.enable_split_jobs = cfg.get('enable_split_jobs', cls.enable_split_jobs)
|
||||
cls.download_timeout_seconds = cfg.get('download_timeout_seconds', cls.download_timeout_seconds)
|
||||
|
||||
@classmethod
|
||||
def config_dir(cls):
|
||||
# Setup the config path
|
||||
if current_system_os() == 'macos':
|
||||
local_config_path = os.path.expanduser('~/Library/Application Support/Zordon')
|
||||
elif current_system_os() == 'windows':
|
||||
local_config_path = os.path.join(os.environ['APPDATA'], 'Zordon')
|
||||
else:
|
||||
local_config_path = os.path.expanduser('~/.config/Zordon')
|
||||
return local_config_path
|
||||
|
||||
@classmethod
|
||||
def setup_config_dir(cls):
|
||||
# Setup the config path
|
||||
local_config_dir = cls.config_dir()
|
||||
if os.path.exists(local_config_dir):
|
||||
return
|
||||
|
||||
try:
|
||||
# Create the local configuration directory
|
||||
os.makedirs(local_config_dir)
|
||||
|
||||
# Determine the template path
|
||||
resource_environment_path = os.environ.get('RESOURCEPATH')
|
||||
if resource_environment_path:
|
||||
template_path = os.path.join(resource_environment_path, 'config')
|
||||
else:
|
||||
template_path = os.path.join(
|
||||
os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))), 'config')
|
||||
|
||||
# Copy contents from the template to the local configuration directory
|
||||
copy_directory_contents(template_path, local_config_dir)
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred while setting up the config directory: {e}")
|
||||
raise
|
||||
@@ -1,6 +1,7 @@
|
||||
import logging
|
||||
import os
|
||||
import platform
|
||||
import shutil
|
||||
import socket
|
||||
import subprocess
|
||||
from datetime import datetime
|
||||
@@ -127,15 +128,24 @@ def current_system_cpu():
|
||||
|
||||
|
||||
def resources_dir():
|
||||
resources_directory = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))),
|
||||
'resources')
|
||||
return resources_directory
|
||||
resource_environment_path = os.environ.get('RESOURCEPATH', None)
|
||||
if resource_environment_path: # running inside resource bundle
|
||||
return os.path.join(resource_environment_path, 'resources')
|
||||
else:
|
||||
return os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))), 'resources')
|
||||
|
||||
|
||||
def config_dir():
|
||||
config_directory = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))),
|
||||
'config')
|
||||
return config_directory
|
||||
def copy_directory_contents(src_dir, dst_dir):
|
||||
"""
|
||||
Copy the contents of the source directory (src_dir) to the destination directory (dst_dir).
|
||||
"""
|
||||
for item in os.listdir(src_dir):
|
||||
src_path = os.path.join(src_dir, item)
|
||||
dst_path = os.path.join(dst_dir, item)
|
||||
if os.path.isdir(src_path):
|
||||
shutil.copytree(src_path, dst_path, dirs_exist_ok=True)
|
||||
else:
|
||||
shutil.copy2(src_path, dst_path)
|
||||
|
||||
|
||||
def is_localhost(comparison_hostname):
|
||||
|
||||
Reference in New Issue
Block a user