def save_settings_file(self, settings, module="config", file_name="settings"): module_folder = ModulesLoader.get_module_content_folder(module) yaml.safe_dump( settings, open("{}/config/{}.yaml".format(module_folder, file_name), "w"))
def save_data(self, table, object_id, data, module="data"): module_folder = ModulesLoader.get_module_content_folder(module) yaml.safe_dump( data, open("{}/data/{}/{}.yaml".format(module_folder, table, object_id), "w")) return data
def download_media(self, media_id, media_url, folder="uncategorized"): module_folder = ModulesLoader.get_module_content_folder("cache") media_data = urllib.request.urlopen(media_url).read() with open("{}/{}/{}".format(module_folder, folder, media_id), "wb") as media_file: media_file.write(media_data) return media_data
def load_form_steps(self, form_name, lang=None): module_folder = ModulesLoader.get_module_content_folder("forms") if not lang: config_manager = ModulesLoader.load_manager("config") lang_settings = config_manager.load_settings_file("forms", "lang") lang = lang_settings["default"] return yaml.safe_load( open("{}/formats/{}/{}/steps.yaml".format(module_folder, lang, form_name), "r", encoding="utf8"))
def find_entry_by_field(self, table, field, value, module="data"): module_folder = ModulesLoader.get_module_content_folder(module) files = os.listdir("{}/data/{}".format(module_folder, table)) files.remove("__default.yaml") for f in files: entry_id = f.replace(".yaml", "") data = self.load_data(table, entry_id) if data[field] == value: return data return None
def load_table_entries(self, table, module="data"): module_folder = ModulesLoader.get_module_content_folder(module) entries = [] files = os.listdir("{}/data/{}".format(module_folder, table)) files.remove("__default.yaml") for f in files: entry_id = f.replace(".yaml", "") data = self.load_data(table, entry_id) entries.append(data) return entries
def load_media(self, media_id, folder="uncategorized"): module_folder = ModulesLoader.get_module_content_folder("cache") return open("{}/{}/{}".format(module_folder, folder, media_id), "rb")
def save_cache(self, cache): module_folder = ModulesLoader.get_module_content_folder("cache") yaml.safe_dump(cache, open("{}/cache.yaml".format(module_folder), "w"))
def load_cache(self): module_folder = ModulesLoader.get_module_content_folder("cache") return yaml.safe_load(open("{}/cache.yaml".format(module_folder), "r"))
def load_settings_file(self, module="config", file_name="settings"): module_folder = ModulesLoader.get_module_content_folder(module) return yaml.safe_load( open("{}/config/{}.yaml".format(module_folder, file_name)))
def has_data(self, table, object_id, module="data"): module_folder = ModulesLoader.get_module_content_folder(module) return os.path.exists("{}/data/{}/{}.yaml".format( module_folder, table, object_id))
def delete_data(self, table, object_id, module="data"): module_folder = ModulesLoader.get_module_content_folder(module) os.remove("{}/data/{}/{}.yaml".format(module_folder, table, object_id))
def load_data(self, table, object_id, module="data"): module_folder = ModulesLoader.get_module_content_folder(module) return yaml.safe_load( open("{}/data/{}/{}.yaml".format(module_folder, table, object_id), "r"))