-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
90 lines (72 loc) · 3.12 KB
/
Copy pathconfig.py
File metadata and controls
90 lines (72 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import os
import sys
from pathlib import Path
from dotenv import load_dotenv
load_dotenv()
BASE_DIR = Path(__file__).parent.parent
def get_mesonh_code_dir() -> str:
return os.getenv("MESONH_CODE_DIR", str(BASE_DIR))
def get_mesonh_doc_dir() -> str:
return os.getenv("MESONH_DOC_DIR", str(BASE_DIR))
# Derived paths
EXAMPLES_DIR = os.path.join(get_mesonh_code_dir(), "examples")
DOC_DIR = os.path.join(get_mesonh_doc_dir(), "docs/source/documentation/users_guide/executables_namelists/namelists")
EXECUTABLES_DIR = os.path.join(get_mesonh_doc_dir(), "docs/source/documentation/users_guide/executables_namelists")
DOC_CATALOGUE_DIR = os.path.join(get_mesonh_doc_dir(), "docs/source/applications/catalogue")
def setup_wizard():
"""Interactive first-time setup wizard."""
print("=" * 60)
print("Meso-NH Namelist Editor - First Time Setup")
print("=" * 60)
print()
env_file = BASE_DIR / ".env"
if env_file.exists():
print(f".env file already exists at {env_file}")
overwrite = input("Overwrite? (y/N): ").strip().lower()
if overwrite != 'y':
print("Setup cancelled.")
return
print("\nPlease provide the paths to the Meso-NH repositories:")
print()
default_code = str(BASE_DIR)
prompt_code = f"Path to Meso-NH CODE repo (contains 'examples/' folder) [{default_code}]: "
mesonh_code_dir = input(prompt_code).strip()
if not mesonh_code_dir:
mesonh_code_dir = default_code
examples_path = Path(mesonh_code_dir) / "examples"
if not examples_path.exists():
print(f"WARNING: {examples_path} does not exist!")
proceed = input("Continue anyway? (y/N): ").strip().lower()
if proceed != 'y':
print("Setup cancelled.")
return
default_doc = str(BASE_DIR)
prompt_doc = f"Path to Meso-NH DOC repo (contains 'docs/.../namelists/') [{default_doc}]: "
mesonh_doc_dir = input(prompt_doc).strip()
if not mesonh_doc_dir:
mesonh_doc_dir = default_doc
namelists_path = Path(mesonh_doc_dir) / "docs" / "source" / "documentation" / "users_guide" / "executables_namelists" / "namelists"
if not namelists_path.exists():
print(f"WARNING: {namelists_path} does not exist!")
proceed = input("Continue anyway? (y/N): ").strip().lower()
if proceed != 'y':
print("Setup cancelled.")
return
env_content = f"""# Meso-NH Namelist Editor Configuration
# Generated by setup wizard
# Path to Meso-NH CODE repository (contains 'examples/' folder)
MESONH_CODE_DIR={mesonh_code_dir}
# Path to Meso-NH DOCUMENTATION repository (contains 'docs/.../namelists/')
MESONH_DOC_DIR={mesonh_doc_dir}
"""
with open(env_file, 'w') as f:
f.write(env_content)
print()
print(f"Configuration saved to {env_file}")
print()
print("You can now run the application with:")
print(" streamlit run Applications.py")
print()
if __name__ == "__main__":
if len(sys.argv) > 1 and sys.argv[1] == "setup":
setup_wizard()