add self contained mode
This commit is contained in:
parent
c22856a324
commit
ed3b9e2832
2 changed files with 37 additions and 10 deletions
|
|
@ -17,7 +17,7 @@ class AppConfig(BaseModel):
|
||||||
anonymize_users: bool = Field(default=False)
|
anonymize_users: bool = Field(default=False)
|
||||||
log_level: str = Field(default="INFO")
|
log_level: str = Field(default="INFO")
|
||||||
|
|
||||||
def load_config(config_path: Union[str, Path] = "config.yaml", create_if_missing: bool = True) -> AppConfig:
|
def load_config(config_path: Union[str, Path] = "reaper_config.yaml", create_if_missing: bool = True) -> AppConfig:
|
||||||
path = Path(config_path)
|
path = Path(config_path)
|
||||||
if not path.exists():
|
if not path.exists():
|
||||||
if not create_if_missing:
|
if not create_if_missing:
|
||||||
|
|
@ -36,19 +36,23 @@ def load_config(config_path: Union[str, Path] = "config.yaml", create_if_missing
|
||||||
|
|
||||||
return AppConfig(**data)
|
return AppConfig(**data)
|
||||||
|
|
||||||
def save_config(config: AppConfig, config_path: Union[str, Path] = "config.yaml"):
|
def save_config(config: AppConfig, config_path: Union[str, Path] = "reaper_config.yaml"):
|
||||||
path = Path(config_path)
|
path = Path(config_path)
|
||||||
data = config.model_dump(exclude_none=True)
|
data = config.model_dump(exclude_none=True)
|
||||||
with open(path, "w", encoding="utf-8") as f:
|
with open(path, "w", encoding="utf-8") as f:
|
||||||
yaml.safe_dump(data, f, default_flow_style=False, sort_keys=False)
|
yaml.safe_dump(data, f, default_flow_style=False, sort_keys=False)
|
||||||
|
|
||||||
def get_available_configs() -> list[str]:
|
def get_available_configs() -> list[str]:
|
||||||
"""Returns a list of available configuration names from `ReaperFiles-*` folders."""
|
"""Returns a list of available configuration names.
|
||||||
|
If reaper_config.yaml exists in CWD, returns ['.'] to signify standalone mode."""
|
||||||
|
if Path("reaper_config.yaml").exists():
|
||||||
|
return ["."]
|
||||||
|
|
||||||
configs = []
|
configs = []
|
||||||
for item in Path(".").iterdir():
|
for item in Path(".").iterdir():
|
||||||
if item.is_dir() and item.name.startswith("ReaperFiles-"):
|
if item.is_dir() and item.name.startswith("ReaperFiles-"):
|
||||||
config_name = item.name[len("ReaperFiles-"):]
|
config_name = item.name[len("ReaperFiles-"):]
|
||||||
if (item / "config.yaml").exists():
|
if (item / "reaper_config.yaml").exists():
|
||||||
configs.append(config_name)
|
configs.append(config_name)
|
||||||
return sorted(configs)
|
return sorted(configs)
|
||||||
|
|
||||||
|
|
@ -56,6 +60,6 @@ def create_new_config(name: str) -> Path:
|
||||||
"""Creates a new configuration folder and default config file."""
|
"""Creates a new configuration folder and default config file."""
|
||||||
folder_path = Path(f"ReaperFiles-{name}")
|
folder_path = Path(f"ReaperFiles-{name}")
|
||||||
folder_path.mkdir(exist_ok=True)
|
folder_path.mkdir(exist_ok=True)
|
||||||
config_path = folder_path / "config.yaml"
|
config_path = folder_path / "reaper_config.yaml"
|
||||||
load_config(config_path) # creates default
|
load_config(config_path) # creates default
|
||||||
return folder_path
|
return folder_path
|
||||||
|
|
|
||||||
|
|
@ -183,15 +183,38 @@ class ConfigSelectionScreen(Screen):
|
||||||
configs = get_available_configs()
|
configs = get_available_configs()
|
||||||
lv = self.query_one("#config_list", ListView)
|
lv = self.query_one("#config_list", ListView)
|
||||||
lv.clear()
|
lv.clear()
|
||||||
|
|
||||||
|
is_standalone = ("." in configs)
|
||||||
|
try:
|
||||||
|
self.query_one("#btn_new_config", Button).display = not is_standalone
|
||||||
|
except Exception: pass
|
||||||
|
|
||||||
for c in configs:
|
for c in configs:
|
||||||
lv.append(ListItem(Label(c), name=c))
|
label = c
|
||||||
|
if c == ".":
|
||||||
|
dir_name = Path(".").resolve().name
|
||||||
|
if dir_name.startswith("ReaperFiles-"):
|
||||||
|
label = dir_name[len("ReaperFiles-"):]
|
||||||
|
else:
|
||||||
|
label = dir_name
|
||||||
|
lv.append(ListItem(Label(label), name=c))
|
||||||
return configs
|
return configs
|
||||||
|
|
||||||
def on_list_view_selected(self, event: ListView.Selected) -> None:
|
def on_list_view_selected(self, event: ListView.Selected) -> None:
|
||||||
cfg_name = event.item.name
|
cfg_name = event.item.name
|
||||||
cfg_path = Path(f"ReaperFiles-{cfg_name}") / "config.yaml"
|
if cfg_name == ".":
|
||||||
|
cfg_path = Path("reaper_config.yaml")
|
||||||
|
dir_name = Path(".").resolve().name
|
||||||
|
if dir_name.startswith("ReaperFiles-"):
|
||||||
|
display_name = dir_name[len("ReaperFiles-"):]
|
||||||
|
else:
|
||||||
|
display_name = dir_name
|
||||||
|
else:
|
||||||
|
cfg_path = Path(f"ReaperFiles-{cfg_name}") / "reaper_config.yaml"
|
||||||
|
display_name = cfg_name
|
||||||
|
|
||||||
from src.ui.mode_screen import ModeScreen
|
from src.ui.mode_screen import ModeScreen
|
||||||
self.app.push_screen(ModeScreen(cfg_name, cfg_path))
|
self.app.push_screen(ModeScreen(display_name, cfg_path))
|
||||||
|
|
||||||
def action_new_config(self) -> None:
|
def action_new_config(self) -> None:
|
||||||
def cb(name: str | None):
|
def cb(name: str | None):
|
||||||
|
|
@ -199,7 +222,7 @@ class ConfigSelectionScreen(Screen):
|
||||||
create_new_config(name)
|
create_new_config(name)
|
||||||
self.refresh_configs()
|
self.refresh_configs()
|
||||||
# Immediately open the ConfigScreen for the new config
|
# Immediately open the ConfigScreen for the new config
|
||||||
cfg_path = Path(f"ReaperFiles-{name}") / "config.yaml"
|
cfg_path = Path(f"ReaperFiles-{name}") / "reaper_config.yaml"
|
||||||
def on_config_saved(saved: bool = False):
|
def on_config_saved(saved: bool = False):
|
||||||
if saved:
|
if saved:
|
||||||
self.refresh_configs()
|
self.refresh_configs()
|
||||||
|
|
@ -399,7 +422,7 @@ class ConfigScreen(Screen):
|
||||||
|
|
||||||
yield Rule(id="footer_rule")
|
yield Rule(id="footer_rule")
|
||||||
with Horizontal(id="cfg_actions"):
|
with Horizontal(id="cfg_actions"):
|
||||||
yield Button("Save Configuration", variant="success", id="btn_save", tooltip="Save all changes to config.yaml")
|
yield Button("Save Configuration", variant="success", id="btn_save", tooltip="Save all changes to reaper_config.yaml")
|
||||||
yield Button("Back", id="btn_back")
|
yield Button("Back", id="btn_back")
|
||||||
yield Footer()
|
yield Footer()
|
||||||
yield RamDisplay()
|
yield RamDisplay()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue