magmascript 4.0.1__tar.gz → 4.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. {magmascript-4.0.1 → magmascript-4.2.0}/PKG-INFO +2 -2
  2. {magmascript-4.0.1 → magmascript-4.2.0}/README.md +1 -1
  3. magmascript-4.2.0/magmascript/_cli/__init__.py +4 -0
  4. magmascript-4.2.0/magmascript/_cli/catalog.py +276 -0
  5. magmascript-4.2.0/magmascript/_cli/machines.py +232 -0
  6. magmascript-4.2.0/magmascript/_cli/mcp.py +290 -0
  7. magmascript-4.2.0/magmascript/_cli/pipelines.py +231 -0
  8. magmascript-4.2.0/magmascript/_cli/scripts.py +127 -0
  9. magmascript-4.2.0/magmascript/_cli/services.py +333 -0
  10. magmascript-4.2.0/magmascript/_cli/usage.py +152 -0
  11. magmascript-4.2.0/magmascript/cli.py +357 -0
  12. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/core/github.py +0 -1
  13. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/core/output.py +6 -0
  14. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/domains/gh/client.py +30 -5
  15. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/domains/gh/tools.py +42 -0
  16. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/domains/mb/client.py +0 -50
  17. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/domains/mc1/client.py +41 -0
  18. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/domains/mc1/tools.py +117 -0
  19. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/domains/mcp/client.py +1 -1
  20. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/domains/mcp/tools.py +2 -2
  21. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/domains/pi/client.py +6 -5
  22. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/domains/pi/tools.py +9 -2
  23. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/domains/search/client.py +0 -4
  24. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript.egg-info/PKG-INFO +2 -2
  25. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript.egg-info/SOURCES.txt +10 -0
  26. {magmascript-4.0.1 → magmascript-4.2.0}/pyproject.toml +1 -1
  27. magmascript-4.2.0/tests/test_gh_runners.py +88 -0
  28. {magmascript-4.0.1 → magmascript-4.2.0}/tests/test_mc1.py +74 -0
  29. magmascript-4.2.0/tests/test_pi.py +77 -0
  30. magmascript-4.0.1/magmascript/cli.py +0 -1879
  31. {magmascript-4.0.1 → magmascript-4.2.0}/LICENSE +0 -0
  32. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/__init__.py +0 -0
  33. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/codegen/__init__.py +0 -0
  34. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/codegen/c.py +0 -0
  35. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/core/__init__.py +0 -0
  36. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/core/cache.py +0 -0
  37. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/core/command_registry.py +0 -0
  38. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/core/commands.py +0 -0
  39. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/core/config.py +0 -0
  40. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/core/exceptions.py +0 -0
  41. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/core/registry.py +0 -0
  42. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/core/rpc.py +0 -0
  43. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/core/runner.py +0 -0
  44. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/domains/__init__.py +0 -0
  45. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/domains/archive/__init__.py +0 -0
  46. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/domains/archive/client.py +0 -0
  47. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/domains/gh/__init__.py +0 -0
  48. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/domains/lastfm/__init__.py +0 -0
  49. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/domains/lastfm/client.py +0 -0
  50. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/domains/mac/__init__.py +0 -0
  51. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/domains/mac/client.py +0 -0
  52. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/domains/mac/tools.py +0 -0
  53. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/domains/mb/__init__.py +0 -0
  54. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/domains/mc1/__init__.py +0 -0
  55. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/domains/mcp/__init__.py +0 -0
  56. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/domains/media/__init__.py +0 -0
  57. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/domains/media/client.py +0 -0
  58. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/domains/media/providers/__init__.py +0 -0
  59. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/domains/media/providers/archive.py +0 -0
  60. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/domains/media/providers/met_museum.py +0 -0
  61. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/domains/media/providers/openverse.py +0 -0
  62. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/domains/media/providers/pexels.py +0 -0
  63. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/domains/media/providers/pixabay.py +0 -0
  64. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/domains/media/providers/smithsonian.py +0 -0
  65. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/domains/media/tools.py +0 -0
  66. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/domains/pi/__init__.py +0 -0
  67. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/domains/rights/__init__.py +0 -0
  68. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/domains/rights/client.py +0 -0
  69. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/domains/rights/tools.py +0 -0
  70. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/domains/scores/__init__.py +0 -0
  71. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/domains/scores/client.py +0 -0
  72. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/domains/scores/tools.py +0 -0
  73. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/domains/search/__init__.py +0 -0
  74. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/lang/__init__.py +0 -0
  75. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/lang/ast_nodes.py +0 -0
  76. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/lang/astheno/__init__.py +0 -0
  77. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/lang/astheno/arena.py +0 -0
  78. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/lang/astheno/dump.py +0 -0
  79. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/lang/astheno/floorplan.py +0 -0
  80. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/lang/astheno/numeric.py +0 -0
  81. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/lang/builtins.py +0 -0
  82. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/lang/domain_bridge.py +0 -0
  83. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/lang/environment.py +0 -0
  84. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/lang/hypnagogia.py +0 -0
  85. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/lang/interpreter.py +0 -0
  86. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/lang/lexer.py +0 -0
  87. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/lang/parser.py +0 -0
  88. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/lang/pretty.py +0 -0
  89. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/lang/pygments_mgs.py +0 -0
  90. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/lang/tokens.py +0 -0
  91. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/lang/util.py +0 -0
  92. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/lang/visitor.py +0 -0
  93. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/repl.py +0 -0
  94. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript/scaffold/__init__.py +0 -0
  95. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript.egg-info/dependency_links.txt +0 -0
  96. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript.egg-info/entry_points.txt +0 -0
  97. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript.egg-info/requires.txt +0 -0
  98. {magmascript-4.0.1 → magmascript-4.2.0}/magmascript.egg-info/top_level.txt +0 -0
  99. {magmascript-4.0.1 → magmascript-4.2.0}/setup.cfg +0 -0
  100. {magmascript-4.0.1 → magmascript-4.2.0}/tests/test_astheno.py +0 -0
  101. {magmascript-4.0.1 → magmascript-4.2.0}/tests/test_cache.py +0 -0
  102. {magmascript-4.0.1 → magmascript-4.2.0}/tests/test_classes.py +0 -0
  103. {magmascript-4.0.1 → magmascript-4.2.0}/tests/test_cli.py +0 -0
  104. {magmascript-4.0.1 → magmascript-4.2.0}/tests/test_cli_regressions.py +0 -0
  105. {magmascript-4.0.1 → magmascript-4.2.0}/tests/test_commands.py +0 -0
  106. {magmascript-4.0.1 → magmascript-4.2.0}/tests/test_domain_bridge.py +0 -0
  107. {magmascript-4.0.1 → magmascript-4.2.0}/tests/test_import.py +0 -0
  108. {magmascript-4.0.1 → magmascript-4.2.0}/tests/test_lang.py +0 -0
  109. {magmascript-4.0.1 → magmascript-4.2.0}/tests/test_mac.py +0 -0
  110. {magmascript-4.0.1 → magmascript-4.2.0}/tests/test_mcp_client.py +0 -0
  111. {magmascript-4.0.1 → magmascript-4.2.0}/tests/test_rpc.py +0 -0
  112. {magmascript-4.0.1 → magmascript-4.2.0}/tests/test_try_catch.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: magmascript
3
- Version: 4.0.1
3
+ Version: 4.2.0
4
4
  Summary: Scripting toolkit with domain-first subcommands
5
5
  Author: Jake McCoy
6
6
  License-Expression: MIT
@@ -465,7 +465,7 @@ magmascript mcp mb-recording <mbid> # get recording details
465
465
  magmascript pi status # all service statuses
466
466
  magmascript pi logs arcade-chat # service logs
467
467
  magmascript pi restart arcade-chat # restart service
468
- magmascript pi info # uptime, memory, temp
468
+ magmascript pi info # uptime, memory, temp, disk
469
469
  magmascript pi deploy arcade/chat-server.py # deploy files
470
470
  magmascript pi backup musicbrainz # backup + commit to GitHub
471
471
  magmascript pi traffic # nginx traffic analysis
@@ -430,7 +430,7 @@ magmascript mcp mb-recording <mbid> # get recording details
430
430
  magmascript pi status # all service statuses
431
431
  magmascript pi logs arcade-chat # service logs
432
432
  magmascript pi restart arcade-chat # restart service
433
- magmascript pi info # uptime, memory, temp
433
+ magmascript pi info # uptime, memory, temp, disk
434
434
  magmascript pi deploy arcade/chat-server.py # deploy files
435
435
  magmascript pi backup musicbrainz # backup + commit to GitHub
436
436
  magmascript pi traffic # nginx traffic analysis
@@ -0,0 +1,4 @@
1
+ """The subcommand handlers behind magmascript.cli, one module per group.
2
+
3
+ Private: import from magmascript.cli, which re-exports every name here.
4
+ """
@@ -0,0 +1,276 @@
1
+ """`rights`, `archive`, `mb`, `lastfm` and `search`: the music catalogue data."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ import sys
7
+
8
+ from magmascript.core.output import format_output
9
+
10
+
11
+ def _dispatch_rights(action: str, args: list[str], client, fmt: str):
12
+ """Dispatch music rights subcommands."""
13
+ if not action or action == "--help":
14
+ print("""Music rights metadata (ISRC, ISWC, ASCAP).
15
+
16
+ Usage:
17
+ magmascript rights search <query> Search by title, ISRC, ISWC, or ASCAP ID
18
+ magmascript rights isrc <code> Look up recording by ISRC
19
+ magmascript rights iswc <code> Look up work by ISWC
20
+ magmascript rights ascap <id> Look up work by ASCAP ID
21
+ magmascript rights catalog <artist> Full rights catalog for an artist
22
+ magmascript rights recording <uuid> Rights data for a recording
23
+ magmascript rights work <uuid> Rights data for a work
24
+ magmascript rights export TSV export of all rights data
25
+
26
+ Options:
27
+ --artist <name> Filter search by artist name
28
+ """)
29
+ sys.exit(0)
30
+
31
+ if action == "search":
32
+ if not args:
33
+ print("Usage: rights search <query> [--artist <name>]", file=sys.stderr)
34
+ sys.exit(1)
35
+ query = args[0]
36
+ artist = ""
37
+ if "--artist" in args:
38
+ idx = args.index("--artist")
39
+ if idx + 1 < len(args):
40
+ artist = args[idx + 1]
41
+ else:
42
+ print("Usage: rights search <query> --artist <name>", file=sys.stderr)
43
+ sys.exit(1)
44
+ results = client.search(query, artist=artist)
45
+ print(format_output(results, fmt))
46
+
47
+ elif action == "isrc":
48
+ if not args:
49
+ print("Usage: rights isrc <code>", file=sys.stderr)
50
+ sys.exit(1)
51
+ result = client.isrc(args[0])
52
+ if result:
53
+ print(format_output(result, fmt))
54
+ else:
55
+ print(f"No recording found with ISRC: {args[0]}")
56
+ sys.exit(1)
57
+
58
+ elif action == "iswc":
59
+ if not args:
60
+ print("Usage: rights iswc <code>", file=sys.stderr)
61
+ sys.exit(1)
62
+ result = client.iswc(args[0])
63
+ if result:
64
+ print(format_output(result, fmt))
65
+ else:
66
+ print(f"No work found with ISWC: {args[0]}")
67
+ sys.exit(1)
68
+
69
+ elif action == "ascap":
70
+ if not args:
71
+ print("Usage: rights ascap <id>", file=sys.stderr)
72
+ sys.exit(1)
73
+ result = client.ascap(args[0])
74
+ if result:
75
+ print(format_output(result, fmt))
76
+ else:
77
+ print(f"No work found with ASCAP ID: {args[0]}")
78
+ sys.exit(1)
79
+
80
+ elif action == "catalog":
81
+ if not args:
82
+ print("Usage: rights catalog <artist>", file=sys.stderr)
83
+ sys.exit(1)
84
+ result = client.catalog(args[0])
85
+ print(format_output(result, fmt))
86
+
87
+ elif action == "recording":
88
+ if not args:
89
+ print("Usage: rights recording <uuid>", file=sys.stderr)
90
+ sys.exit(1)
91
+ result = client.recording(args[0])
92
+ print(format_output(result, fmt))
93
+
94
+ elif action == "work":
95
+ if not args:
96
+ print("Usage: rights work <uuid>", file=sys.stderr)
97
+ sys.exit(1)
98
+ result = client.work(args[0])
99
+ print(format_output(result, fmt))
100
+
101
+ elif action == "export":
102
+ results = client.export()
103
+ if fmt == "json":
104
+ print(format_output(results, fmt))
105
+ else:
106
+ # TSV format
107
+ print("Title\tType\tArtist/Composer\tISRC\tISWC\tASCAP ID")
108
+ for row in results:
109
+ print(f"{row.title}\t{row.type}\t{row.artist_composer}\t{row.isrc}\t{row.iswc}\t{row.ascap_id}")
110
+
111
+ else:
112
+ print(f"Unknown rights action: {action!r}", file=sys.stderr)
113
+ print("Run 'magmascript rights --help' for available actions.", file=sys.stderr)
114
+ sys.exit(1)
115
+
116
+
117
+ def _dispatch_archive(action: str, args: list[str], client, fmt: str):
118
+ """Dispatch Archive subcommands."""
119
+ if not action or action == "--help":
120
+ print("""Archive page operations.
121
+
122
+ Usage:
123
+ magmascript archive check-format Validate archive HTML formatting
124
+ magmascript archive generate-stubs Generate stub HTML for new archive entities
125
+ """)
126
+ sys.exit(0)
127
+
128
+ if action == "check-format":
129
+ warnings = client.check_format()
130
+ if fmt == "json":
131
+ print(json.dumps([{"file": w.file, "line": w.line, "msg": w.msg} for w in warnings], indent=2))
132
+ else:
133
+ if not warnings:
134
+ print("all checks passed")
135
+ else:
136
+ for w in warnings:
137
+ print(f"\nWARN {w.file}:{w.line}")
138
+ print(f" {w.msg}")
139
+ print(f"\n{len(warnings)} warning{'s' if len(warnings) != 1 else ''} found")
140
+ if warnings:
141
+ sys.exit(1)
142
+
143
+ elif action == "generate-stubs":
144
+ result = client.generate_stubs()
145
+ if fmt == "json":
146
+ print(json.dumps(result, indent=2))
147
+ else:
148
+ print(f"Generated {result['generated']} stubs, skipped {result['skipped']}")
149
+
150
+ else:
151
+ print(f"Unknown archive action: {action!r}", file=sys.stderr)
152
+ print("Run 'magmascript archive --help' for available actions.", file=sys.stderr)
153
+ sys.exit(1)
154
+
155
+
156
+ def _dispatch_mb(action: str, args: list[str], client, fmt: str):
157
+ """Dispatch MusicBrainz subcommands."""
158
+ if not action or action == "--help":
159
+ print("""MusicBrainz API client.
160
+
161
+ Usage:
162
+ magmascript mb backup Run full MusicBrainz backup
163
+ magmascript mb backup --dry-run Preview backup without writing files
164
+ magmascript mb backup --skip-existing Skip already-cached entities
165
+ magmascript mb backup --stale-only Only refresh stale caches
166
+ """)
167
+ sys.exit(0)
168
+
169
+ if action == "backup":
170
+ dry_run = "--dry-run" in args
171
+ skip_existing = "--skip-existing" in args
172
+ stale_only = "--stale-only" in args
173
+
174
+ result = client.backup(
175
+ dry_run=dry_run,
176
+ skip_existing=skip_existing,
177
+ stale_only=stale_only,
178
+ )
179
+
180
+ if fmt == "json":
181
+ print(json.dumps({
182
+ "completed": result.completed,
183
+ "skipped": result.skipped,
184
+ "elapsed_seconds": result.elapsed_seconds,
185
+ "errors": result.errors,
186
+ }, indent=2))
187
+ elif result.errors:
188
+ print(f"\nErrors ({len(result.errors)}):")
189
+ for err in result.errors:
190
+ print(f" {err}")
191
+
192
+ else:
193
+ print(f"Unknown mb action: {action!r}", file=sys.stderr)
194
+ print("Run 'magmascript mb --help' for available actions.", file=sys.stderr)
195
+ sys.exit(1)
196
+
197
+
198
+ def _dispatch_lastfm(action: str, args: list[str], client, fmt: str):
199
+ """Dispatch Last.fm subcommands."""
200
+ if not action or action == "--help":
201
+ print("""Last.fm API client.
202
+
203
+ Usage:
204
+ magmascript lastfm fetch Fetch play counts for all artists
205
+ magmascript lastfm fetch --dry-run Preview fetch without writing files
206
+ magmascript lastfm fetch --skip-existing Skip already-cached artists
207
+ """)
208
+ sys.exit(0)
209
+
210
+ if action == "fetch":
211
+ dry_run = "--dry-run" in args
212
+ skip_existing = "--skip-existing" in args
213
+
214
+ result = client.fetch(
215
+ dry_run=dry_run,
216
+ skip_existing=skip_existing,
217
+ )
218
+
219
+ if fmt == "json":
220
+ print(json.dumps({
221
+ "completed": result.completed,
222
+ "skipped": result.skipped,
223
+ "resolved": result.resolved,
224
+ "errors": result.errors,
225
+ }, indent=2))
226
+ elif result.errors:
227
+ print(f"\nErrors ({len(result.errors)}):")
228
+ for err in result.errors:
229
+ print(f" {err}")
230
+
231
+ else:
232
+ print(f"Unknown lastfm action: {action!r}", file=sys.stderr)
233
+ print("Run 'magmascript lastfm --help' for available actions.", file=sys.stderr)
234
+ sys.exit(1)
235
+
236
+
237
+ def _dispatch_search(action: str, args: list[str], client, fmt: str):
238
+ """Dispatch Search subcommands."""
239
+ if not action or action == "--help":
240
+ print("""Site search index builder.
241
+
242
+ Usage:
243
+ magmascript search build-index Build search index (search-index.json)
244
+ magmascript search preview [limit] Preview search index entries
245
+ """)
246
+ sys.exit(0)
247
+
248
+ if action == "build-index":
249
+ result = client.build()
250
+ if fmt == "json":
251
+ print(json.dumps({
252
+ "total_entries": result.total_entries,
253
+ "deduplicated": result.deduplicated,
254
+ "output_file": result.output_file,
255
+ }, indent=2))
256
+ else:
257
+ print(f"Built search index: {result.deduplicated} entries ({result.total_entries} total) → {result.output_file}")
258
+
259
+ elif action == "preview":
260
+ limit = int(args[0]) if args else 10
261
+ entries = client.preview(limit=limit)
262
+ if fmt == "json":
263
+ print(json.dumps([{"t": e.t, "c": e.c, "u": e.u, "d": e.d} for e in entries], indent=2))
264
+ else:
265
+ print(f"Preview ({len(entries)} entries):\n")
266
+ for e in entries:
267
+ print(f" [{e.c}] {e.t}")
268
+ print(f" {e.u}")
269
+ if e.d:
270
+ print(f" {e.d}")
271
+ print()
272
+
273
+ else:
274
+ print(f"Unknown search action: {action!r}", file=sys.stderr)
275
+ print("Run 'magmascript search --help' for available actions.", file=sys.stderr)
276
+ sys.exit(1)
@@ -0,0 +1,232 @@
1
+ """`mc1`, `mac` and `pi`: the machines, over direct SSH."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import sys
6
+
7
+ from magmascript._cli.usage import usage
8
+ from magmascript.core.output import format_output
9
+
10
+
11
+ def _dispatch_mc1(action: str, args: list[str], client, fmt: str):
12
+ """Dispatch MC1 (Windows PC) subcommands."""
13
+ if not action or action == "--help":
14
+ usage()
15
+
16
+ if action == "status":
17
+ print(format_output(client.services(), fmt))
18
+
19
+ elif action == "info":
20
+ print(format_output(client.info(), fmt))
21
+
22
+ elif action == "processes":
23
+ print(client.processes())
24
+
25
+ elif action == "memory":
26
+ from magmascript.domains.mc1.tools import format_memory
27
+
28
+ mem = client.memory()
29
+ if fmt == "json":
30
+ from dataclasses import asdict
31
+ import json
32
+
33
+ out = asdict(mem)
34
+ out["commit_headroom_gb"] = mem.commit_headroom_gb
35
+ out["low"] = mem.low
36
+ print(json.dumps(out, indent=2))
37
+ else:
38
+ print(format_memory(mem))
39
+
40
+ elif action == "restart":
41
+ if not args:
42
+ print("Usage: mc1 restart <service>", file=sys.stderr)
43
+ sys.exit(1)
44
+ print(client.restart(args[0]))
45
+
46
+ elif action == "power":
47
+ print(format_output(client.get_power_settings(), fmt))
48
+
49
+ elif action == "set-power-mode":
50
+ if not args or args[0] not in ("always-on", "sleep"):
51
+ print("Usage: mc1 set-power-mode <always-on|sleep>", file=sys.stderr)
52
+ sys.exit(1)
53
+ print(client.set_power_mode(args[0]))
54
+
55
+ elif action == "wake":
56
+ if not args:
57
+ print("Usage: mc1 wake <mac-address>", file=sys.stderr)
58
+ sys.exit(1)
59
+ print(client.wake_on_lan(args[0]))
60
+
61
+ elif action == "reboot":
62
+ print(client.reboot())
63
+
64
+ else:
65
+ print(f"Unknown mc1 action: {action!r}", file=sys.stderr)
66
+ print(
67
+ "Actions: status, info, processes, memory, restart, power, "
68
+ "set-power-mode, wake, reboot",
69
+ file=sys.stderr,
70
+ )
71
+ sys.exit(1)
72
+
73
+
74
+ def _dispatch_mac(action: str, args: list[str], client, fmt: str):
75
+ """Dispatch Mac subcommands."""
76
+ if not action or action == "--help":
77
+ usage()
78
+
79
+ if action == "info":
80
+ print(format_output(client.info(), fmt))
81
+
82
+ elif action == "processes":
83
+ limit = int(args[0]) if args else 15
84
+ print(format_output(client.processes(limit), fmt))
85
+
86
+ elif action == "git-status":
87
+ repo = args[0] if args else "~/Documents/magmascript"
88
+ print(client.git_status(repo))
89
+
90
+ elif action == "git-pull":
91
+ repo = args[0] if args else "~/Documents/magmascript"
92
+ print(client.git_pull(repo))
93
+
94
+ elif action == "run":
95
+ if not args:
96
+ print("Usage: mac run <command>", file=sys.stderr)
97
+ sys.exit(1)
98
+ print(client.run(" ".join(args), timeout=30))
99
+
100
+ else:
101
+ print(f"Unknown mac action: {action!r}", file=sys.stderr)
102
+ print("Actions: info, processes, git-status, git-pull, run", file=sys.stderr)
103
+ sys.exit(1)
104
+
105
+
106
+ def _dispatch_pi(action: str, args: list[str], client, fmt: str):
107
+ """Dispatch Pi subcommands."""
108
+ if not action or action == "--help":
109
+ usage()
110
+
111
+ if action == "status":
112
+ results = client.services()
113
+ print(format_output(results, fmt))
114
+
115
+ elif action == "logs":
116
+ if not args:
117
+ print("Usage: pi logs <service> [lines]", file=sys.stderr)
118
+ sys.exit(1)
119
+ lines = int(args[1]) if len(args) > 1 else 50
120
+ result = client.logs(args[0], lines)
121
+ print(result)
122
+
123
+ elif action == "logs-errors":
124
+ lines = int(args[0]) if args else 100
125
+ result = client.logs_errors(lines)
126
+ print(result)
127
+
128
+ elif action == "logs-today":
129
+ result = client.logs_today()
130
+ print(result)
131
+
132
+ elif action == "restart":
133
+ if not args:
134
+ print("Usage: pi restart <service>", file=sys.stderr)
135
+ sys.exit(1)
136
+ result = client.restart(args[0])
137
+ print(result)
138
+
139
+ elif action == "restart-all":
140
+ result = client.restart_all()
141
+ print(result)
142
+
143
+ elif action == "info":
144
+ result = client.info()
145
+ print(format_output(result, fmt))
146
+
147
+ elif action == "traffic":
148
+ lines = int(args[0]) if args else 1000
149
+ result = client.traffic(lines)
150
+ print(f"=== Top IPs ===\n{result.top_ips}")
151
+ print(f"\n=== Status Codes ===\n{result.status_codes}")
152
+ print(f"\n=== User Agents ===\n{result.user_agents}")
153
+ print(f"\n=== Total Requests ===\n{result.total_requests}")
154
+
155
+ elif action == "deploy":
156
+ if not args:
157
+ print("Usage: pi deploy <path> [service]", file=sys.stderr)
158
+ sys.exit(1)
159
+ service = args[1] if len(args) > 1 else ""
160
+ result = client.deploy(args[0], service)
161
+ print(result)
162
+
163
+ elif action == "reboot":
164
+ result = client.reboot()
165
+ print(result)
166
+
167
+ elif action == "shutdown":
168
+ result = client.shutdown()
169
+ print(result)
170
+
171
+ elif action == "backup":
172
+ if not args or args[0] != "musicbrainz":
173
+ print("Usage: pi backup musicbrainz", file=sys.stderr)
174
+ sys.exit(1)
175
+ backup_type = args[0]
176
+ message = ""
177
+ if "--message" in args:
178
+ idx = args.index("--message")
179
+ if idx + 1 < len(args):
180
+ message = args[idx + 1]
181
+
182
+ print(f"Running {backup_type} backup on Pi...")
183
+ result = client.run_backup(backup_type, timeout=600)
184
+ print(result)
185
+
186
+ # Pull changed files from Pi and commit
187
+ from magmascript.core.config import get_config
188
+ config = get_config()
189
+ pi_host = config.pi.host
190
+ pi_user = config.pi.user
191
+
192
+ print("Pulling cache from Pi...")
193
+ import subprocess
194
+ subprocess.run(
195
+ ["rsync", "-avz",
196
+ f"{pi_user}@{pi_host}:~/website/archive/_cache/", "archive/_cache/"],
197
+ capture_output=True, text=True, timeout=60,
198
+ )
199
+
200
+ # Check for changes
201
+ git_result = subprocess.run(
202
+ ["git", "diff", "--name-only", "archive/_cache/"],
203
+ capture_output=True, text=True, timeout=10,
204
+ )
205
+ changed = [f for f in git_result.stdout.strip().splitlines() if f]
206
+
207
+ if not changed:
208
+ print("No cache files changed.")
209
+ return
210
+
211
+ print(f"Found {len(changed)} changed file(s). Committing...")
212
+ from magmascript.domains.gh import GHClient
213
+ gh = GHClient(config)
214
+ try:
215
+ files = []
216
+ for path in changed:
217
+ try:
218
+ with open(path) as f:
219
+ files.append({"path": path, "content": f.read()})
220
+ except Exception:
221
+ continue
222
+ if files:
223
+ msg = message or f"Update {backup_type} cache via magmascript"
224
+ result = gh.commit_multiple(files, msg)
225
+ print(result)
226
+ finally:
227
+ gh.close()
228
+
229
+ else:
230
+ print(f"Unknown Pi action: {action!r}", file=sys.stderr)
231
+ print("Run 'magmascript pi --help' for available actions.", file=sys.stderr)
232
+ sys.exit(1)