Skip to content

Commit 1bc3bc8

Browse files
authored
Fix too many arguments when strip is called (#69)
* Fix too many arguments when strip is called * Bump version * Fix lint
1 parent 465607b commit 1bc3bc8

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "toltecmk"
3-
version = "0.5.2"
3+
version = "0.5.3"
44
authors = [
55
{ name="Mattéo Delabre", email="git.matteo@delab.re" },
66
{ name="Eeems", email="eeems@eeems.email" },

toltec/hooks/patch_rm2fb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,5 @@ def docker_file_path(file_path: str) -> str:
8282
+ " ".join(docker_file_path(file_path) for file_path in binaries)
8383
)
8484

85-
script += restore_mtime_script(original_mtime)
85+
script += restore_mtime_script(src_dir, MOUNT_SRC, original_mtime)
8686
run_in_container(builder, src_dir, logger, script)

toltec/hooks/strip.py

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
import os
1010
import logging
11+
import random
12+
import string
1113
import shlex
1214
from typing import Callable
1315
import docker
@@ -60,17 +62,35 @@ def run_in_container(
6062
bash.pipe_logs(_logger, logs)
6163

6264

63-
def restore_mtime_script(original_mtime: dict[str, int]) -> list[str]:
65+
def restore_mtime_script(
66+
src_dir: str, mnt_dir: str, original_mtime: dict[str, int]
67+
) -> list[str]:
6468
"""Restore original mtimes for files after they have been modified"""
65-
script: list[str] = []
69+
if not original_mtime:
70+
return []
71+
72+
script: list[str] = ["import os"]
6673
for file_path, mtime in original_mtime.items():
67-
script.append(
68-
'echo "import os; os.utime('
69-
+ f'\\"{file_path}\\", ns=({mtime}, {mtime})'
70-
+ ')" | python3 -u'
71-
)
74+
script.append(f'os.utime("{file_path}", ns=({mtime}, {mtime}))')
75+
76+
while os.path.exists(
77+
(script_path := os.path.join(src_dir, f".{randomword(10)}.py"))
78+
):
79+
pass
80+
81+
with open(script_path, "w", encoding="utf-8") as f:
82+
_ = f.write("\n".join(script))
83+
84+
docker_path = shlex.quote(
85+
os.path.join(mnt_dir, os.path.relpath(script_path, src_dir))
86+
)
87+
return [f"python3 -u {docker_path}", f"rm {docker_path}"]
88+
7289

73-
return script
90+
def randomword(length: int) -> str:
91+
"""Create a random string"""
92+
letters = string.ascii_lowercase
93+
return "".join(random.choice(letters) for i in range(length))
7494

7595

7696
def register(builder: Builder) -> None:
@@ -177,5 +197,5 @@ def docker_file_path(file_path: str) -> str:
177197
os.path.relpath(file_path, src_dir),
178198
)
179199

180-
script += restore_mtime_script(original_mtime)
200+
script += restore_mtime_script(src_dir, MOUNT_SRC, original_mtime)
181201
run_in_container(builder, src_dir, logger, script)

0 commit comments

Comments
 (0)