Mercurial > repos > davidvanzessen > shm_csr
annotate create_container_hash.py @ 95:d63eff357515 draft
planemo upload commit d96a736dcd6da34137f79861fbc6369716c332f1
author | rhpvorderman |
---|---|
date | Mon, 27 Mar 2023 13:11:53 +0000 |
parents | 6809c63d9161 |
children |
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() |