Updated op25 config functions
This commit is contained in:
@@ -2,6 +2,7 @@ import csv
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
from models.models import TalkgroupTag
|
||||
from typing import List, Dict
|
||||
from internal.logger import create_logger
|
||||
@@ -28,8 +29,8 @@ def scan_local_library() -> List[Dict]:
|
||||
# Use trunking sysname or filename as the identifier
|
||||
sys_name = data.get("trunking", {}).get("sysname", filename.replace(".json", ""))
|
||||
library.append({
|
||||
"name": sys_name,
|
||||
"system_name": filename,
|
||||
"system_name": sys_name,
|
||||
"filename": filename,
|
||||
"mode": "P25" if "trunking" in data else "NBFM"
|
||||
})
|
||||
except Exception as e:
|
||||
@@ -44,16 +45,27 @@ def activate_config_from_library(system_name: str) -> bool:
|
||||
if not system_name.endswith(".json"):
|
||||
system_name += ".json"
|
||||
|
||||
src = os.path.join(CONFIG_DIR, system_name)
|
||||
dst = os.path.join(CONFIG_DIR, "active.cfg.json")
|
||||
config_path = Path(CONFIG_DIR)
|
||||
src = config_path / system_name
|
||||
dst = config_path / "active.cfg.json"
|
||||
|
||||
if not os.path.exists(src):
|
||||
if not src.exists():
|
||||
LOGGER.error(f"Source config {system_name} not found in library.")
|
||||
return False
|
||||
|
||||
try:
|
||||
shutil.copy2(src, dst)
|
||||
LOGGER.info(f"Activated config: {system_name}")
|
||||
|
||||
# Copy sidecar files (tags/whitelist) if they exist
|
||||
src_tags = src.with_suffix(".tags.tsv")
|
||||
if src_tags.exists():
|
||||
shutil.copy2(src_tags, config_path / "active.cfg.tags.tsv")
|
||||
|
||||
src_whitelist = src.with_suffix(".whitelist.tsv")
|
||||
if src_whitelist.exists():
|
||||
shutil.copy2(src_whitelist, config_path / "active.cfg.whitelist.tsv")
|
||||
|
||||
return True
|
||||
except Exception as e:
|
||||
LOGGER.error(f"Failed to copy config: {e}")
|
||||
@@ -88,14 +100,16 @@ def get_current_active_config() -> Dict:
|
||||
return {}
|
||||
return {}
|
||||
|
||||
def save_talkgroup_tags(talkgroup_tags: List[TalkgroupTag]) -> None:
|
||||
with open(os.path.join(CONFIG_DIR, "active.cfg.tags.tsv"), 'w', newline='', encoding='utf-8') as file:
|
||||
def save_talkgroup_tags(talkgroup_tags: List[TalkgroupTag], prefix: str = "active.cfg") -> None:
|
||||
filename = f"{prefix}.tags.tsv"
|
||||
with open(os.path.join(CONFIG_DIR, filename), 'w', newline='', encoding='utf-8') as file:
|
||||
writer = csv.writer(file, delimiter='\t', lineterminator='\n')
|
||||
for tag in talkgroup_tags:
|
||||
writer.writerow([tag.tagDec, tag.talkgroup])
|
||||
|
||||
def save_whitelist(talkgroup_tags: List[int]) -> None:
|
||||
with open(os.path.join(CONFIG_DIR, "active.cfg.whitelist.tsv"), 'w', newline='', encoding='utf-8') as file:
|
||||
def save_whitelist(talkgroup_tags: List[int], prefix: str = "active.cfg") -> None:
|
||||
filename = f"{prefix}.whitelist.tsv"
|
||||
with open(os.path.join(CONFIG_DIR, filename), 'w', newline='', encoding='utf-8') as file:
|
||||
writer = csv.writer(file, delimiter='\t', lineterminator='\n')
|
||||
for tag in talkgroup_tags:
|
||||
writer.writerow([tag])
|
||||
|
||||
Reference in New Issue
Block a user