ra8-firmware
0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
write-proof.py
Go to the documentation of this file.
1
#!/usr/bin/env python3
2
# SPDX-License-Identifier: MIT
3
# Copyright (c) 2026 Brighton Sikarskie
4
"""Create one exclusive, no-follow Git-hook completion proof."""
5
6
from
__future__
import
annotations
7
8
import
os
9
import
sys
10
from
pathlib
import
Path
11
12
EXPECTED_ARGC = 2
13
14
15
def
write_proof(path: Path, token: str) ->
None
:
16
"""Write one ASCII token without replacing or following an existing path."""
17
token.encode(
"ascii"
)
18
flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL | getattr(os,
"O_NOFOLLOW"
, 0)
19
descriptor = os.open(path, flags, 0o600)
20
try
:
21
with
os.fdopen(descriptor,
"w"
, encoding=
"ascii"
, closefd=
False
)
as
output:
22
output.write(f
"{token}\n"
)
23
output.flush()
24
finally
:
25
os.close(descriptor)
26
27
28
def
main
() -> int:
29
"""Read one private token from stdin and create the requested proof."""
30
if
len(sys.argv) != EXPECTED_ARGC:
31
print(
"usage: write-proof.py <path> # token on stdin"
, file=sys.stderr)
32
return
2
33
token = sys.stdin.readline().removesuffix(
"\n"
)
34
if
not
token
or
sys.stdin.read(1):
35
print(
"write-proof.py: stdin must contain one non-empty token line"
, file=sys.stderr)
36
return
2
37
try
:
38
write_proof(Path(sys.argv[1]), token)
39
except
(OSError, UnicodeError)
as
exc:
40
print(f
"write-proof.py: {exc}"
, file=sys.stderr)
41
return
1
42
return
0
43
44
45
if
__name__ ==
"__main__"
:
46
raise
SystemExit(
main
())
main
void main(void)
The application entry point Reset_Handler hands control to.
Definition
main.c:298
scripts
git
write-proof.py
Generated by
1.16.1