Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import json
- from DreamersDiscoveries.infrastructure.services.result import Result
- class Helpers:
- def __init__(self):
- self.file_path = ""
- async def check_infrastructure_setup(self, progress):
- task = progress.add_task("Checking for settings.json file", total=100)
- task2 = progress.add_task("Building path to settings.json", total=100)
- src_path = 'src'
- sub_path = os.path.join(src_path, 'DreamersDiscoveries')
- infrastructure_path = os.path.join(sub_path, 'infrastructure')
- setup_path = os.path.join(infrastructure_path, 'setup')
- self.file_path = os.path.join(setup_path, 'settings.json')
- task3 = progress.add_task("Checking if the setup folder exists", total=100)
- if not os.path.exists(setup_path):
- task4 = progress.add_task("Setup Folder Not Found. Creating Setup Folder", total=100)
- progress.write("some text")
- os.makedirs(setup_path)
- setup_file_check = self.create_setup_file()
- if not setup_file_check.is_success:
- return Result.fail(setup_file_check.message)
- return Result.ok("Setup File Create Successfully")
- return Result.ok("Setup File Already Exists")
- async def create_setup_file(self):
- if not os.path.exists(self.file_path):
- try:
- with open(self.file_path, 'w') as file:
- data = {"setup": False}
- json.dump(data, file, indent=4)
- return Result.ok("Setup File Created Successfully")
- except Exception as e:
- return Result.fail(e)
- return Result.ok("Setup File Created Successfully")
Advertisement
Add Comment
Please, Sign In to add comment