pdev-pj1-yaml-tool 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,10 @@
1
+ Metadata-Version: 2.3
2
+ Name: pdev-pj1-yaml-tool
3
+ Version: 0.1.0
4
+ Summary: Add your description here
5
+ Author: pdev
6
+ Author-email: pdev <pdevfig@gmail.com>
7
+ Requires-Dist: ruamel-yaml>=0.19.1
8
+ Requires-Python: >=3.13
9
+ Description-Content-Type: text/markdown
10
+
File without changes
@@ -0,0 +1,18 @@
1
+ [project]
2
+ name = "pdev-pj1-yaml-tool"
3
+ version = "0.1.0"
4
+ description = "Add your description here"
5
+ readme = "README.md"
6
+ requires-python = ">=3.13"
7
+ dependencies = ["ruamel-yaml>=0.19.1"]
8
+
9
+ [[project.authors]]
10
+ name = "pdev"
11
+ email = "pdevfig@gmail.com"
12
+
13
+ [project.scripts]
14
+ pdev-pj1-yaml-tool = "pdev_pj1_yaml_tool.main:main"
15
+
16
+ [build-system]
17
+ requires = ["uv_build>=0.12.13,<0.13.0"]
18
+ build-backend = "uv_build"
@@ -0,0 +1,19 @@
1
+ [project]
2
+ name = "pdev-pj1-yaml-tool"
3
+ version = "0.1.0"
4
+ description = "Add your description here"
5
+ readme = "README.md"
6
+ authors = [
7
+ { name = "pdev", email = "pdevfig@gmail.com" }
8
+ ]
9
+ requires-python = ">=3.13"
10
+ dependencies = [
11
+ "ruamel-yaml>=0.19.1",
12
+ ]
13
+
14
+ [project.scripts]
15
+ pdev-pj1-yaml-tool = "pdev_pj1_yaml_tool.main:main"
16
+
17
+ [build-system]
18
+ requires = ["uv_build>=0.12.13,<0.13.0"]
19
+ build-backend = "uv_build"
@@ -0,0 +1,77 @@
1
+ import argparse
2
+ import json
3
+ from pathlib import Path
4
+ import secrets
5
+
6
+ from ruamel.yaml import YAML
7
+
8
+ class YamlException(Exception):
9
+ pass
10
+
11
+ def arg_parser() -> argparse.Namespace:
12
+ parser = argparse.ArgumentParser()
13
+
14
+ parser.add_argument(
15
+ "--backend-image-tag-value",
16
+ help="Backend image tag value",
17
+ type=str,
18
+ dest="backend_new_tag",
19
+ default=""
20
+ )
21
+
22
+ parser.add_argument(
23
+ "--frontend-image-tag-value",
24
+ help="Frontend image tag value",
25
+ type=str,
26
+ dest="frontend_new_tag",
27
+ default=""
28
+ )
29
+
30
+ parser.add_argument(
31
+ "--file",
32
+ help="Yaml file name.",
33
+ type=str,
34
+ required=True
35
+ )
36
+
37
+ return parser.parse_args()
38
+
39
+ def change_tag(
40
+ service_type: str,
41
+ yaml_data,
42
+ tag_value
43
+ ):
44
+ try:
45
+ yaml_data[service_type]["deployment"]["imageName"]["tag"] = tag_value
46
+ except Exception as exc:
47
+ raise YamlException(f"Exception occurred during change value: {exc}")
48
+ return yaml_data
49
+
50
+ def main() -> int:
51
+ args = arg_parser()
52
+
53
+ yaml = YAML()
54
+ yaml.preserve_quotes = True
55
+
56
+ try:
57
+ file_path = Path(args.file)
58
+ if file_path.exists:
59
+ with file_path.open("r") as file:
60
+ data = yaml.load(file)
61
+
62
+ if args.backend_new_tag != "":
63
+ yaml_data = change_tag(service_type ="backend", yaml_data=data, tag_value=args.backend_new_tag)
64
+ if args.frontend_new_tag != "":
65
+ yaml_data = change_tag(service_type ="frontend", yaml_data=data, tag_value=args.frontend_new_tag)
66
+
67
+ newfile_name = f"newvalue-{secrets.token_hex(6)}.yaml"
68
+ with open(newfile_name, "w") as newfile:
69
+ yaml.dump(data, stream=newfile)
70
+ print(f"Data is wrtten to {newfile_name}")
71
+ except Exception as exc:
72
+ raise YamlException(f"Exception occured: {exc}")
73
+ return 1
74
+ return 0
75
+
76
+ if __name__ == "__main__":
77
+ raise SystemExit(main())