Files
RidgeScout/server/utils.py
T

41 lines
889 B
Python
Raw Normal View History

2025-05-23 12:28:52 -06:00
import os
ROOT = os.path.dirname(__file__)
2025-05-25 18:48:02 -06:00
DATA_ROOT = os.path.join(os.path.dirname(__file__), 'server_data')
2025-05-23 12:28:52 -06:00
2025-05-25 13:38:50 -06:00
METADATA_PATH4 = os.path.join(ROOT, 'metadata.json')
API_KEY_PATH = os.path.join(ROOT, 'api_key.txt')
MODIFIED_HEADER = 'modified'
API_KEY_HEADER = 'api_key'
2025-05-23 12:28:52 -06:00
def mkdir(path):
if not os.path.exists(path):
os.makedirs(path)
def ls(path):
try:
return os.listdir(path)
except:
return []
def read(path):
if not os.path.exists(path):
return None
try:
2025-05-25 13:38:50 -06:00
with open(path, 'rb') as f:
2025-05-23 12:28:52 -06:00
return f.read()
2025-05-25 13:38:50 -06:00
except Exception as e:
print(f"Error reading file {path}: {e}")
2025-05-23 12:28:52 -06:00
return None
def write(path, data):
if not os.path.exists(path):
2025-05-25 13:38:50 -06:00
with open(path, mode='ab'): pass
if isinstance(data, str):
data = str.encode(data)
with open(path, 'wb') as f:
2025-05-23 12:28:52 -06:00
f.write(data)