gallery.accords-library.com/server/szurubooru/func/files.py

27 lines
683 B
Python
Raw Normal View History

2016-04-09 19:41:10 +00:00
import os
from szurubooru import config
2016-04-30 21:17:08 +00:00
def _get_full_path(path):
return os.path.join(config.config['data_dir'], path)
def delete(path):
full_path = _get_full_path(path)
if os.path.exists(full_path):
os.unlink(full_path)
def has(path):
return os.path.exists(_get_full_path(path))
2016-04-30 21:17:08 +00:00
def get(path):
full_path = _get_full_path(path)
if not os.path.exists(full_path):
return None
with open(full_path, 'rb') as handle:
return handle.read()
2016-04-09 19:41:10 +00:00
def save(path, content):
2016-04-30 21:17:08 +00:00
full_path = _get_full_path(path)
2016-04-09 19:41:10 +00:00
os.makedirs(os.path.dirname(full_path), exist_ok=True)
with open(full_path, 'wb') as handle:
handle.write(content)