Exemple #1
0
    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"))
Exemple #2
0
    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
Exemple #3
0
    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
Exemple #4
0
    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"))
Exemple #5
0
    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
Exemple #6
0
    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
Exemple #7
0
    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")
Exemple #8
0
    def save_cache(self, cache):
        module_folder = ModulesLoader.get_module_content_folder("cache")

        yaml.safe_dump(cache, open("{}/cache.yaml".format(module_folder), "w"))
Exemple #9
0
    def load_cache(self):
        module_folder = ModulesLoader.get_module_content_folder("cache")

        return yaml.safe_load(open("{}/cache.yaml".format(module_folder), "r"))
Exemple #10
0
    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)))
Exemple #11
0
    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))
Exemple #12
0
    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))
Exemple #13
0
    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"))