Python xdg.BaseDirectory.xdg_cache_home() Examples

The following are 3 code examples of xdg.BaseDirectory.xdg_cache_home(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module xdg.BaseDirectory , or try the search function .
Example #1
Source File: humblebundle.py    From humblebundle with GNU General Public License v3.0 6 votes vote down vote up
def cli():
    global APPNAME, CONFIGDIR, CACHEDIR, AUTHFILE, COOKIEJAR

    APPNAME   = osp.basename(osp.splitext(__file__)[0])
    CONFIGDIR = xdg.save_config_path(APPNAME)  # creates the dir
    CACHEDIR  = osp.join(xdg.xdg_cache_home, APPNAME)
    AUTHFILE  = osp.join(CONFIGDIR, "login.conf")
    COOKIEJAR = osp.join(CONFIGDIR, "cookies.txt")
    # No changes in DATADIR

    try:
        sys.exit(main())

    except KeyboardInterrupt:
        pass
    except HumbleBundleError as e:
        log.critical(e)
        sys.exit(1)
    except Exception as e:
        log.critical(e, exc_info=True)
        sys.exit(1) 
Example #2
Source File: logger.py    From ytmdl with MIT License 6 votes vote down vote up
def __init__(
            self,
            name,
            level='INFO',
            disable_file=False
    ):
        self.name = name
        self._file_format = ''
        self._console_format = ''
        self._log_file = Path(os.path.join(xdg_cache_home, 'ytmdl/logs/log.cat'))
        self._check_logfile()
        self._level_number = {
                                'DEBUG': 0,
                                'INFO': 1,
                                'WARNING': 2,
                                'ERROR': 3,
                                'CRITICAL': 4
                             }
        self.level = self._level_number[level]
        self._disable_file = disable_file
        self._instances.append(self) 
Example #3
Source File: search.py    From duden with MIT License 5 votes vote down vote up
def cached_response(prefix=''):
    """
    Add `cache=True` keyword argument to a function to allow result caching based on single string
    argument.
    """
    def decorator_itself(func):
        def function_wrapper(cache_key, cache=True, **kwargs):
            cachedir = Path(xdg_cache_home) / 'duden'
            filename = prefix + sanitize_word(cache_key) + '.gz'
            full_path = str(cachedir / filename)

            if cache:
                # try to read from cache
                cachedir.mkdir(exist_ok=True)
                try:
                    with gzip.open(full_path, 'rt') as f:
                        return f.read()
                except FileNotFoundError:
                    pass

            result = func(cache_key, **kwargs)

            if cache and result is not None:
                with gzip.open(full_path, 'wt') as f:
                    f.write(result)

            return result

        return function_wrapper
    return decorator_itself