forked from osbuild/osbuild
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorg.osbuild.cpio.out
executable file
·69 lines (53 loc) · 1.55 KB
/
org.osbuild.cpio.out
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/python3
import os
import subprocess
import sys
import osbuild.api
def iter_files(tree, include):
for root, _, files in os.walk(tree, topdown=True):
for f in files:
path = os.path.relpath(os.path.join(root, f), tree)
yield path
if tree != root or include:
yield os.path.relpath(root, tree)
def main(inputs, output_dir, options):
tree = inputs["tree"]["path"]
filename = options["filename"].lstrip("/")
outfmt = options.get("format", "newc")
root_node = options.get("root-node", "include")
append = options.get("append", False)
reproducible = options.get("reproducible", True)
owner = options.get("owner", {})
extra_args = []
if reproducible:
extra_args += ["--reproducible"]
if append:
extra_args += ["--append"]
if owner:
user = owner["user"]
group = owner.get("group")
user_arg = f"--owner={user}"
if group:
user_arg += f":{group}"
extra_args += [user_arg]
cmd = [
"cpio",
"-v",
"-o",
f"--format={outfmt}",
"--null",
*extra_args,
"-O", os.path.join(output_dir, filename),
"-D", tree,
]
files = "\0".join([str(f) for f in iter_files(tree, root_node == "include")])
subprocess.run(
cmd,
check=True,
input=files.encode("utf-8"),
)
return 0
if __name__ == '__main__':
args = osbuild.api.arguments()
r = main(args["inputs"], args["tree"], args["options"])
sys.exit(r)