mirror of
https://github.com/RRZE-HPC/OSACA.git
synced 2026-01-05 02:30:08 +01:00
new caching structure with support for distribution
This commit is contained in:
@@ -1,28 +1,17 @@
|
||||
#!/usr/bin/env python3
|
||||
import os.path
|
||||
from pathlib import Path
|
||||
import hashlib
|
||||
|
||||
DATA_DIRS = [os.path.expanduser('~/.osaca/data'),
|
||||
os.path.join(os.path.dirname(__file__), 'data')]
|
||||
CACHE_DIR = os.path.expanduser('~/.osaca/cache')
|
||||
|
||||
|
||||
def find_file(name):
|
||||
def find_datafile(name):
|
||||
"""Check for existence of name in user or package data folders and return path."""
|
||||
search_paths = [os.path.expanduser('~/.osaca/data'),
|
||||
os.path.join(os.path.dirname(__file__), 'data')]
|
||||
for dir in search_paths:
|
||||
for dir in DATA_DIRS:
|
||||
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))
|
||||
|
||||
|
||||
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
|
||||
raise FileNotFoundError("Could not find {!r} in {!r}.".format(name, DATA_DIRS))
|
||||
|
||||
Reference in New Issue
Block a user