本文整理汇总了Python中xdg.BaseDirectory.xdg_cache_home方法的典型用法代码示例。如果您正苦于以下问题:Python BaseDirectory.xdg_cache_home方法的具体用法?Python BaseDirectory.xdg_cache_home怎么用?Python BaseDirectory.xdg_cache_home使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xdg.BaseDirectory
的用法示例。
在下文中一共展示了BaseDirectory.xdg_cache_home方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cli
# 需要导入模块: from xdg import BaseDirectory [as 别名]
# 或者: from xdg.BaseDirectory import xdg_cache_home [as 别名]
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)
示例2: __init__
# 需要导入模块: from xdg import BaseDirectory [as 别名]
# 或者: from xdg.BaseDirectory import xdg_cache_home [as 别名]
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)
示例3: cached_response
# 需要导入模块: from xdg import BaseDirectory [as 别名]
# 或者: from xdg.BaseDirectory import xdg_cache_home [as 别名]
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