Add files via upload
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
extract_for_dev.py
|
||||
──────────────────
|
||||
Extracts all embedded source files from Avaya_5952_setup.py
|
||||
into individual files for development with Claude Code or any editor.
|
||||
|
||||
Run once to bootstrap the repo:
|
||||
python extract_for_dev.py
|
||||
|
||||
After editing source files, re-embed for distribution:
|
||||
python embed_for_dist.py (see that script)
|
||||
|
||||
The single-file Avaya_5952_setup.py is for end-user distribution.
|
||||
These extracted files are the development source of truth.
|
||||
"""
|
||||
|
||||
import re, sys
|
||||
from pathlib import Path
|
||||
|
||||
HERE = Path(__file__).parent
|
||||
SETUP = HERE / "Avaya_5952_setup.py"
|
||||
|
||||
if not SETUP.exists():
|
||||
print(f"Error: {SETUP} not found")
|
||||
sys.exit(1)
|
||||
|
||||
src = SETUP.read_text()
|
||||
|
||||
# ── Extract repr()-encoded string constants ─────────────────────────────────
|
||||
|
||||
def extract_repr(src, name):
|
||||
idx = src.find(f'\n{name} = ')
|
||||
if idx == -1:
|
||||
return None
|
||||
start = idx + len(f'\n{name} = ')
|
||||
qc = src[start]
|
||||
end = start + 1
|
||||
while end < len(src):
|
||||
if src[end] == qc and src[end-1] != '\\':
|
||||
end += 1; break
|
||||
end += 1
|
||||
try:
|
||||
return eval(src[start:end])
|
||||
except Exception as e:
|
||||
print(f" Warning: could not extract {name}: {e}")
|
||||
return None
|
||||
|
||||
# ── Extract triple-quoted string constants ───────────────────────────────────
|
||||
|
||||
def extract_triple(src, name):
|
||||
pattern = rf'{name}\s*=\s*"""(.*?)"""'
|
||||
m = re.search(pattern, src, re.DOTALL)
|
||||
return m.group(1) if m else None
|
||||
|
||||
# ── Files to extract ─────────────────────────────────────────────────────────
|
||||
|
||||
print("Extracting source files from Avaya_5952_setup.py...\n")
|
||||
|
||||
extractions = [
|
||||
# (extract_fn, constant_name, output_filename, note)
|
||||
(extract_repr, 'BACKEND_SRC', 'switch_backend.py', "FastAPI backend"),
|
||||
(extract_repr, 'JSX_SRC', 'ers5952-manager.jsx', "React frontend"),
|
||||
(extract_repr, 'README_SRC', 'README.md', "Documentation"),
|
||||
(extract_triple, 'DOCKERFILE', 'Dockerfile', "Docker image"),
|
||||
(extract_triple, 'COMPOSE_YML', 'docker-compose.yml', "Docker Compose"),
|
||||
(extract_triple, 'CADDYFILE_TEMPLATE','Caddyfile.template', "Caddy config template"),
|
||||
]
|
||||
|
||||
written = []
|
||||
for fn, const, fname, note in extractions:
|
||||
content = fn(src, const)
|
||||
if content:
|
||||
out = HERE / fname
|
||||
if out.exists():
|
||||
overwrite = input(f" {fname} already exists — overwrite? [y/N] ").strip().lower()
|
||||
if overwrite != 'y':
|
||||
print(f" skipped {fname}")
|
||||
continue
|
||||
out.write_text(content)
|
||||
written.append(fname)
|
||||
print(f" ✓ {fname:<35} {note} ({len(content):,} chars)")
|
||||
else:
|
||||
print(f" ✗ {fname:<35} not found in setup script")
|
||||
|
||||
print(f"\n{len(written)} files extracted.")
|
||||
print("""
|
||||
Next steps:
|
||||
1. git init && git add . && git commit -m "initial: extracted from single-file setup"
|
||||
2. Push to GitHub (check no credentials in source first)
|
||||
3. Open with Claude Code: claude
|
||||
4. Say: "Read HANDOFF.md — continue building the switch manager"
|
||||
|
||||
To re-embed source files back into Avaya_5952_setup.py for distribution:
|
||||
python embed_for_dist.py
|
||||
""")
|
||||
Reference in New Issue
Block a user