-
Notifications
You must be signed in to change notification settings - Fork 27
/
gen-patchset.py
executable file
·38 lines (31 loc) · 1023 Bytes
/
gen-patchset.py
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
#!/usr/bin/env python3
import argparse
import json
from pathlib import Path
def main():
parser = argparse.ArgumentParser(description="Create flatpak source from patch files")
parser.add_argument("-o", "--output", help="Output json file")
parser.add_argument("patchdir")
args = parser.parse_args()
patchdir = Path(args.patchdir)
assert patchdir.is_dir()
patch_paths = []
for path in sorted(patchdir.iterdir()):
if not path.is_file():
continue
if not (path.name.endswith(".patch") or path.name.endswith(".diff")):
continue
patch_paths.append(str(path))
patch_source = {
"type": "patch",
"paths": patch_paths
}
if args.output:
patch_source_file = args.output
else:
patch_source_file = str(patchdir).replace("/", "-") + ".json"
with open(patch_source_file, "w") as out:
print(patch_source_file)
json.dump(patch_source, out, indent=4)
if __name__ == "__main__":
main()