mekasu0124

Untitled

May 5th, 2024
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.75 KB | None | 0 0
  1. import os
  2. import json
  3.  
  4. from rich.status import Console
  5.  
  6. from DreamersDiscoveries.infrastructure.services.result import Result
  7.  
  8. class Helpers:
  9.     def __init__(self):
  10.         self.file_path = ""
  11.         self.console = Console()
  12.  
  13.     def check_infrastructure_setup(self):
  14.         src_path = 'src'
  15.         sub_path = os.path.join(src_path, 'DreamersDiscoveries')
  16.         infrastructure_path = os.path.join(sub_path, 'infrastructure')
  17.         setup_path = os.path.join(infrastructure_path, 'setup')
  18.         self.file_path = os.path.join(setup_path, 'settings.json')
  19.  
  20.         if not os.path.exists(setup_path):
  21.             os.makedirs(setup_path)
  22.  
  23.             setup_file_check = self.create_setup_file()
  24.  
  25.             if not setup_file_check.is_success:
  26.                 return Result.fail(setup_file_check.message)
  27.            
  28.             return Result.ok("Setup File Create Successfully")
  29.        
  30.         return Result.ok("Setup File Already Exists")
  31.    
  32.     def create_setup_file(self):
  33.         if not os.path.exists(self.file_path):
  34.             try:
  35.                 with open(self.file_path, 'w') as file:
  36.                     data = {"setup": False}
  37.                     json.dump(data, file, indent=4)
  38.  
  39.                 return Result.ok("Setup File Created Successfully")
  40.             except Exception as e:
  41.                 return Result.fail(e)
  42.  
  43.         return Result.ok("Setup File Created Successfully")
  44.  
  45.     def build_database_path(self):
  46.         src_path = 'src'
  47.         sub_path = os.path.join(src_path, 'DreamersDiscoveries')
  48.         infrastructure_path = os.path.join(sub_path, 'infrastructure')
  49.         db_path = os.path.join(infrastructure_path, "database")
  50.         file_path = os.path.join(db_path, 'main.db')
  51.  
  52.         return file_path
Advertisement
Add Comment
Please, Sign In to add comment