Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
f338c84
fix(capture): assemble every chunk of a remote capture (NEH-241)
juancobo Sep 9, 2026
901efc0
fix(device): install the signal handlers only on the main thread (NEH…
juancobo Sep 9, 2026
d600af6
feat(own-txt): carry a camera id beside the page parity (NEH-243)
juancobo Sep 9, 2026
532fd46
chore(release): 0.1.1
juancobo Sep 9, 2026
3d67301
refactor(package): resolve the exports lazily so the flasher stays st…
juancobo Sep 9, 2026
fd10ad3
fix(capture): follow CHDK's seek semantics when assembling a capture …
juancobo Sep 9, 2026
c1a1cd5
fix(flasher): read the card's id before the card is erased (NEH-243)
juancobo Sep 9, 2026
d6dd551
fix(own-txt): accept only a well-formed id, and never let a bad line …
juancobo Sep 9, 2026
d983e33
feat(capture): refuse a streamed DNG instead of returning a partial file
juancobo Sep 9, 2026
dc94883
fix(capture): tell an uninitialized remote capture from a ready one (…
juancobo Sep 9, 2026
111e91e
fix(script): keep the text of a script error and name its kind
juancobo Sep 9, 2026
30f5d63
fix(script): refuse a script that never started
juancobo Sep 9, 2026
7fb0c3f
ci: run the test suite on push and pull request
juancobo Sep 9, 2026
90f778e
fix(capture): initialize and shoot in one script so the shot cannot k…
juancobo Sep 9, 2026
e331750
fix(capture): refuse a ready mask without the requested format
juancobo Sep 9, 2026
f62fa6d
fix(flasher): keep the card's id even when parity is skipped
juancobo Sep 9, 2026
2ca4375
fix(flasher): stop rather than erase a card whose identity could not …
juancobo Sep 9, 2026
2722b65
fix(capture): download while the script runs instead of waiting for it
juancobo Sep 9, 2026
2c1213a
fix(flasher): never erase a card whose filesystem could not be inspected
juancobo Sep 9, 2026
c10e9c9
fix(flasher): leave parity alone when the operator skips it
juancobo Sep 9, 2026
6cb9e7b
fix(script): raise on a script that fails after it starts
juancobo Sep 9, 2026
93485f5
fix(capture): let the caller decide what an uninitialized capture means
juancobo Sep 9, 2026
febc784
fix(flasher): read the whole card's layout before calling it blank
juancobo Sep 9, 2026
66526c4
fix(script): match a script's messages to the script that started
juancobo Sep 10, 2026
1f05922
fix(flasher): recognize a blank card rather than assuming one
juancobo Sep 10, 2026
994bf7a
fix(device): match a mode switch's messages to its own script
juancobo Sep 10, 2026
0c8aca9
fix(capture): tell a slow initialization from one that never happened
juancobo Sep 10, 2026
713a5eb
fix(flasher): fail rather than guess when a card will not mount
juancobo Sep 10, 2026
5282bcd
fix(capture): stop the DNG refusal pointing at a path that does nothing
juancobo Sep 10, 2026
22f5f73
fix(flasher): never extract to a path the card did not give us
juancobo Sep 10, 2026
2e469b1
fix(flasher): let the layout decide whether a card can be inspected
juancobo Sep 10, 2026
d77b34d
fix(flasher): stop reading a partition scheme as a filesystem
juancobo Sep 10, 2026
ac2f426
docs(own-txt): describe the file shapes that actually occur, and keep…
juancobo Sep 10, 2026
1f0c6c5
docs(own-txt): state the four file shapes, and make the APFS test pro…
juancobo Sep 10, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# The suite is all mocks: it runs the PTP and CHDK protocol logic without a
# camera, which is the only way this library can be tested between bench
# sessions. `tests/` is named explicitly because `examples/` holds hardware
# scripts that pytest would otherwise collect and fail to import.
name: CI

on:
push:
branches: [main]
pull_request:
workflow_dispatch:

jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.11", "3.12"]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"
- name: Test
run: pytest tests/ -q
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,11 @@ pyusb / libusb — raw USB access

## Camera side assignment

For book scanning with two cameras, each camera is identified as "odd" or "even" (left/right pages). This is stored in a file called `OWN.TXT` on the camera's SD card containing either `ODD` or `EVEN`. The Captua workflow reads this via `download_file('OWN.TXT')` to determine page sequencing and EXIF orientation.
For book scanning with two cameras, each body is assigned a page parity — which pages it shoots — stored in a file called `OWN.TXT` on the camera's SD card. A parity line reads `ODD` or `EVEN`; which of the two sits on the left is the operator's reading direction, and the file says nothing about it. An id line, `id=3f9a1c2b7d4e`, gives the body a stable identity, because pyusb cannot always read a serial number from a Canon compact. The Captua workflow reads the file via `download_file('A/OWN.TXT')` to determine page sequencing and EXIF orientation, and to tell one body from the other across replugs. Note the `A/` prefix: `download_file` and `upload_file` both take a card path.

The `tools/flash_chdk.py` script writes this file during SD card preparation.
Either line can stand alone, so a reader must handle four shapes: both lines, a parity alone, an identity alone, and no file at all. `parse_own_txt` and `format_own_txt` in `util.py` read and write all four; treat a missing parity as unassigned rather than as an error.

Skipping the parity prompt while flashing means "leave the assignment alone", so a card that said `EVEN` still says `EVEN` afterwards. An identity-only file is what skipping produces on a card that had no parity to preserve — the body keeps its identity even though nobody has said yet which pages it shoots — and a card with neither a parity nor an identity gets no file at all. In practice `tools/flash_chdk.py` never writes a parity on its own, because it mints an identity whenever it writes one; a parity-only file comes from an older card or a hand-written one, and is read normally.

## Tools

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "pychdk"
version = "0.1.0"
version = "0.1.1"
description = "Pure Python CHDK PTP camera control"
requires-python = ">=3.11"
dependencies = [
Expand Down
59 changes: 52 additions & 7 deletions src/pychdk/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,58 @@
"""Pure Python CHDK PTP camera control."""
__version__ = "0.1.0"
import importlib

from pychdk.device import ChdkDevice, list_devices, DeviceInfo
from pychdk.ptp import PTPError
from pychdk.chdk import ChdkPTP
from pychdk.multicam import MultiCam
from pychdk import util
__version__ = "0.1.1"

__all__ = [
"ChdkDevice", "list_devices", "DeviceInfo",
"ChdkDevice", "list_devices", "DeviceInfo", "install_signal_handlers",
"PTPError", "ChdkPTP", "MultiCam", "util",
"parse_own_txt", "format_own_txt",
]

# Submodules reachable as attributes of the package.
_SUBMODULES = ("util",)

# Every other export, mapped to the submodule that owns it.
_EXPORTS = {
"ChdkDevice": "pychdk.device",
"list_devices": "pychdk.device",
"DeviceInfo": "pychdk.device",
"install_signal_handlers": "pychdk.device",
"PTPError": "pychdk.ptp",
"ChdkPTP": "pychdk.chdk",
"MultiCam": "pychdk.multicam",
"parse_own_txt": "pychdk.util",
"format_own_txt": "pychdk.util",
}


def __getattr__(name):
"""Resolve an export on first access (PEP 562).

Importing the submodules eagerly meant that reaching pychdk.util —
which needs nothing but math — imported pychdk.device and so pyusb.
Each name now costs only the submodule that owns it, and is cached
in the module globals afterwards.

Args:
name: Attribute being looked up on the package.

Returns:
The submodule or the exported object.

Raises:
AttributeError: If the package exports no such name.
"""
if name in _SUBMODULES:
value = importlib.import_module(f"pychdk.{name}")
elif name in _EXPORTS:
value = getattr(importlib.import_module(_EXPORTS[name]), name)
else:
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
globals()[name] = value
return value


def __dir__():
"""List the exports alongside whatever has already been resolved."""
return sorted(set(globals()) | set(__all__))
Loading
Loading