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:
2023-12-16 22:20:24 -06:00
committed by GitHub
parent 525fd99a58
commit f663430984
28 changed files with 93 additions and 25 deletions

View File

@@ -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