mekasu0124

Untitled

May 5th, 2024
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.77 KB | None | 0 0
  1. import os
  2. import json
  3.  
  4. from DreamersDiscoveries.infrastructure.services.result import Result
  5.  
  6. class Helpers:
  7.     def __init__(self):
  8.         self.file_path = ""
  9.  
  10.     async def check_infrastructure_setup(self, progress):
  11.         task = progress.add_task("Checking for settings.json file", total=100)
  12.         task2 = progress.add_task("Building path to settings.json", total=100)
  13.  
  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.        
  21.         task3 = progress.add_task("Checking if the setup folder exists", total=100)
  22.        
  23.  
  24.         if not os.path.exists(setup_path):
  25.             task4 = progress.add_task("Setup Folder Not Found. Creating Setup Folder", total=100)
  26.             progress.write("some text")
  27.             os.makedirs(setup_path)
  28.  
  29.             setup_file_check = self.create_setup_file()
  30.  
  31.             if not setup_file_check.is_success:
  32.                 return Result.fail(setup_file_check.message)
  33.            
  34.             return Result.ok("Setup File Create Successfully")
  35.        
  36.         return Result.ok("Setup File Already Exists")
  37.    
  38.     async def create_setup_file(self):
  39.         if not os.path.exists(self.file_path):
  40.             try:
  41.                 with open(self.file_path, 'w') as file:
  42.                     data = {"setup": False}
  43.                     json.dump(data, file, indent=4)
  44.  
  45.                 return Result.ok("Setup File Created Successfully")
  46.             except Exception as e:
  47.                 return Result.fail(e)
  48.  
  49.         return Result.ok("Setup File Created Successfully")
  50.  
Advertisement
Add Comment
Please, Sign In to add comment