xy-forever 0.1.0.dev135__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 (30) hide show
  1. xy_forever-0.1.0.dev135/LICENSE +21 -0
  2. xy_forever-0.1.0.dev135/PKG-INFO +117 -0
  3. xy_forever-0.1.0.dev135/README.md +95 -0
  4. xy_forever-0.1.0.dev135/pyproject.toml +75 -0
  5. xy_forever-0.1.0.dev135/xy_forever/__init__.py +10 -0
  6. xy_forever-0.1.0.dev135/xy_forever/bounds.py +14 -0
  7. xy_forever-0.1.0.dev135/xy_forever/depth.py +72 -0
  8. xy_forever-0.1.0.dev135/xy_forever/dev_entry.py +323 -0
  9. xy_forever-0.1.0.dev135/xy_forever/device_client.py +385 -0
  10. xy_forever-0.1.0.dev135/xy_forever/device_lock.py +145 -0
  11. xy_forever-0.1.0.dev135/xy_forever/host_trust.py +58 -0
  12. xy_forever-0.1.0.dev135/xy_forever/host_write.py +81 -0
  13. xy_forever-0.1.0.dev135/xy_forever/ldr.py +119 -0
  14. xy_forever-0.1.0.dev135/xy_forever/modconfig.py +143 -0
  15. xy_forever-0.1.0.dev135/xy_forever/moddev.py +329 -0
  16. xy_forever-0.1.0.dev135/xy_forever/modsend.py +668 -0
  17. xy_forever-0.1.0.dev135/xy_forever/modsend_local.py +64 -0
  18. xy_forever-0.1.0.dev135/xy_forever/modstore.py +94 -0
  19. xy_forever-0.1.0.dev135/xy_forever/mtp_read.py +311 -0
  20. xy_forever-0.1.0.dev135/xy_forever/native_json.py +244 -0
  21. xy_forever-0.1.0.dev135/xy_forever/no_device.py +42 -0
  22. xy_forever-0.1.0.dev135/xy_forever/package_records.py +73 -0
  23. xy_forever-0.1.0.dev135/xy_forever/package_store.py +298 -0
  24. xy_forever-0.1.0.dev135/xy_forever/paths.py +195 -0
  25. xy_forever-0.1.0.dev135/xy_forever/startup_ready.py +35 -0
  26. xy_forever-0.1.0.dev135/xy_forever/transport.py +315 -0
  27. xy_forever-0.1.0.dev135/xy_forever/usb_proto.py +246 -0
  28. xy_forever-0.1.0.dev135/xy_forever/usb_proto_ids.py +437 -0
  29. xy_forever-0.1.0.dev135/xy_forever/xyf.py +407 -0
  30. xy_forever-0.1.0.dev135/xy_forever/xyf_entry.py +344 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 XY Forever contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,117 @@
1
+ Metadata-Version: 2.5
2
+ Name: xy-forever
3
+ Version: 0.1.0.dev135
4
+ Summary: Boot your Open-XY build once on an OP-XY running XY Forever: xyf stock-os, xyf dev, xyf logs
5
+ Project-URL: Homepage, https://xy-forever.trappar.com
6
+ Project-URL: Source, https://github.com/trappar/xy-forever
7
+ Project-URL: Issues, https://github.com/trappar/xy-forever/issues
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Keywords: mods,op-xy,open-xy,teenage engineering,xy-forever
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Operating System :: MacOS
15
+ Classifier: Operating System :: Microsoft :: Windows
16
+ Classifier: Operating System :: POSIX :: Linux
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Topic :: Multimedia :: Sound/Audio
19
+ Requires-Python: >=3.11
20
+ Requires-Dist: pyserial>=3.5
21
+ Description-Content-Type: text/markdown
22
+
23
+ # xy-forever
24
+
25
+ Boot your [Open-XY](https://github.com/etcetc000/open-xy) build, or any other full firmware image, on an OP-XY running
26
+ [XY Forever](https://xy-forever.trappar.com), without cloning XY Forever. `xyf` checks the image as XY Forever checks
27
+ the firmware in its library, puts it on the OP-XY with its content (if it has any) and boots it once. Your own setup
28
+ stays as it is: the next plain start goes back to it, and holding PLAY at power-on always opens the XY Forever menu.
29
+
30
+ ## Needs
31
+
32
+ - An OP-XY running XY Forever with protocol 1.31 or later (update at https://xy-forever.trappar.com, Manage → Device
33
+ → Update), connected over USB.
34
+ - macOS, Linux or Windows, and Python 3.11 or later in a virtual environment (a stock Mac has only `python3` 3.9 and
35
+ no `python`; [uv](https://docs.astral.sh/uv/) brings its own Python).
36
+ - An Open-XY checkout with its toolchain (`python sdk.py toolchain fetch`) and your machine (`python sdk.py new`).
37
+ Open-XY's `sdk.py` runs in the same environment.
38
+
39
+ ## Install
40
+
41
+ In your Open-XY checkout:
42
+
43
+ ```sh
44
+ uv venv --python 3.12 .venv && source .venv/bin/activate # or: python3.11 -m venv .venv (Windows: .venv\Scripts\activate)
45
+ uv pip install xy-forever # with python3.11 -m venv: pip install xy-forever; the command is xyf
46
+ ```
47
+
48
+ Or without installing: `uvx xy-forever dev BUILD` (or `pipx run xy-forever …`) runs `xyf` as `xy-forever`.
49
+
50
+ ## The loop
51
+
52
+ In the checkout, with that environment active:
53
+
54
+ ```sh
55
+ xyf stock-os # once: prints "xyf stock-os: STOCK (2373336 bytes, SHA-256 checked, ...)"
56
+ python sdk.py build --machine ../mymachine --stock-os "STOCK" --out ../builds/mine-001
57
+ xyf dev ../builds/mine-001
58
+ ```
59
+
60
+ `STOCK` is the path `xyf stock-os` printed: the os.ldr itself, under Open-XY's private folder
61
+ (`~/Library/Application Support/OPXY-SDK/private/stock-1.2.1/os.ldr` on macOS, the same under `~/.local/share/` on
62
+ Linux and `%LOCALAPPDATA%` on Windows); quote it. After an edit, build into a new folder with the last build's machine
63
+ numbers, as Open-XY's build asks: `python sdk.py build --machine ../mymachine --stock-os "STOCK" --layout
64
+ ../builds/mine-001/layout.json --out ../builds/mine-002`, then `xyf dev ../builds/mine-002`. Or leave `xyf dev --watch
65
+ ../builds` running: it does the same for every new build in that folder.
66
+
67
+ Any other firmware works the same way: `xyf dev FOLDER` (holding `os.ldr`, and optionally `content/` with files to put
68
+ over the official content) or `xyf dev path/to/os.ldr`. The push line says `Open-XY build on 1.2.1` when the image is
69
+ exactly Open-XY's build on the stock OS (checked against the stock os.ldr and your checkout's profile), else `custom
70
+ image`; without content it boots with the official content. `xyf logs` copies the OP-XY's new crash logs and XY
71
+ Forever's reports of the last boot into `./xyf-logs` and prints the text ones.
72
+
73
+ ## For AI agents
74
+
75
+ Run every step in a terminal and read its output; only the power cycle needs the person at the OP-XY.
76
+
77
+ The loop, in the Open-XY checkout with its Python 3.11+ environment active: edit the machine → `python sdk.py build
78
+ --machine M --stock-os "STOCK" --layout LAST/layout.json --out NEW_FOLDER` (no `--layout` the first time) → `xyf dev
79
+ NEW_FOLDER` → if it prints the power line, ask the person to do exactly that → read the result → `xyf logs` when the
80
+ mod misbehaved or crashed. Run `xyf stock-os` once first; `STOCK` is the path it prints. Each command waits up to
81
+ `--wait` (600 s) for the menu: leave it at that, the power cycle takes the person a while.
82
+
83
+ What each line means:
84
+
85
+ | Line | Meaning |
86
+ |---|---|
87
+ | `Power the OP-XY off, then on holding PLAY (let go at the logo)` | The OP-XY is off or running its OS. Ask the person to do this; `xyf` waits (up to `--wait`, 600 s). |
88
+ | `[wait] 12.30 s` | The OP-XY's XY Forever menu answered after that wait. |
89
+ | `[push] 41.20 s: xyf-dev: Open-XY build on 1.2.1, os.ldr 2318 KB, 2 of 2 content files sent` | The build is on the OP-XY as library entry `xyf-dev` (or `custom image`; `the official content` when it has none). |
90
+ | `[content] 43.10 s: recorded the official 1.2.1 content (once)` | Only the first time on an OP-XY that never saved mods: it read its official content (the OP-XY shows "Reading OS 1.2.1 content"). |
91
+ | `[boot] 3.00 s: xyf-dev started once; ...` | Its content is installed and it is starting: try it now. |
92
+ | `total 44.20 s` | The run ended. Exit code 0 only when the build booted. |
93
+
94
+ What to do on each failure (the line starts with `xyf dev:`, `xyf stock-os:` or `xyf logs:`, or a step line says
95
+ `refused` or `failed`):
96
+
97
+ | Output | Do |
98
+ |---|---|
99
+ | `refused: ... holds no candidate/os.ldr or os.ldr` | Give the folder `sdk.py build --out` wrote, or an os.ldr. |
100
+ | `refused: the os.ldr is ...` (not an OS image, its size, where it starts or writes) | XY Forever would not boot it either: fix the build. |
101
+ | `custom image` where you expected `Open-XY build on 1.2.1` | Not an error. Run `xyf stock-os` and run from the Open-XY checkout (or add `--sdk DIR`) so it can be compared. |
102
+ | `the OP-XY speaks XY Forever protocol X; xyf needs Y ... Update XY Forever at ...` | Ask the person to update XY Forever as the line says (or, when it says so, update xyf). |
103
+ | `the XY Forever menu did not answer within N s (--wait)` (or `XY Forever USB service not found ...`) | The menu never answered in time: check the USB cable, ask for the power cycle holding PLAY again and run it again. |
104
+ | `[push] ...: failed: ...` | The OP-XY refused a step of the copy (the reason follows). Run it again; if it repeats, report it. |
105
+ | `[boot] ...: refused: ...` or `the OP-XY stayed in its menu: ...` | The build did not start; the reason follows (a content file that would replace an official one, say). Run `xyf logs`. |
106
+ | `connection lost (...)` | Run the same command again. |
107
+ | `stopped` (exit 130) | Ctrl-C. |
108
+
109
+ If the build crashes the OP-XY or does not start, ask for the power cycle holding PLAY (the XY Forever menu opens,
110
+ whatever was booted), then run `xyf logs` and read what it printed and saved. A plain power-on boots the saved setup
111
+ again.
112
+
113
+ ## Compatibility
114
+
115
+ `xyf` checks the protocol the OP-XY reports when it connects: `xyf dev` needs XY Forever protocol 1.31 or a later 1.x,
116
+ `xyf logs` and `xyf stock-os` 1.5 or later; `xyf --version` says so. The package has its own version numbers, separate from XY Forever's: `pip install
117
+ xy-forever` gets the latest normal version, `pip install --pre xy-forever` also the newest development version.
@@ -0,0 +1,95 @@
1
+ # xy-forever
2
+
3
+ Boot your [Open-XY](https://github.com/etcetc000/open-xy) build, or any other full firmware image, on an OP-XY running
4
+ [XY Forever](https://xy-forever.trappar.com), without cloning XY Forever. `xyf` checks the image as XY Forever checks
5
+ the firmware in its library, puts it on the OP-XY with its content (if it has any) and boots it once. Your own setup
6
+ stays as it is: the next plain start goes back to it, and holding PLAY at power-on always opens the XY Forever menu.
7
+
8
+ ## Needs
9
+
10
+ - An OP-XY running XY Forever with protocol 1.31 or later (update at https://xy-forever.trappar.com, Manage → Device
11
+ → Update), connected over USB.
12
+ - macOS, Linux or Windows, and Python 3.11 or later in a virtual environment (a stock Mac has only `python3` 3.9 and
13
+ no `python`; [uv](https://docs.astral.sh/uv/) brings its own Python).
14
+ - An Open-XY checkout with its toolchain (`python sdk.py toolchain fetch`) and your machine (`python sdk.py new`).
15
+ Open-XY's `sdk.py` runs in the same environment.
16
+
17
+ ## Install
18
+
19
+ In your Open-XY checkout:
20
+
21
+ ```sh
22
+ uv venv --python 3.12 .venv && source .venv/bin/activate # or: python3.11 -m venv .venv (Windows: .venv\Scripts\activate)
23
+ uv pip install xy-forever # with python3.11 -m venv: pip install xy-forever; the command is xyf
24
+ ```
25
+
26
+ Or without installing: `uvx xy-forever dev BUILD` (or `pipx run xy-forever …`) runs `xyf` as `xy-forever`.
27
+
28
+ ## The loop
29
+
30
+ In the checkout, with that environment active:
31
+
32
+ ```sh
33
+ xyf stock-os # once: prints "xyf stock-os: STOCK (2373336 bytes, SHA-256 checked, ...)"
34
+ python sdk.py build --machine ../mymachine --stock-os "STOCK" --out ../builds/mine-001
35
+ xyf dev ../builds/mine-001
36
+ ```
37
+
38
+ `STOCK` is the path `xyf stock-os` printed: the os.ldr itself, under Open-XY's private folder
39
+ (`~/Library/Application Support/OPXY-SDK/private/stock-1.2.1/os.ldr` on macOS, the same under `~/.local/share/` on
40
+ Linux and `%LOCALAPPDATA%` on Windows); quote it. After an edit, build into a new folder with the last build's machine
41
+ numbers, as Open-XY's build asks: `python sdk.py build --machine ../mymachine --stock-os "STOCK" --layout
42
+ ../builds/mine-001/layout.json --out ../builds/mine-002`, then `xyf dev ../builds/mine-002`. Or leave `xyf dev --watch
43
+ ../builds` running: it does the same for every new build in that folder.
44
+
45
+ Any other firmware works the same way: `xyf dev FOLDER` (holding `os.ldr`, and optionally `content/` with files to put
46
+ over the official content) or `xyf dev path/to/os.ldr`. The push line says `Open-XY build on 1.2.1` when the image is
47
+ exactly Open-XY's build on the stock OS (checked against the stock os.ldr and your checkout's profile), else `custom
48
+ image`; without content it boots with the official content. `xyf logs` copies the OP-XY's new crash logs and XY
49
+ Forever's reports of the last boot into `./xyf-logs` and prints the text ones.
50
+
51
+ ## For AI agents
52
+
53
+ Run every step in a terminal and read its output; only the power cycle needs the person at the OP-XY.
54
+
55
+ The loop, in the Open-XY checkout with its Python 3.11+ environment active: edit the machine → `python sdk.py build
56
+ --machine M --stock-os "STOCK" --layout LAST/layout.json --out NEW_FOLDER` (no `--layout` the first time) → `xyf dev
57
+ NEW_FOLDER` → if it prints the power line, ask the person to do exactly that → read the result → `xyf logs` when the
58
+ mod misbehaved or crashed. Run `xyf stock-os` once first; `STOCK` is the path it prints. Each command waits up to
59
+ `--wait` (600 s) for the menu: leave it at that, the power cycle takes the person a while.
60
+
61
+ What each line means:
62
+
63
+ | Line | Meaning |
64
+ |---|---|
65
+ | `Power the OP-XY off, then on holding PLAY (let go at the logo)` | The OP-XY is off or running its OS. Ask the person to do this; `xyf` waits (up to `--wait`, 600 s). |
66
+ | `[wait] 12.30 s` | The OP-XY's XY Forever menu answered after that wait. |
67
+ | `[push] 41.20 s: xyf-dev: Open-XY build on 1.2.1, os.ldr 2318 KB, 2 of 2 content files sent` | The build is on the OP-XY as library entry `xyf-dev` (or `custom image`; `the official content` when it has none). |
68
+ | `[content] 43.10 s: recorded the official 1.2.1 content (once)` | Only the first time on an OP-XY that never saved mods: it read its official content (the OP-XY shows "Reading OS 1.2.1 content"). |
69
+ | `[boot] 3.00 s: xyf-dev started once; ...` | Its content is installed and it is starting: try it now. |
70
+ | `total 44.20 s` | The run ended. Exit code 0 only when the build booted. |
71
+
72
+ What to do on each failure (the line starts with `xyf dev:`, `xyf stock-os:` or `xyf logs:`, or a step line says
73
+ `refused` or `failed`):
74
+
75
+ | Output | Do |
76
+ |---|---|
77
+ | `refused: ... holds no candidate/os.ldr or os.ldr` | Give the folder `sdk.py build --out` wrote, or an os.ldr. |
78
+ | `refused: the os.ldr is ...` (not an OS image, its size, where it starts or writes) | XY Forever would not boot it either: fix the build. |
79
+ | `custom image` where you expected `Open-XY build on 1.2.1` | Not an error. Run `xyf stock-os` and run from the Open-XY checkout (or add `--sdk DIR`) so it can be compared. |
80
+ | `the OP-XY speaks XY Forever protocol X; xyf needs Y ... Update XY Forever at ...` | Ask the person to update XY Forever as the line says (or, when it says so, update xyf). |
81
+ | `the XY Forever menu did not answer within N s (--wait)` (or `XY Forever USB service not found ...`) | The menu never answered in time: check the USB cable, ask for the power cycle holding PLAY again and run it again. |
82
+ | `[push] ...: failed: ...` | The OP-XY refused a step of the copy (the reason follows). Run it again; if it repeats, report it. |
83
+ | `[boot] ...: refused: ...` or `the OP-XY stayed in its menu: ...` | The build did not start; the reason follows (a content file that would replace an official one, say). Run `xyf logs`. |
84
+ | `connection lost (...)` | Run the same command again. |
85
+ | `stopped` (exit 130) | Ctrl-C. |
86
+
87
+ If the build crashes the OP-XY or does not start, ask for the power cycle holding PLAY (the XY Forever menu opens,
88
+ whatever was booted), then run `xyf logs` and read what it printed and saved. A plain power-on boots the saved setup
89
+ again.
90
+
91
+ ## Compatibility
92
+
93
+ `xyf` checks the protocol the OP-XY reports when it connects: `xyf dev` needs XY Forever protocol 1.31 or a later 1.x,
94
+ `xyf logs` and `xyf stock-os` 1.5 or later; `xyf --version` says so. The package has its own version numbers, separate from XY Forever's: `pip install
95
+ xy-forever` gets the latest normal version, `pip install --pre xy-forever` also the newest development version.
@@ -0,0 +1,75 @@
1
+ # The mod developer's package, `xy-forever` on PyPI (#284): the `xyf` command and only what it runs. Its inputs are
2
+ # this folder, ../LICENSE and the modules listed below; scripts/xyf_dist.py stages them into one folder and runs
3
+ # `uv build` there, and .github/workflows/pypi.yml publishes the result (docs/operating/pypi.md). The repository's own
4
+ # project is ../pyproject.toml.
5
+ [project]
6
+ name = "xy-forever"
7
+ version = "0.1.0.dev135" # the lowest the next normal version may be: scripts/xyf_dist.py version picks the real one
8
+ description = "Boot your Open-XY build once on an OP-XY running XY Forever: xyf stock-os, xyf dev, xyf logs"
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ license-files = ["LICENSE"]
12
+ requires-python = ">=3.11" # Open-XY's sdk.py's
13
+ dependencies = [
14
+ "pyserial>=3.5", # the OP-XY's serial port: finding it, and on Windows opening it (transport.py)
15
+ ]
16
+ keywords = ["op-xy", "open-xy", "xy-forever", "teenage engineering", "mods"]
17
+ classifiers = [
18
+ "Development Status :: 3 - Alpha",
19
+ "Environment :: Console",
20
+ "Intended Audience :: Developers",
21
+ "Operating System :: MacOS",
22
+ "Operating System :: Microsoft :: Windows",
23
+ "Operating System :: POSIX :: Linux",
24
+ "Programming Language :: Python :: 3",
25
+ "Topic :: Multimedia :: Sound/Audio",
26
+ ]
27
+
28
+ [project.urls]
29
+ Homepage = "https://xy-forever.trappar.com"
30
+ Source = "https://github.com/trappar/xy-forever"
31
+ Issues = "https://github.com/trappar/xy-forever/issues"
32
+
33
+ [project.scripts]
34
+ xyf = "xy_forever.xyf:main"
35
+ xy-forever = "xy_forever.xyf:main" # the same: `uvx xy-forever dev ...` and `pipx run xy-forever dev ...` run the package's name
36
+
37
+ [build-system]
38
+ requires = ["hatchling>=1.27"]
39
+ build-backend = "hatchling.build"
40
+
41
+ [tool.hatch.build.targets.wheel]
42
+ packages = ["xy_forever"]
43
+
44
+ [tool.xyf]
45
+ # The package's modules (xy_forever/NAME.py). They run on Python 3.11 too: ../pyproject.toml
46
+ # lints them as 3.11 (per-file-target-version; tests/test_xyf_dist.py keeps both lists equal), and the PyPI workflow
47
+ # runs the installed package on 3.11.
48
+ modules = [
49
+ "__init__",
50
+ "bounds",
51
+ "depth",
52
+ "dev_entry",
53
+ "device_client",
54
+ "device_lock",
55
+ "host_trust",
56
+ "host_write",
57
+ "ldr",
58
+ "moddev",
59
+ "modconfig",
60
+ "modsend",
61
+ "modsend_local",
62
+ "modstore",
63
+ "mtp_read",
64
+ "native_json",
65
+ "no_device",
66
+ "package_records",
67
+ "package_store",
68
+ "paths",
69
+ "startup_ready",
70
+ "transport",
71
+ "usb_proto",
72
+ "usb_proto_ids",
73
+ "xyf",
74
+ "xyf_entry",
75
+ ]
@@ -0,0 +1,10 @@
1
+ """Host-side tooling for XY Forever, the OP-XY firmware and mod manager."""
2
+
3
+ import sys
4
+
5
+ __version__ = '0.1.0'
6
+
7
+ if 'unittest' in sys.modules: # a test run: no real device here or in any process it starts
8
+ from xy_forever import no_device
9
+
10
+ no_device.switch_on()
@@ -0,0 +1,14 @@
1
+ """Hard bounds on tests, processes and simulator calls (#230): a hang ends, named, within its bound.
2
+
3
+ A bound ends a hang, never a slow run: each is several times what its work takes on a busy machine, as the
4
+ CPU budgets (tests/conftest.py) are what hold a test to its speed. Never raise one to make a test pass.
5
+ """
6
+
7
+ TEST_S = 60.0 # one test with the fixtures before it (pytest-timeout's timeout, set by tests/conftest.py; HUNG)
8
+ SIM_TEST_S = 20.0 # one simulator core test (the `sim` tier, #233): hard-killed past it
9
+ SIM_DEADLINE_S = 45.0 # a test's simulator exits on its own this long after it started (xyf_sim --deadline-s); a
10
+ # sweep's one board ran past 20 s at load 48: that ended a slow run, not a hang (a sim-tier test ends at SIM_TEST_S)
11
+ SIM_CALL_S = 5.0 # one host call to the simulator, wall time (xyf-host --sim, conformance.py --sim)
12
+ SIM_CONNECT_S = 5.0 # finding the simulator's endpoint and its HELLO (xyf-host connect --sim)
13
+ WAIT_S = 10.0 # a test's wait for the simulator to reach a state
14
+ COMPILE_S = 120.0 # one CMake configure or build of a simulator variant (xy_forever/sim.py build())
@@ -0,0 +1,72 @@
1
+ """The depth rule (#124, docs/SAFETY.md): no file more than MAX_FOLDERS folders below /yaffs2.
2
+
3
+ The stock dev-menu MTP walks /yaffs2 with fixed 10-entry stacks (889f1ff6): after it has walked a file 7
4
+ folders deep, the dev menu's Track 5 in that boot hangs and the next boot needs a storage repair (8: it cannot
5
+ read or delete the file; 9: it crashes). XY Forever's file service refuses deeper folders and files
6
+ (target/file_engine.hpp, file_client::rename for a folder moved deeper); the host tools check first so that
7
+ they say why. Reads, listing and removals work at any depth, so an older deep tree can still be deleted.
8
+ """
9
+
10
+ from xy_forever import usb_proto as P
11
+
12
+ MAX_FOLDERS = 6
13
+ TEXT = (
14
+ "more than %d folders below /yaffs2 (deeper hangs the dev menu's MTP, then Track 5: docs/SAFETY.md)" % MAX_FOLDERS
15
+ )
16
+
17
+
18
+ def folders(path, folder=False):
19
+ """The folders below /yaffs2 that a device path sits in (a folder: counting itself)."""
20
+ names = [n for n in path[len('/yaffs2') :].split('/') if n]
21
+ return len(names) - (0 if folder else 1)
22
+
23
+
24
+ def refusal(path, folder=False, below=0):
25
+ """None when path (a folder: with `below` levels of folders inside it) keeps the rule, else the message."""
26
+ if folders(path, folder) + below <= MAX_FOLDERS:
27
+ return None
28
+ return 'refused: %s%s is %s' % (path, ' with the folders inside it' if below else '', TEXT)
29
+
30
+
31
+ def folders_below(list_dir, folder, most=MAX_FOLDERS + 1):
32
+ """Levels of folders inside a device folder (0: none), through list_dir(path) -> (code, [(kind, size, name)]);
33
+ stops counting at most. (code, levels)."""
34
+ code, entries = list_dir(folder)
35
+ if code:
36
+ return code, 0
37
+ deepest = 0
38
+ for kind, _, name in entries:
39
+ if kind == 1 and most > 0:
40
+ code, below = folders_below(list_dir, folder + '/' + name.decode('utf-8'), most - 1)
41
+ if code:
42
+ return code, 0
43
+ deepest = max(deepest, below + 1)
44
+ return 0, min(deepest, most)
45
+
46
+
47
+ def command_refusal(args):
48
+ """xyf_host.py: the message refusing a mkdir, put, put-file, mv or cp whose path breaks the rule, else None."""
49
+ command = args.command
50
+ if command == 'mkdir':
51
+ return refusal(args.path, True)
52
+ if command in ('put', 'put-file'):
53
+ return refusal(args.remote)
54
+ return refusal(args.target.rstrip('/')) if command in ('mv', 'cp') else None
55
+
56
+
57
+ def move_note(code):
58
+ """xyf-host mv: why the device refused a move (the folder walk of file.rename), appended to its result line."""
59
+ if code != P.STATUS_NAMES.index('refused'):
60
+ return ''
61
+ return (
62
+ '\n (a folder moved deeper must keep every folder in it within %d below /yaffs2: docs/SAFETY.md)' % MAX_FOLDERS
63
+ )
64
+
65
+
66
+ def copy_refusal(list_dir, source, target):
67
+ """cp -r: 0 when the folder source, copied to target, keeps the rule; else prints why and returns the exit code."""
68
+ code, below = folders_below(list_dir, source)
69
+ deep = code or refusal(target, True, below)
70
+ if deep:
71
+ print(deep if not code else 'ls %s: %s' % (source, P.status_name(code)))
72
+ return code or (2 if deep else 0)