mirror of https://github.com/gmbrax/Pilgrim.git
Fix the Database no being put on the right path according with the config.toml
This commit is contained in:
parent
bdaa37e355
commit
967c7e4ce6
|
|
@ -7,14 +7,15 @@ from pilgrim.utils import ConfigManager
|
||||||
class Application:
|
class Application:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.config_manager = ConfigManager()
|
self.config_manager = ConfigManager()
|
||||||
|
self.config_manager.read_config() # Chamar antes de criar o Database
|
||||||
self.database = Database(self.config_manager)
|
self.database = Database(self.config_manager)
|
||||||
session = self.database.session()
|
session = self.database.session()
|
||||||
session_manager = ServiceManager()
|
session_manager = ServiceManager()
|
||||||
session_manager.set_session(session)
|
session_manager.set_session(session)
|
||||||
self.ui = UIApp(session_manager,self.config_manager)
|
self.ui = UIApp(session_manager, self.config_manager)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self.config_manager.read_config()
|
print(f"URL do banco: {self.config_manager.database_url}")
|
||||||
self.database.create()
|
self.database.create()
|
||||||
self.ui.run()
|
self.ui.run()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,10 +12,17 @@ Base = declarative_base()
|
||||||
|
|
||||||
|
|
||||||
class Database:
|
class Database:
|
||||||
def __init__(self,config_manager:ConfigManager):
|
|
||||||
db_path = config_manager.database_url
|
def __init__(self, config_manager: ConfigManager):
|
||||||
|
self.db_path = config_manager.database_url
|
||||||
|
|
||||||
|
# Garantir que o diretório existe
|
||||||
|
db_dir = os.path.dirname(self.db_path)
|
||||||
|
if not os.path.exists(db_dir):
|
||||||
|
os.makedirs(db_dir, exist_ok=True)
|
||||||
|
|
||||||
self.engine = create_engine(
|
self.engine = create_engine(
|
||||||
f"sqlite:///{config_manager.database_url}",
|
f"sqlite:///{self.db_path}",
|
||||||
echo=False,
|
echo=False,
|
||||||
connect_args={"check_same_thread": False},
|
connect_args={"check_same_thread": False},
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ class NewDiaryModal(ModalScreen[str]):
|
||||||
Binding("escape", "cancel", "Cancel"),
|
Binding("escape", "cancel", "Cancel"),
|
||||||
Binding("enter", "create_diary", "Create",priority=True),
|
Binding("enter", "create_diary", "Create",priority=True),
|
||||||
]
|
]
|
||||||
def __init__(self,autoopen=True):
|
def __init__(self,autoopen:bool = True):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.auto_open = autoopen
|
self.auto_open = autoopen
|
||||||
self.name_input = Input(id="NewDiaryModal-NameInput",classes="NewDiaryModal-NameInput") # This ID is fine, it's specific to the input
|
self.name_input = Input(id="NewDiaryModal-NameInput",classes="NewDiaryModal-NameInput") # This ID is fine, it's specific to the input
|
||||||
|
|
|
||||||
|
|
@ -53,9 +53,14 @@ class ConfigManager(metaclass=SingletonMeta):
|
||||||
self.read_config()
|
self.read_config()
|
||||||
|
|
||||||
def create_config(self, config: dict = None):
|
def create_config(self, config: dict = None):
|
||||||
|
# Garantir que o diretório de configuração existe
|
||||||
|
config_dir = DirectoryManager.get_config_directory()
|
||||||
|
if not os.path.exists(config_dir):
|
||||||
|
os.makedirs(config_dir, exist_ok=True)
|
||||||
|
|
||||||
default = {
|
default = {
|
||||||
"database": {
|
"database": {
|
||||||
"url": f"{DirectoryManager.get_config_directory()}/database.db",
|
"url": f"{config_dir}/database.db",
|
||||||
"type": "sqlite"
|
"type": "sqlite"
|
||||||
},
|
},
|
||||||
"settings": {
|
"settings": {
|
||||||
|
|
@ -67,11 +72,12 @@ class ConfigManager(metaclass=SingletonMeta):
|
||||||
}
|
}
|
||||||
if config is None:
|
if config is None:
|
||||||
config = default
|
config = default
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(f"{DirectoryManager.get_config_directory()}/config.toml", "wb") as f:
|
with open(f"{config_dir}/config.toml", "wb") as f:
|
||||||
tomli_w.dump(config, f)
|
tomli_w.dump(config, f)
|
||||||
except FileNotFoundError:
|
except Exception as e:
|
||||||
print("Error: config.toml not found.")
|
print(f"Erro ao criar config: {e}")
|
||||||
|
|
||||||
def save_config(self):
|
def save_config(self):
|
||||||
if self.__data is None:
|
if self.__data is None:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue