Skip to main content

Acorn file metadata handling: INF sidecars, filename encoding, xattrs, and access flags

Project description

oaknut-file

PyPI version CI Python versions License: MIT

Acorn file metadata handling for the oaknut package family.

oaknut-file is the shared metadata layer used by oaknut-zip and oaknut-dfs. It provides:

  • The Access IntFlag enum for Acorn file attribute bytes
  • The AcornMeta dataclass for load/exec addresses and attributes
  • INF sidecar file parsing and formatting (traditional and PiEconetBridge variants)
  • Filename metadata encoding (,xxx, ,llllllll,eeeeeeee, ,load-exec)
  • Extended attribute read/write under user.acorn.* and user.econet_*

Installation

Using uv (recommended):

uv add oaknut-file

pip install oaknut-file also works.

The xattr package is automatically installed on macOS, where it is required for extended attribute support. Linux uses os.setxattr from the standard library and needs no additional dependency. Windows does not support extended attributes; the xattr functions will raise on use.

Quick start

Access flags

The Access IntFlag enum represents the standard Acorn OSFILE attribute byte. Bit values match the filing system API convention used by PiEconetBridge and the user.acorn.attr extended attribute.

from oaknut.file import Access

# Compose flags with bitwise OR
flags = Access.R | Access.W | Access.L
print(repr(flags))   # <Access.R|W|L: 11>
print(hex(flags))    # 0x0B
Flag Value Meaning
Access.R 0x01 Owner read
Access.W 0x02 Owner write
Access.E 0x04 Execute only
Access.L 0x08 Locked
Access.PR 0x10 Public read
Access.PW 0x20 Public write

INF sidecar files

Two INF sidecar formats are supported. parse_inf_line() auto-detects which format a line uses, while format_trad_inf_line() and format_pieb_inf_line() let you choose explicitly when writing.

from oaknut.file import (
    Access, format_trad_inf_line, format_pieb_inf_line, parse_inf_line,
)

# Traditional INF: filename load exec length [attr]
trad = format_trad_inf_line(
    filename="HELLO",
    load_addr=0x1900,
    exec_addr=0x8023,
    length=0x100,
    attr=int(Access.R | Access.W),
)
print(trad)
# HELLO       00001900 00008023 00000100 03

# PiEconetBridge INF: owner load exec perm
pieb = format_pieb_inf_line(
    load_addr=0xFFFFDD00,
    exec_addr=0xFFFFDD00,
    attr=int(Access.R | Access.W | Access.L | Access.PR),
)
print(pieb)
# 0 ffffdd00 ffffdd00 1b

# Auto-detect format on parse
source, meta = parse_inf_line(trad)
print(meta)
# AcornMeta(load_addr=0x1900, exec_addr=0x8023, attr=0x03)

source, meta = parse_inf_line(pieb)
print(meta)
# AcornMeta(load_addr=0xFFFFDD00, exec_addr=0xFFFFDD00, attr=0x1B, filetype=0xFDD)

Filename metadata encoding

Three filename suffix conventions are supported for embedding load/exec addresses or RISC OS filetypes in host filenames.

from oaknut.file import parse_encoded_filename

# RISC OS filetype suffix (3 hex digits)
clean, meta = parse_encoded_filename("PROG,ffb")
print(clean, meta.infer_filetype())
# ('PROG', filetype=0xFFB)

# MOS load-exec suffix (variable-width hex)
clean, meta = parse_encoded_filename("PROG,1900-801f")
print(clean, meta.load_addr, meta.exec_addr)
# ('PROG', load_addr=0x1900, exec_addr=0x801F)

Filetype-stamped load addresses

When a load address has its top 12 bits set to 0xFFF, the next 12 bits encode a RISC OS filetype.

from oaknut.file import AcornMeta

meta = AcornMeta(load_addr=0xFFFF0E10)
print(meta.is_filetype_stamped, hex(meta.infer_filetype()))
# is_filetype_stamped=True, infer_filetype()=0xF0E

Extended attributes

from oaknut.file import write_acorn_xattrs, read_acorn_xattrs

# Write to user.acorn.* namespace
write_acorn_xattrs(
    "myfile.bin",
    load_addr=0x1900,
    exec_addr=0x8023,
    attr=0x03,
)

# Read back (falls through to user.econet_* if user.acorn.* is absent)
meta = read_acorn_xattrs("myfile.bin")
print(meta.load_addr, meta.exec_addr, meta.attr)

Public API

Module Exports
oaknut.file.access Access, format_access_hex, format_access_text
oaknut.file.meta AcornMeta
oaknut.file.formats MetaFormat, SOURCE_* labels
oaknut.file.inf parse_inf_line, format_trad_inf_line, format_pieb_inf_line, read_inf_file, write_inf_file
oaknut.file.filename_encoding parse_encoded_filename, build_filename_suffix, build_mos_filename_suffix
oaknut.file.xattr read_acorn_xattrs, write_acorn_xattrs, read_econet_xattrs, write_econet_xattrs

All public symbols are also re-exported from the top-level oaknut.file package.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

oaknut_file-10.0.3.tar.gz (30.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

oaknut_file-10.0.3-py3-none-any.whl (22.2 kB view details)

Uploaded Python 3

File details

Details for the file oaknut_file-10.0.3.tar.gz.

File metadata

  • Download URL: oaknut_file-10.0.3.tar.gz
  • Upload date:
  • Size: 30.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for oaknut_file-10.0.3.tar.gz
Algorithm Hash digest
SHA256 f4db37790e314f184a703de42715aa93b81840bcc1d5309c4cce4b2f918bf7be
MD5 8e9c8f89b1f58d95efcb1032c43c2e03
BLAKE2b-256 ee00306168f7c039115d3f764fa5b6f33496d3ef43c451f8743c9452e16ba3db

See more details on using hashes here.

File details

Details for the file oaknut_file-10.0.3-py3-none-any.whl.

File metadata

  • Download URL: oaknut_file-10.0.3-py3-none-any.whl
  • Upload date:
  • Size: 22.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for oaknut_file-10.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a2f1222d644c1dc231fb7136e7ea6c03f7f7b83588b547a8539cced4071f5dbc
MD5 2f14b6d04a99dca2a82a1a3a0f7d8c1e
BLAKE2b-256 64fcca2efb4c64744b91c0f04b8b5c633d6c225108cd8b98f5cf2106a26c5327

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page