added file caching for DBs

This commit is contained in:
JanLJL
2020-01-22 15:07:46 +01:00
parent 662ad829ec
commit 02233f627e
2 changed files with 70 additions and 23 deletions

View File

@@ -1,6 +1,8 @@
#!/usr/bin/env python3
import os.path
CACHE_DIR = os.path.expanduser('~/.osaca/cache')
def find_file(name):
"""Check for existence of name in user or package data folders and return path."""
@@ -10,4 +12,17 @@ def find_file(name):
path = os.path.join(dir, name)
if os.path.exists(path):
return path
raise FileNotFoundError("Could not find {!r} in {!r}.".format(name, search_paths))
raise FileNotFoundError("Could not find {!r} in {!r}.".format(name, search_paths))
def exists_cached_file(name):
"""Check for existence of file in cache dir. Returns path if it exists and False otherwise."""
if not os.path.exists(CACHE_DIR):
os.makedirs(CACHE_DIR)
return False
search_paths = [CACHE_DIR]
for dir in search_paths:
path = os.path.join(dir, name)
if os.path.exists(path):
return path
return False