def load_from_cache(self, name):
        if self.controller.site_settings.base_path is None:
            return []
        path_name = self.controller.site_settings.base_path.replace(
            "\\", "").replace("/", "").replace(":", "").replace(".", "")
        json = cache.get_json(name + path_name)
        if self.template_node.unique_key not in json:
            result = []
            json[self.template_node.unique_key] = result
            return result

        return json[self.template_node.unique_key]
Exemplo n.º 2
0
    def load_from_cache(self, name):
        download_settings = gui.Application.instance().download_settings
        if download_settings.save_path is None:
            return []
        path_name = download_settings.save_path.replace("\\", "").replace(
            "/", "").replace(":", "").replace(".", "")
        json = cache.get_json(name + path_name)
        if self.template_node.unique_key not in json:
            result = []
            json[self.template_node.unique_key] = result
            return result

        return json[self.template_node.unique_key]
Exemplo n.º 3
0
    async def retrieve_folder_name(self, session, signal_handler,
                                   site_settings):
        if self.folder_name is not None or self.folder_module_name is None:
            return self.folder_name

        folder_module = importlib.import_module(self.folder_module_name)
        function = getattr(folder_module, self.folder_function_name)
        logger.debug(
            f"Calling folder function: {function.__module__}."
            f"{function.__name__}<{dict_to_string(self.function_kwargs)}>")
        folder_name = await function(session=session,
                                     site_settings=site_settings,
                                     **self.function_kwargs)

        folder_name_cache = cache.get_json("folder_name")
        folder_name_cache[self.kwargs_hash] = folder_name

        signal_handler.update_folder_name(self.unique_key, folder_name)
        return folder_name
Exemplo n.º 4
0
async def call_function_or_cache(func, identifier, *args, **kwargs):
    json_name = func.__module__ + "." + func.__name__
    table = cache.get_json(json_name)

    func_identifier = get_func_identifier(args, kwargs)
    attributes = table.get(func_identifier, {})
    cache_identifier = copy.copy(attributes.get("identifier", None))
    try:
        if identifier is not None and identifier == cache_identifier:
            if attributes["pickle"]:
                with open(attributes["value"], "rb") as f:
                    return pickle.load(f)

            return attributes["value"]
    except FileNotFoundError:
        logger.warning("Pickle file could not be found")
        pass

    result = await func(*args, **kwargs)

    if identifier is not None:
        logger.debug(
            f"Called function: {json_name}, func_identifier: {func_identifier}"
        )
    attributes["identifier"] = identifier

    if is_jsonable(result):
        attributes["value"] = result
        attributes["pickle"] = False
    else:
        file_name = str(random.randint(1e18, 1e19)) + ".pickle"
        path = os.path.join(FUNCTION_CACHE_PATH, file_name)
        attributes["value"] = path
        attributes["pickle"] = True

        with open(path, "wb+") as f:
            pickle.dump(result, f)

    table[func_identifier] = attributes
    return result
Exemplo n.º 5
0
def get_folder_name_from_hash(kwargs_hash):
    folder_name_cache = cache.get_json("folder_name")
    folder_name = folder_name_cache.get(kwargs_hash, None)
    return folder_name