"""Read-only collection of default-template metadata for isolated onboarding tests.""" import base64 import gzip import importlib.util import json import os from pathlib import Path import shlex import sys root = Path(__file__).resolve().parents[1] deps = Path(os.environ.get('TEMP', '')) / 'fmode-baseline-python' if deps.is_dir(): sys.path.insert(0, str(deps)) spec = importlib.util.spec_from_file_location('server_access', root / 'cloud/scripts/r730_root_v3.py') server = importlib.util.module_from_spec(spec) spec.loader.exec_module(server) server.USER = 'fmode' client, attempts, error = server._connect(attempts=3) if client is None: raise SystemExit('SSH unavailable: ' + type(error).__name__) out = root / '.local-backup/new-account-20261128' out.mkdir(parents=True, exist_ok=True) remote = r''' import base64,gzip,json,pathlib base=pathlib.Path('/opt/fmode-templates/default') manifest=[] for directory in ['plugins','scripts','.fmode-media-patch','hooks','platforms']: root=base/directory if root.is_dir(): for p in sorted(root.rglob('*')): if p.is_file() and '__pycache__' not in p.parts and '.git' not in p.parts: manifest.append({'path':str(p.relative_to(base)),'bytes':p.stat().st_size}) selected_plugins=['plugin-active-reporter','plugin-deliverable-inject','plugin-fmode','plugin-gateway-finish-guard','plugin-matrix-cloud-url-fallback','plugin-matrix-outbound-s3','plugin-matrix-process-notice','plugin-media-text-merge'] selected_scripts=['fmode-artifact-drain.sh','fmode-artifact-push.py','fmode-deliverable-hook.py','fmode-process-notice.py','fmode-round-marker.py'] files={} for item in manifest: rel=item['path']; parts=pathlib.PurePosixPath(rel).parts wanted=((parts[0]=='plugins' and len(parts)>1 and parts[1] in selected_plugins) or (parts[0]=='scripts' and parts[-1] in selected_scripts) or (parts[0]=='.fmode-media-patch' and parts[-1] in ['entry.sh','patch_spec.py']) or parts[0]=='platforms') if wanted and '.bak' not in rel and '/tests/' not in rel and not parts[-1].startswith('.'): files[rel]=(base/rel).read_text() result={'source':str(base),'manifest':manifest,'files':files, 'config':(base/'config.yaml').read_text() if (base/'config.yaml').is_file() else None, 'envKeys':[line.split('=',1)[0] for line in (base/'.env').read_text().splitlines() if '=' in line and not line.startswith('#')] if (base/'.env').is_file() else []} print(base64.b64encode(gzip.compress(json.dumps(result).encode())).decode()) ''' try: stdin, stdout, stderr = client.exec_command('sudo -S -p "" python3 -B -c ' + shlex.quote(remote), timeout=60) stdin.write(server.PW + '\n') stdin.flush() data, error = stdout.read(), stderr.read() code = stdout.channel.recv_exit_status() if code: raise SystemExit('Read-only template query failed: ' + str(code)) result = json.loads(gzip.decompress(base64.b64decode(data.strip()))) (out / 'template-metadata.json').write_text(json.dumps(result, ensure_ascii=False, indent=2), encoding='utf-8') print(json.dumps({'source': result['source'], 'files': list(result['files']), 'envKeys': result['envKeys'], 'configSavedPrivately': result['config'] is not None}, ensure_ascii=False)) finally: client.close()