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,6 +7,7 @@ from pilgrim.utils import ConfigManager | |||
| class Application: | ||||
|     def __init__(self): | ||||
|         self.config_manager = ConfigManager() | ||||
|         self.config_manager.read_config()  # Chamar antes de criar o Database | ||||
|         self.database = Database(self.config_manager) | ||||
|         session = self.database.session() | ||||
|         session_manager = ServiceManager() | ||||
|  | @ -14,7 +15,7 @@ class Application: | |||
|         self.ui = UIApp(session_manager, self.config_manager) | ||||
| 
 | ||||
|     def run(self): | ||||
|         self.config_manager.read_config() | ||||
|         print(f"URL do banco: {self.config_manager.database_url}") | ||||
|         self.database.create() | ||||
|         self.ui.run() | ||||
| 
 | ||||
|  |  | |||
|  | @ -12,10 +12,17 @@ Base = declarative_base() | |||
| 
 | ||||
| 
 | ||||
| class Database: | ||||
| 
 | ||||
|     def __init__(self, config_manager: ConfigManager): | ||||
|         db_path = config_manager.database_url | ||||
|         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( | ||||
|             f"sqlite:///{config_manager.database_url}", | ||||
|             f"sqlite:///{self.db_path}", | ||||
|             echo=False, | ||||
|             connect_args={"check_same_thread": False}, | ||||
|         ) | ||||
|  |  | |||
|  | @ -12,7 +12,7 @@ class NewDiaryModal(ModalScreen[str]): | |||
|         Binding("escape", "cancel", "Cancel"), | ||||
|         Binding("enter", "create_diary", "Create",priority=True), | ||||
|     ] | ||||
|     def __init__(self,autoopen=True): | ||||
|     def __init__(self,autoopen:bool = True): | ||||
|         super().__init__() | ||||
|         self.auto_open = autoopen | ||||
|         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() | ||||
| 
 | ||||
|     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 = { | ||||
|             "database": { | ||||
|                 "url": f"{DirectoryManager.get_config_directory()}/database.db", | ||||
|                 "url": f"{config_dir}/database.db", | ||||
|                 "type": "sqlite" | ||||
|             }, | ||||
|             "settings": { | ||||
|  | @ -67,11 +72,12 @@ class ConfigManager(metaclass=SingletonMeta): | |||
|         } | ||||
|         if config is None: | ||||
|             config = default | ||||
| 
 | ||||
|         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) | ||||
|         except FileNotFoundError: | ||||
|             print("Error: config.toml not found.") | ||||
|         except Exception as e: | ||||
|             print(f"Erro ao criar config: {e}") | ||||
| 
 | ||||
|     def save_config(self): | ||||
|         if self.__data is None: | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue