Files
auto-git/git_monitor/config.py

46 lines
1.2 KiB
Python

import json
import os
import sys
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:
def __init__(self):
self.data = {
"repository_path": ""
}
self.load()
def load(self):
if os.path.exists(CONFIG_FILE):
try:
with open(CONFIG_FILE, "r") as f:
self.data = json.load(f)
except Exception as e:
print(f"Error loading config: {e}")
def save(self):
try:
with open(CONFIG_FILE, "w") as f:
json.dump(self.data, f, indent=4)
except Exception as e:
print(f"Error saving config: {e}")
@property
def repository_path(self):
return self.data.get("repository_path", "")
@repository_path.setter
def repository_path(self, value):
self.data["repository_path"] = value
self.save()
config = Config()