mmpSearch/scripts/handler/utils.py

99 lines
2.6 KiB
Python
Executable File

# utils.py
import os
BASE_PATH = "/var/www/html/trens"
BASE_PATH_MMPSEARCH = "/var/www/html/trens/mmpSearch"
BASE_DATA = "/nethome/jotachina/projetos/mmpSearch"
SRC_MMPSEARCH = "/var/www/html/trens/src_mmpSearch"
MMP_FOLDER = os.path.join(BASE_PATH, "src_mmpSearch", "mmp")
MMPZ_FOLDER = os.path.join(BASE_PATH, "src_mmpSearch", "mmpz")
WAV_FOLDER = os.path.join(BASE_PATH, "src_mmpSearch", "wav")
METADATA_FOLDER = os.path.join(BASE_PATH, "src_mmpSearch", "metadata")
SAMPLE_MANIFEST = os.path.join(BASE_PATH, "src_mmpSearch", "metadata", "samples-manifest.json")
SAMPLE_SRC = os.path.join(SRC_MMPSEARCH, "samples")
MMP_MANIFEST = os.path.join(BASE_PATH, "src_mmpSearch", "metadata", "mmp-manifest.json")
DATA_FOLDER = os.path.join(BASE_DATA, "_data")
LOG_FOLDER = os.path.join(SRC_MMPSEARCH, "logs", "handler_logs")
CERT_PATH = "/etc/letsencrypt/live/alice.ufsj.edu.br/fullchain.pem"
KEY_PATH = "/etc/letsencrypt/live/alice.ufsj.edu.br/privkey.pem"
RUNTIME_DIR = "/tmp/runtime-root"
CONFIGS = [
{
"source_dir": SAMPLE_SRC,
"output_file": SAMPLE_MANIFEST,
"scan_type": "tree",
},
{
"source_dir": MMP_FOLDER,
"output_file": MMP_MANIFEST,
"scan_type": "list",
"extensions": [".mmp", ".mmpz"],
},
]
def scan_directory_tree(path):
tree = {}
if not os.path.isdir(path):
return tree
for item in os.listdir(path):
full_path = os.path.join(path, item)
if os.path.isdir(full_path):
tree[item] = scan_directory_tree(full_path)
else:
tree[item] = {"_isFile": True}
return tree
def scan_directory_list(path, allowed_extensions):
file_list = []
if not os.path.isdir(path):
return file_list
for item in os.listdir(path):
full_path = os.path.join(path, item)
if os.path.isfile(full_path) and any(
item.lower().endswith(ext) for ext in allowed_extensions
):
file_list.append(item)
return sorted(file_list)
SUPPORTED_PLUGINS = [
"audiofileprocessor",
"bitinvader",
"freeboy",
"papu",
"gigplayer",
"kicker",
"lb302",
"malletsstk",
"monstro",
"nes",
"opl2",
"organic",
"patman",
"sf2player",
"sfxr",
"sid",
"tripleoscillator",
"vibedstrings",
"watsyn",
"zynaddsubfx",
]
tags = {}
tags["TAG"] = []
tags["plugin"] = []
tags["sample"] = []
tags["bassline"] = []
tags["automation"] = []
def create_folders_if_not_exist(folders):
for folder in folders:
if not os.path.exists(folder):
os.makedirs(folder)