-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.py
More file actions
332 lines (268 loc) · 11.8 KB
/
install.py
File metadata and controls
332 lines (268 loc) · 11.8 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
"""
Synapse Design System — Installer
Detects Houdini preferences directory and installs:
- Shelf toolbar (synapse.shelf)
- Python panel (synapse_panel.pypanel)
- Shelf callbacks module (synapse_shelf.py)
- SVG icons with SYNAPSE_ namespace
- Design system modules (tokens, styles)
Supports: install, uninstall, verify, dry-run.
Usage:
python install.py # Install
python install.py --verify # Verify installation
python install.py --uninstall # Remove Synapse files
python install.py --dry-run # Show what would be done
python install.py --houdini-prefs PATH # Override prefs location
"""
import argparse
import os
import platform
import shutil
import sys
import glob
# ── Constants ─────────────────────────────────────────────
_VERSION = "1.0.0"
_SYNAPSE_HOME = os.path.dirname(os.path.abspath(__file__))
# Source locations relative to SYNAPSE_HOME
_SOURCES = {
"shelf": os.path.join(_SYNAPSE_HOME, "houdini", "toolbar", "synapse.shelf"),
"panel": os.path.join(_SYNAPSE_HOME, "houdini", "python_panels", "synapse_panel.pypanel"),
"shelf_callbacks": os.path.join(_SYNAPSE_HOME, "houdini", "scripts", "python", "synapse_shelf.py"),
"tokens": os.path.join(_SYNAPSE_HOME, "design", "tokens.py"),
"styles": os.path.join(_SYNAPSE_HOME, "design", "synapse_styles.py"),
"svg_dir": os.path.join(_SYNAPSE_HOME, "design", "icons", "svg"),
}
# Houdini target subdirectories
_TARGETS = {
"shelf": os.path.join("toolbar", "synapse.shelf"),
"panel": os.path.join("python_panels", "synapse_panel.pypanel"),
"shelf_callbacks": os.path.join("scripts", "python", "synapse_shelf.py"),
"tokens": os.path.join("scripts", "python", "tokens.py"),
"styles": os.path.join("scripts", "python", "synapse_styles.py"),
}
# Icon name mapping: remove size suffix for Houdini registration
# Houdini looks for SYNAPSE_iconname.svg in config/Icons/
_ICON_NAMESPACE = "SYNAPSE"
# ── Houdini Prefs Detection ──────────────────────────────
def _detect_houdini_prefs():
"""
Detect the Houdini user preferences directory.
Search order:
1. $HOUDINI_USER_PREF_DIR (if set)
2. Platform-specific defaults for Houdini 21.x, 20.x, 19.x
"""
# Check environment variable first
env_prefs = os.environ.get("HOUDINI_USER_PREF_DIR")
if env_prefs and os.path.isdir(env_prefs):
return env_prefs
# Platform-specific default locations
system = platform.system()
home = os.path.expanduser("~")
if system == "Windows":
documents = os.path.join(home, "Documents")
search_root = documents
elif system == "Darwin":
search_root = os.path.join(home, "Library", "Preferences", "houdini")
else: # Linux
search_root = home
# Search for houdini21.x, 20.x, etc. (newest first)
candidates = []
for major in [21, 20, 19]:
for minor in range(9, -1, -1):
if system == "Windows":
path = os.path.join(search_root, f"houdini{major}.{minor}")
elif system == "Darwin":
path = os.path.join(search_root, f"{major}.{minor}")
else:
path = os.path.join(search_root, f"houdini{major}.{minor}")
if os.path.isdir(path):
candidates.append(path)
if candidates:
return candidates[0] # Return newest version found
return None
# ── File Operations ───────────────────────────────────────
def _copy_file(src, dst, dry_run=False):
"""Copy a single file, creating parent directories as needed."""
if not os.path.exists(src):
print(f" SKIP {os.path.basename(src)} (source missing)")
return False
if dry_run:
print(f" COPY {src}")
print(f" -> {dst}")
return True
os.makedirs(os.path.dirname(dst), exist_ok=True)
shutil.copy2(src, dst)
print(f" OK {os.path.basename(dst)}")
return True
def _remove_file(path, dry_run=False):
"""Remove a file if it exists."""
if not os.path.exists(path):
return False
if dry_run:
print(f" DEL {path}")
return True
os.remove(path)
print(f" DEL {os.path.basename(path)}")
return True
# ── Install ───────────────────────────────────────────────
def install(prefs_dir, dry_run=False):
"""Install Synapse files into Houdini preferences."""
print(f"\n{'DRY RUN: ' if dry_run else ''}Installing Synapse v{_VERSION}")
print(f" Target: {prefs_dir}\n")
count = 0
# Core files
print("--- Core Files ---")
for key, rel_target in _TARGETS.items():
src = _SOURCES[key]
dst = os.path.join(prefs_dir, rel_target)
if _copy_file(src, dst, dry_run):
count += 1
# Icons — copy 32px SVGs as SYNAPSE_<name>.svg
print("\n--- Icons ---")
icons_dst_dir = os.path.join(prefs_dir, "config", "Icons")
svg_dir = _SOURCES["svg_dir"]
if os.path.isdir(svg_dir):
svg_32_files = sorted(glob.glob(os.path.join(svg_dir, "*_32.svg")))
for svg_path in svg_32_files:
basename = os.path.basename(svg_path)
# e.g., "synapse_32.svg" -> "SYNAPSE_synapse.svg"
icon_name = basename.replace("_32.svg", "")
dst_name = f"{_ICON_NAMESPACE}_{icon_name}.svg"
dst_path = os.path.join(icons_dst_dir, dst_name)
if _copy_file(svg_path, dst_path, dry_run):
count += 1
else:
print(" SKIP No SVG directory found (run generate_icons.py first)")
print(f"\n{'Would install' if dry_run else 'Installed'}: {count} files")
return count
# ── Uninstall ─────────────────────────────────────────────
def uninstall(prefs_dir, dry_run=False):
"""Remove Synapse files from Houdini preferences."""
print(f"\n{'DRY RUN: ' if dry_run else ''}Uninstalling Synapse")
print(f" Target: {prefs_dir}\n")
count = 0
# Core files
print("--- Core Files ---")
for key, rel_target in _TARGETS.items():
path = os.path.join(prefs_dir, rel_target)
if _remove_file(path, dry_run):
count += 1
# Icons
print("\n--- Icons ---")
icons_dir = os.path.join(prefs_dir, "config", "Icons")
if os.path.isdir(icons_dir):
for icon_file in glob.glob(os.path.join(icons_dir, f"{_ICON_NAMESPACE}_*.svg")):
if _remove_file(icon_file, dry_run):
count += 1
print(f"\n{'Would remove' if dry_run else 'Removed'}: {count} files")
return count
# ── Verify ────────────────────────────────────────────────
def verify(prefs_dir):
"""Verify Synapse installation integrity."""
print(f"\nVerifying Synapse installation")
print(f" Target: {prefs_dir}\n")
ok_count = 0
fail_count = 0
# Core files
print("--- Core Files ---")
for key, rel_target in _TARGETS.items():
path = os.path.join(prefs_dir, rel_target)
if os.path.exists(path):
size = os.path.getsize(path)
print(f" OK {rel_target} ({size} bytes)")
ok_count += 1
else:
print(f" MISS {rel_target}")
fail_count += 1
# Icons
print("\n--- Icons ---")
icons_dir = os.path.join(prefs_dir, "config", "Icons")
expected_icons = ["synapse", "inspect", "execute", "verify", "document", "profile"]
for icon_name in expected_icons:
path = os.path.join(icons_dir, f"{_ICON_NAMESPACE}_{icon_name}.svg")
if os.path.exists(path):
print(f" OK {_ICON_NAMESPACE}_{icon_name}.svg")
ok_count += 1
else:
print(f" MISS {_ICON_NAMESPACE}_{icon_name}.svg")
fail_count += 1
# Python importability
print("\n--- Import Check ---")
scripts_python = os.path.join(prefs_dir, "scripts", "python")
if scripts_python not in sys.path:
sys.path.insert(0, scripts_python)
for module_name in ["tokens", "synapse_styles", "synapse_shelf"]:
try:
__import__(module_name)
print(f" OK import {module_name}")
ok_count += 1
except Exception as e:
print(f" FAIL import {module_name}: {e}")
fail_count += 1
# Shelf XML validity
print("\n--- Shelf Validation ---")
shelf_path = os.path.join(prefs_dir, "toolbar", "synapse.shelf")
if os.path.exists(shelf_path):
try:
import xml.etree.ElementTree as ET
tree = ET.parse(shelf_path)
root = tree.getroot()
tools = root.findall(".//tool")
print(f" OK synapse.shelf ({len(tools)} tools)")
ok_count += 1
except Exception as e:
print(f" FAIL synapse.shelf: {e}")
fail_count += 1
else:
print(f" MISS synapse.shelf")
fail_count += 1
# Summary
total = ok_count + fail_count
print(f"\n--- Summary ---")
print(f" Passed: {ok_count}/{total}")
if fail_count:
print(f" Failed: {fail_count}/{total}")
print(f"\n Run 'python install.py' to fix missing files.")
else:
print(f" Installation looks good.")
return fail_count == 0
# ── CLI ───────────────────────────────────────────────────
def main():
parser = argparse.ArgumentParser(
description="Synapse Design System Installer",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog=(
"Examples:\n"
" python install.py Install to auto-detected Houdini prefs\n"
" python install.py --dry-run Show what would be installed\n"
" python install.py --verify Check existing installation\n"
" python install.py --uninstall Remove Synapse files\n"
" python install.py --houdini-prefs PATH Override prefs directory\n"
),
)
parser.add_argument("--verify", action="store_true", help="Verify installation")
parser.add_argument("--uninstall", action="store_true", help="Remove Synapse files")
parser.add_argument("--dry-run", action="store_true", help="Show what would be done")
parser.add_argument("--houdini-prefs", type=str, help="Override Houdini prefs directory")
args = parser.parse_args()
# Detect or use provided prefs directory
prefs_dir = args.houdini_prefs or _detect_houdini_prefs()
if prefs_dir is None:
print("Couldn't find Houdini preferences directory.")
print("\nTry one of:")
print(" python install.py --houdini-prefs /path/to/houdiniXX.X")
print(" Set HOUDINI_USER_PREF_DIR environment variable")
sys.exit(1)
print(f"Houdini prefs: {prefs_dir}")
if not os.path.isdir(prefs_dir):
print(f"Directory doesn't exist: {prefs_dir}")
sys.exit(1)
if args.verify:
success = verify(prefs_dir)
sys.exit(0 if success else 1)
elif args.uninstall:
uninstall(prefs_dir, dry_run=args.dry_run)
else:
install(prefs_dir, dry_run=args.dry_run)
if __name__ == "__main__":
main()