annotate create_container_hash.py @ 92:cf8ad181628f draft

planemo upload commit 36be3b053802693392f935e6619ba3f2b1704e3c
author rhpvorderman
date Mon, 12 Dec 2022 12:32:44 +0000
parents 6809c63d9161
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
90
6809c63d9161 "planemo upload commit fd64827ff6e63df008f6f50ddb8576ad2b1dbb26"
rhpvorderman
parents:
diff changeset
1 #!/usr/bin/env python3
6809c63d9161 "planemo upload commit fd64827ff6e63df008f6f50ddb8576ad2b1dbb26"
rhpvorderman
parents:
diff changeset
2
6809c63d9161 "planemo upload commit fd64827ff6e63df008f6f50ddb8576ad2b1dbb26"
rhpvorderman
parents:
diff changeset
3 import sys
6809c63d9161 "planemo upload commit fd64827ff6e63df008f6f50ddb8576ad2b1dbb26"
rhpvorderman
parents:
diff changeset
4
6809c63d9161 "planemo upload commit fd64827ff6e63df008f6f50ddb8576ad2b1dbb26"
rhpvorderman
parents:
diff changeset
5 from xml.etree import ElementTree
6809c63d9161 "planemo upload commit fd64827ff6e63df008f6f50ddb8576ad2b1dbb26"
rhpvorderman
parents:
diff changeset
6 from xml.etree.ElementTree import Element
6809c63d9161 "planemo upload commit fd64827ff6e63df008f6f50ddb8576ad2b1dbb26"
rhpvorderman
parents:
diff changeset
7
6809c63d9161 "planemo upload commit fd64827ff6e63df008f6f50ddb8576ad2b1dbb26"
rhpvorderman
parents:
diff changeset
8 DEFAULT_BASE_IMAGE = "bgruening/busybox-bash:0.1"
6809c63d9161 "planemo upload commit fd64827ff6e63df008f6f50ddb8576ad2b1dbb26"
rhpvorderman
parents:
diff changeset
9 def main():
6809c63d9161 "planemo upload commit fd64827ff6e63df008f6f50ddb8576ad2b1dbb26"
rhpvorderman
parents:
diff changeset
10 try:
6809c63d9161 "planemo upload commit fd64827ff6e63df008f6f50ddb8576ad2b1dbb26"
rhpvorderman
parents:
diff changeset
11 base_image = sys.argv[1]
6809c63d9161 "planemo upload commit fd64827ff6e63df008f6f50ddb8576ad2b1dbb26"
rhpvorderman
parents:
diff changeset
12 except IndexError:
6809c63d9161 "planemo upload commit fd64827ff6e63df008f6f50ddb8576ad2b1dbb26"
rhpvorderman
parents:
diff changeset
13 base_image = DEFAULT_BASE_IMAGE
6809c63d9161 "planemo upload commit fd64827ff6e63df008f6f50ddb8576ad2b1dbb26"
rhpvorderman
parents:
diff changeset
14 tool = ElementTree.parse("shm_csr.xml").getroot()
6809c63d9161 "planemo upload commit fd64827ff6e63df008f6f50ddb8576ad2b1dbb26"
rhpvorderman
parents:
diff changeset
15 requirements: Element = tool.find("requirements")
6809c63d9161 "planemo upload commit fd64827ff6e63df008f6f50ddb8576ad2b1dbb26"
rhpvorderman
parents:
diff changeset
16 packages = []
6809c63d9161 "planemo upload commit fd64827ff6e63df008f6f50ddb8576ad2b1dbb26"
rhpvorderman
parents:
diff changeset
17 for req in requirements.findall("requirement"):
6809c63d9161 "planemo upload commit fd64827ff6e63df008f6f50ddb8576ad2b1dbb26"
rhpvorderman
parents:
diff changeset
18 if req.get("type") == "package":
6809c63d9161 "planemo upload commit fd64827ff6e63df008f6f50ddb8576ad2b1dbb26"
rhpvorderman
parents:
diff changeset
19 name = req.text
6809c63d9161 "planemo upload commit fd64827ff6e63df008f6f50ddb8576ad2b1dbb26"
rhpvorderman
parents:
diff changeset
20 version = req.get("version")
6809c63d9161 "planemo upload commit fd64827ff6e63df008f6f50ddb8576ad2b1dbb26"
rhpvorderman
parents:
diff changeset
21 package_string = f"{name}={version}"
6809c63d9161 "planemo upload commit fd64827ff6e63df008f6f50ddb8576ad2b1dbb26"
rhpvorderman
parents:
diff changeset
22 packages.append(package_string)
6809c63d9161 "planemo upload commit fd64827ff6e63df008f6f50ddb8576ad2b1dbb26"
rhpvorderman
parents:
diff changeset
23 with open("container_hash.tsv", mode="wt") as container_hash_file:
6809c63d9161 "planemo upload commit fd64827ff6e63df008f6f50ddb8576ad2b1dbb26"
rhpvorderman
parents:
diff changeset
24 container_hash_file.write("#targets\tbase_image\timage_build\n")
6809c63d9161 "planemo upload commit fd64827ff6e63df008f6f50ddb8576ad2b1dbb26"
rhpvorderman
parents:
diff changeset
25 container_hash_file.write(",".join(packages) + f"\t{base_image}\t0\n")
6809c63d9161 "planemo upload commit fd64827ff6e63df008f6f50ddb8576ad2b1dbb26"
rhpvorderman
parents:
diff changeset
26
6809c63d9161 "planemo upload commit fd64827ff6e63df008f6f50ddb8576ad2b1dbb26"
rhpvorderman
parents:
diff changeset
27
6809c63d9161 "planemo upload commit fd64827ff6e63df008f6f50ddb8576ad2b1dbb26"
rhpvorderman
parents:
diff changeset
28 if __name__ == "__main__":
6809c63d9161 "planemo upload commit fd64827ff6e63df008f6f50ddb8576ad2b1dbb26"
rhpvorderman
parents:
diff changeset
29 main()