| 11 | |
| 12 | |
| 13 | class Storage(): |
| 14 | def __init__(self): |
| 15 | pass |
| 16 | |
| 17 | |
| 18 | def get_project_settings(self) -> List[Settings]: |
| 19 | project_settings: List[Settings] = [] |
| 20 | for project_name in os.listdir(PATH_WEB_PROJECT): |
| 21 | project_setting = self.get_project_setting(project_name) |
| 22 | if project_setting is None: |
| 23 | continue |
| 24 | project_settings.append(project_setting) |
| 25 | return project_settings |
| 26 | |
| 27 | |
| 28 | def get_project_setting(self, project_name: str) -> Settings| None: |
| 29 | path = "{}/{}".format(PATH_WEB_PROJECT, project_name) |
| 30 | json_path = "{}/project.pickle".format(path) |
| 31 | if not os.path.exists(json_path): |
| 32 | return None |
| 33 | logger.info("Loading project from: {}".format(json_path)) |
| 34 | with open(json_path, "rb") as f: |
| 35 | settings = pickle.load(f) |
| 36 | return settings |
| 37 | |
| 38 | |
| 39 | def add_project_setting(self, settings: Settings): |
| 40 | os.makedirs(PATH_WEB_PROJECT + settings.project_name, exist_ok=True) |
| 41 | with open("{}/{}/project.pickle".format(PATH_WEB_PROJECT, settings.project_name), "wb") as f: |
| 42 | pickle.dump(settings, f) |
| 43 | |
| 44 | |
| 45 | def save_project_settings(self, settings: Settings): |
| 46 | with open("{}/{}/project.pickle".format(PATH_WEB_PROJECT, settings.project_name), "wb") as f: |
| 47 | pickle.dump(settings, f) |
| 48 | |
| 49 | |
| 50 | storage = Storage() |