当前位置: 首页>>代码示例>>Python>>正文


Python appdirs.user_cache_dir方法代码示例

本文整理汇总了Python中appdirs.user_cache_dir方法的典型用法代码示例。如果您正苦于以下问题:Python appdirs.user_cache_dir方法的具体用法?Python appdirs.user_cache_dir怎么用?Python appdirs.user_cache_dir使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在appdirs的用法示例。


在下文中一共展示了appdirs.user_cache_dir方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: set_cache_dir

# 需要导入模块: import appdirs [as 别名]
# 或者: from appdirs import user_cache_dir [as 别名]
def set_cache_dir(cache_dir=None):
    """
    The cache_dir is the directory in which stdpopsim stores and checks for
    downloaded data. If the specified cache_dir is not None, this value is
    converted to a pathlib.Path instance, which is used as the cache directory.
    If cache_dir is None (the default), the cache directory is set either from
    the environment variable `STDPOPSIM_CACHE` if it exists, or set to the
    default location using the :mod:`appdirs` module.

    No checks for existance, writability, etc. are performed by this function.
    """
    if cache_dir is None:
        cache_dir = os.environ.get("STDPOPSIM_CACHE", None)
    if cache_dir is None:
        cache_dir = appdirs.user_cache_dir("stdpopsim", "popgensims")
    global _cache_dir
    _cache_dir = pathlib.Path(cache_dir)
    logger.info(f"Set cache_dir to {_cache_dir}") 
开发者ID:popsim-consortium,项目名称:stdpopsim,代码行数:20,代码来源:cache.py

示例2: __init__

# 需要导入模块: import appdirs [as 别名]
# 或者: from appdirs import user_cache_dir [as 别名]
def __init__(self, config, api):
        self.config = config
        self.api = api
        self.cache_dir = user_cache_dir('fac', appauthor=False)
        self.storage = FileStorage(os.path.join(self.cache_dir, 'index'))

        self.schema = Schema(
            name=TEXT(sortable=True, phrase=True, field_boost=3,
                      analyzer=intraword),
            owner=TEXT(sortable=True, field_boost=2.5,
                       analyzer=intraword),
            title=TEXT(field_boost=2.0, phrase=False),
            summary=TEXT(phrase=True),
            downloads=NUMERIC(sortable=True),
            sort_name=SortColumn(),
            name_id=ID(stored=True),
        )

        try:
            self.index = self.storage.open_index()
        except EmptyIndexError:
            self.index = None

        self.db = JSONFile(os.path.join(self.cache_dir, 'mods.json')) 
开发者ID:mickael9,项目名称:fac,代码行数:26,代码来源:db.py

示例3: get_cache_dir

# 需要导入模块: import appdirs [as 别名]
# 或者: from appdirs import user_cache_dir [as 别名]
def get_cache_dir(subdir=None):
    """
    Function for getting cache directory to store reused files like kernels, or scratch space
    for autotuning, etc.
    """
    cache_dir = os.environ.get("NEON_CACHE_DIR")

    if cache_dir is None:
        cache_dir = appdirs.user_cache_dir("neon", "neon")

    if subdir:
        subdir = subdir if isinstance(subdir, list) else [subdir]
        cache_dir = os.path.join(cache_dir, *subdir)

    if not os.path.exists(cache_dir):
        os.makedirs(cache_dir)

    return cache_dir 
开发者ID:NervanaSystems,项目名称:ngraph-python,代码行数:20,代码来源:util.py

示例4: test_cache

# 需要导入模块: import appdirs [as 别名]
# 或者: from appdirs import user_cache_dir [as 别名]
def test_cache(capsys):
    my_cache_dir = os.path.join(user_cache_dir("genomepy"), __version__)
    if os.path.exists(my_cache_dir):
        rmtree(my_cache_dir)
    os.makedirs(my_cache_dir)
    cached = Bucket(my_cache_dir, days=7)

    @cached
    def expensive_method():
        print("Method called.")

    @expensive_method.callback
    def expensive_method(callinfo):
        print("Cache used.")

    expensive_method()
    expensive_method()

    captured = capsys.readouterr().out.strip().split("\n")
    assert captured == ["Method called.", "Cache used."] 
开发者ID:vanheeringen-lab,项目名称:genomepy,代码行数:22,代码来源:01_basic_test.py

示例5: __init__

# 需要导入模块: import appdirs [as 别名]
# 或者: from appdirs import user_cache_dir [as 别名]
def __init__(self, text, lang, segment_num, segment_count=None):
    self.text = text
    self.lang = lang
    self.segment_num = segment_num
    self.segment_count = segment_count
    self.preload_mutex = threading.Lock()
    if not hasattr(__class__, "cache"):
      db_filepath = os.path.join(appdirs.user_cache_dir(appname="google_speech",
                                                        appauthor=False),
                                 "google_speech-cache.sqlite")
      os.makedirs(os.path.dirname(db_filepath), exist_ok=True)
      cache_name = "sound_data"
      __class__.cache = web_cache.ThreadedWebCache(db_filepath,
                                                   cache_name,
                                                   expiration=60 * 60 * 24 * 365,  # 1 year
                                                   caching_strategy=web_cache.CachingStrategy.LRU)
      logging.getLogger().debug("Total size of file '%s': %s" % (db_filepath,
                                                                 __class__.cache.getDatabaseFileSize()))
      purged_count = __class__.cache.purge()
      logging.getLogger().debug("%u obsolete entries have been removed from cache '%s'" % (purged_count, cache_name))
      row_count = len(__class__.cache)
      logging.getLogger().debug("Cache '%s' contains %u entries" % (cache_name, row_count)) 
开发者ID:desbma,项目名称:GoogleSpeech,代码行数:24,代码来源:__init__.py

示例6: _ensure_directories

# 需要导入模块: import appdirs [as 别名]
# 或者: from appdirs import user_cache_dir [as 别名]
def _ensure_directories(self):
        """
        Create config dir, config file & cache dir if they do not exist yet.
        """
        self._config_dir = appdirs.user_config_dir('clay', 'Clay')
        self._config_file_path = os.path.join(self._config_dir, 'config.yaml')
        self._colours_file_path = os.path.join(self._config_dir, 'colours.yaml')

        try:
            os.makedirs(self._config_dir)
        except OSError as error:
            if error.errno != errno.EEXIST:
                raise

        self._cache_dir = appdirs.user_cache_dir('clay', 'Clay')
        try:
            os.makedirs(self._cache_dir)
        except OSError as error:
            if error.errno != errno.EEXIST:
                raise

        if not os.path.exists(self._config_file_path):
            with open(self._config_file_path, 'w') as settings_file:
                settings_file.write('{}') 
开发者ID:and3rson,项目名称:clay,代码行数:26,代码来源:settings.py

示例7: test_none

# 需要导入模块: import appdirs [as 别名]
# 或者: from appdirs import user_cache_dir [as 别名]
def test_none(self):
        stdpopsim.set_cache_dir(None)
        cache_dir = pathlib.Path(appdirs.user_cache_dir("stdpopsim", "popgensims"))
        self.assertEqual(stdpopsim.get_cache_dir(), cache_dir) 
开发者ID:popsim-consortium,项目名称:stdpopsim,代码行数:6,代码来源:test_cache.py

示例8: get_default_cache

# 需要导入模块: import appdirs [as 别名]
# 或者: from appdirs import user_cache_dir [as 别名]
def get_default_cache():
    """
    Return the ``PYTHON_EGG_CACHE`` environment variable
    or a platform-relevant user cache dir for an app
    named "Python-Eggs".
    """
    return (
        os.environ.get('PYTHON_EGG_CACHE')
        or appdirs.user_cache_dir(appname='Python-Eggs')
    ) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:12,代码来源:__init__.py

示例9: from_header

# 需要导入模块: import appdirs [as 别名]
# 或者: from appdirs import user_cache_dir [as 别名]
def from_header(cls, include_path=None, header_files=None):
        cache_dir = user_cache_dir('lst', 'kotori')
        if not os.path.isdir(cache_dir): os.makedirs(cache_dir)
        library = LibraryAdapter(
            header_files, cls.compile(include_path, header_files),
            include_path=include_path, library_path=include_path,
            cache_path=cache_dir)
        return library 
开发者ID:daq-tools,项目名称:kotori,代码行数:10,代码来源:c.py

示例10: setup_h2m_structs_pyclibrary

# 需要导入模块: import appdirs [as 别名]
# 或者: from appdirs import user_cache_dir [as 别名]
def setup_h2m_structs_pyclibrary():
    cache_dir = os.path.join(user_cache_dir('kotori'), 'lst')
    if not os.path.isdir(cache_dir): os.makedirs(cache_dir)
    lib_dir = os.path.join(os.path.dirname(__file__), 'cpp')
    library = LibraryAdapter(u'h2m_structs.h', u'h2m_structs.so', include_path=lib_dir, library_path=lib_dir, cache_path=cache_dir)
    struct_registry = StructRegistryByID(library)
    return struct_registry 
开发者ID:daq-tools,项目名称:kotori,代码行数:9,代码来源:util.py

示例11: setup_h2m_structs_cffi

# 需要导入模块: import appdirs [as 别名]
# 或者: from appdirs import user_cache_dir [as 别名]
def setup_h2m_structs_cffi():
    cache_dir = os.path.join(user_cache_dir('kotori'), 'lst')
    if not os.path.isdir(cache_dir): os.makedirs(cache_dir)
    lib_dir = os.path.join(os.path.dirname(__file__), 'cpp')
    library = LibraryAdapterCFFI(u'h2m_structs.h', u'h2m_structs.so', include_path=lib_dir, library_path=lib_dir, cache_path=cache_dir)
    struct_registry = StructRegistryByID(library)
    return struct_registry 
开发者ID:daq-tools,项目名称:kotori,代码行数:9,代码来源:util.py

示例12: __init__

# 需要导入模块: import appdirs [as 别名]
# 或者: from appdirs import user_cache_dir [as 别名]
def __init__(self, cachename):
        self.cachedir = os.path.join(appdirs.user_cache_dir(), cachename)
        if not os.path.exists(self.cachedir):
            os.makedirs(self.cachedir)
            with open(os.path.join(self.cachedir, "CACHEDIR.TAG"), "w") as f:
                f.write(
                    "Signature: 8a477f597d28d172789f06886806bc55\n"
                    "# This file is a cache directory tag created by 'acsoo'.\n"
                    "# For information about cache directory tags, see:\n"
                    "#	http://www.brynosaurus.com/cachedir/\n"
                ) 
开发者ID:acsone,项目名称:acsoo,代码行数:13,代码来源:cache.py

示例13: test_wheel

# 需要导入模块: import appdirs [as 别名]
# 或者: from appdirs import user_cache_dir [as 别名]
def test_wheel(mocker, tmp_path):
    # mock appdirs.user_cache_dir, so the cache
    # goes to a known place
    cachedir = tmp_path / "cache"
    mocker.patch.object(appdirs, "user_cache_dir", lambda: str(cachedir))
    runner = CliRunner()
    with runner.isolated_filesystem():
        with open("requirements.txt", "w") as f:
            f.write(
                "requests\n"
                "-e git+https://github.com/acsone/acsoo"
                "@178a896c360ed6059bb76da35af4e99815a8b8de"
                "#egg=acsoo\n"
            )
        res = runner.invoke(wheel, ["--no-deps", "--exclude-project"])
        assert res.exit_code == 0
        # acsoo wheel must be in cache
        cache_content = list(cachedir.glob("**/acsoo*.whl"))
        assert len(cache_content) == 1
        # two wheels must have been generated
        files = sorted(os.listdir("release"))
        assert len(files) == 2
        assert files[0].startswith("acsoo-2.0.2")
        assert files[1].startswith("requests")

        # run it again
        shutil.rmtree("release")
        res = runner.invoke(wheel, ["--no-deps", "--exclude-project"])
        assert res.exit_code == 0
        assert "Obtained -e git+https://github.com/acsone/acsoo" in res.output
        files = sorted(os.listdir("release"))
        assert len(files) == 2
        assert files[0].startswith("acsoo-2.0.2")
        assert files[1].startswith("requests") 
开发者ID:acsone,项目名称:acsoo,代码行数:36,代码来源:test_wheel.py

示例14: __make_path

# 需要导入模块: import appdirs [as 别名]
# 或者: from appdirs import user_cache_dir [as 别名]
def __make_path(self):
        uu = hashlib.sha256(self.response.content).hexdigest()
        base_path = user_cache_dir("python/pygbif")
        if not os.path.exists(base_path):
            os.makedirs(base_path)
        file_ext = (
            ".png" if has(self.response.headers["Content-Type"], "png") else ".mvt"
        )
        path = base_path + "/" + uu + file_ext
        return path 
开发者ID:sckott,项目名称:pygbif,代码行数:12,代码来源:map.py

示例15: _cache

# 需要导入模块: import appdirs [as 别名]
# 或者: from appdirs import user_cache_dir [as 别名]
def _cache(cls, app_name):
        """Return cache file."""
        from pathlib import Path
        from appdirs import user_cache_dir

        cache_dir = Path(user_cache_dir(app_name, None))
        cache_dir.mkdir(parents=True, exist_ok=True)

        return cache_dir / cls.STATE_NAME 
开发者ID:SwissDataScienceCenter,项目名称:renku-python,代码行数:11,代码来源:version.py


注:本文中的appdirs.user_cache_dir方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。