コード例 #1
0
def test_get_cache_home():
    os.environ["XDG_CACHE_HOME"] = '~/.cache'
    assert (get_cache_home() == os.path.expanduser(
        os.path.join(os.environ["XDG_CACHE_HOME"], 'papis')))
    os.environ["XDG_CACHE_HOME"] = os.path.abspath('/tmp/.cache')
    assert (get_cache_home() == os.path.abspath('/tmp/.cache/papis'))
    assert (os.path.exists(get_cache_home()))
    del os.environ["XDG_CACHE_HOME"]
    assert (get_cache_home() == os.path.abspath(
        os.path.expanduser(os.path.join('~/.cache', 'papis'))))
    tmp = os.path.join(tempfile.mkdtemp(), 'blah')
    papis.config.set('cache-dir', tmp)
    assert (get_cache_home() == tmp)
コード例 #2
0
    def __init__(self, library=None):
        papis.database.base.Database.__init__(self, library)
        self.logger = logging.getLogger('db:whoosh')
        self.cache_dir = os.path.join(get_cache_home(), 'database', 'whoosh')
        self.index_dir = os.path.expanduser(
            os.path.join(
                self.cache_dir,
                papis.database.cache.get_cache_file_name(
                    self.lib.path_format())))

        self.initialize()
コード例 #3
0
def get_cache_file_path(directory):
    """Get the full path to the cache file

    :param directory: Library folder
    :type  directory: str

    >>> import os; os.environ["XDG_CACHE_HOME"] = '/tmp'
    >>> get_cache_file_path('blah/papers')
    '/tmp/papis/database/c39177eca0eaea2e21134b0bd06631b6-papers'
    """
    cache_name = get_cache_file_name(directory)
    folder = os.path.expanduser(os.path.join(get_cache_home(), 'database'))
    if not os.path.exists(folder):
        os.makedirs(folder)
    return os.path.join(folder, cache_name)