fix: improve path handling for PyInstaller compatibility
This commit is contained in:
@@ -1,7 +1,15 @@
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
CONFIG_FILE = "config.json"
|
def get_app_dir():
|
||||||
|
if getattr(sys, 'frozen', False):
|
||||||
|
return os.path.dirname(sys.executable)
|
||||||
|
else:
|
||||||
|
# If in git_monitor package, go up to the project root
|
||||||
|
return os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
|
||||||
|
CONFIG_FILE = os.path.join(get_app_dir(), "config.json")
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|||||||
@@ -3,9 +3,14 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
def setup_logger():
|
def setup_logger():
|
||||||
log_file = "git_monitor.log"
|
# Find application directory
|
||||||
# Ensure log is in the application directory
|
if getattr(sys, 'frozen', False):
|
||||||
log_path = os.path.abspath(log_file)
|
app_dir = os.path.dirname(sys.executable)
|
||||||
|
else:
|
||||||
|
# If in a package, go up one level to the root
|
||||||
|
app_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
|
||||||
|
log_file = os.path.join(app_dir, "git_monitor.log")
|
||||||
|
|
||||||
logger = logging.getLogger("GitMonitor")
|
logger = logging.getLogger("GitMonitor")
|
||||||
logger.setLevel(logging.INFO)
|
logger.setLevel(logging.INFO)
|
||||||
@@ -13,7 +18,7 @@ def setup_logger():
|
|||||||
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
|
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
|
||||||
|
|
||||||
# File handler
|
# File handler
|
||||||
file_handler = logging.FileHandler(log_path)
|
file_handler = logging.FileHandler(log_file)
|
||||||
file_handler.setFormatter(formatter)
|
file_handler.setFormatter(formatter)
|
||||||
logger.addHandler(file_handler)
|
logger.addHandler(file_handler)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user