kop-cli 0.1.0a1__py3-none-any.whl

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.
Files changed (60) hide show
  1. kop/__init__.py +0 -0
  2. kop/app/__init__.py +4 -0
  3. kop/app/main.py +124 -0
  4. kop/controllers/handler.py +1903 -0
  5. kop/factory.py +1662 -0
  6. kop/models.py +1379 -0
  7. kop/provider/attach.py +34 -0
  8. kop/provider/client.py +797 -0
  9. kop/provider/config.py +196 -0
  10. kop/provider/events.py +260 -0
  11. kop/provider/exec.py +135 -0
  12. kop/provider/forward.py +294 -0
  13. kop/provider/logs.py +106 -0
  14. kop/registry.py +70 -0
  15. kop/renderers/details.py +387 -0
  16. kop/renderers/fields.py +194 -0
  17. kop/renderers/formatter.py +622 -0
  18. kop/renderers/forms.py +51 -0
  19. kop/renderers/table.py +281 -0
  20. kop/templates/resource/configmaps.yaml +6 -0
  21. kop/templates/resource/cronjobs.yaml +23 -0
  22. kop/templates/resource/daemonsets.yaml +18 -0
  23. kop/templates/resource/deployments.yaml +19 -0
  24. kop/templates/resource/jobs.yaml +20 -0
  25. kop/templates/resource/node-shell-pod.yaml +40 -0
  26. kop/templates/resource/pods.yaml +9 -0
  27. kop/templates/resource/statefulsets.yaml +20 -0
  28. kop/validations.py +52 -0
  29. kop/views/EditView.py +229 -0
  30. kop/views/PodAttach.py +23 -0
  31. kop/views/PodLog.py +27 -0
  32. kop/views/PodTerminal.py +41 -0
  33. kop/views/ResourceView.py +398 -0
  34. kop/views/StartupView.py +821 -0
  35. kop/widgets/Actions.py +176 -0
  36. kop/widgets/Attach.py +112 -0
  37. kop/widgets/Columns.py +21 -0
  38. kop/widgets/Detail.py +192 -0
  39. kop/widgets/Directory.py +16 -0
  40. kop/widgets/Dynamic.py +177 -0
  41. kop/widgets/Edit.py +146 -0
  42. kop/widgets/Events.py +95 -0
  43. kop/widgets/Expandable.py +35 -0
  44. kop/widgets/Focusable.py +90 -0
  45. kop/widgets/Forward.py +314 -0
  46. kop/widgets/Log.py +34 -0
  47. kop/widgets/Modals.py +565 -0
  48. kop/widgets/MultipleSelect.py +255 -0
  49. kop/widgets/Panel.py +150 -0
  50. kop/widgets/Pty.py +300 -0
  51. kop/widgets/RichDetail.py +164 -0
  52. kop/widgets/Rules.py +64 -0
  53. kop/widgets/SideMenu.py +228 -0
  54. kop/widgets/__init__.py +0 -0
  55. kop_cli-0.1.0a1.dist-info/METADATA +159 -0
  56. kop_cli-0.1.0a1.dist-info/RECORD +60 -0
  57. kop_cli-0.1.0a1.dist-info/WHEEL +4 -0
  58. kop_cli-0.1.0a1.dist-info/entry_points.txt +2 -0
  59. kop_cli-0.1.0a1.dist-info/licenses/LICENSE +201 -0
  60. kop_cli-0.1.0a1.dist-info/licenses/NOTICE +4 -0
kop/__init__.py ADDED
File without changes
kop/app/__init__.py ADDED
@@ -0,0 +1,4 @@
1
+ from .main import run
2
+
3
+
4
+ __all__ = ["run"]
kop/app/main.py ADDED
@@ -0,0 +1,124 @@
1
+ import os
2
+ import argparse
3
+ import difflib
4
+ from pathlib import Path
5
+ from importlib.metadata import PackageNotFoundError, version
6
+ from textual.app import App
7
+ from kop.views.ResourceView import ResourceView
8
+ from kop.views.StartupView import ConfigView
9
+ from kop.provider.config import ConfigModel, Config
10
+ from kop.provider.client import KbsEndpoint
11
+ from typing import Optional
12
+
13
+
14
+
15
+
16
+ class Kop(App):
17
+ TITLE = "Kop"
18
+
19
+ def __init__(self, config_file: Optional[str] = None, **kwargs):
20
+ """
21
+ `config_file` is the path to the local kubuconfig file
22
+ specified by the user when starting Kop using the
23
+ `--kubeconfig` parameter.
24
+ """
25
+
26
+ super().__init__(**kwargs)
27
+ self.endpoint: Optional[KbsEndpoint] = None
28
+ self.config_file = config_file
29
+
30
+ def on_mount(self) -> None:
31
+ if self.config_file:
32
+ self.endpoint = KbsEndpoint(config_file=self.config_file)
33
+ self.view = view = ResourceView()
34
+ self.view.sub_title = self.config_file
35
+ self.push_screen(view)
36
+ return
37
+ start_view = ConfigView(kubeconfigs=self._get_configs())
38
+ self.push_screen(
39
+ start_view
40
+ )
41
+ self.home = start_view
42
+
43
+
44
+ def _get_configs(self) -> list[ConfigModel]:
45
+ """
46
+ retrieve all synchronized kubuconfig files in the kop working directory
47
+ """
48
+ return Config().get_configs()
49
+
50
+
51
+ def get_app_version() -> str:
52
+ """Resolve Kop version from package metadata, with a pyproject fallback."""
53
+ try:
54
+ return version("kop")
55
+ except PackageNotFoundError:
56
+ pyproject_path = Path(__file__).resolve().parents[3] / "pyproject.toml"
57
+ if pyproject_path.is_file():
58
+ with pyproject_path.open("r", encoding="utf-8") as f:
59
+ for line in f:
60
+ if line.strip().startswith("version ="):
61
+ return line.split("=", 1)[1].strip().strip('"').strip("'")
62
+ return "unknown"
63
+
64
+
65
+ def get_args() -> Optional[str]:
66
+ """
67
+ retrieves the value of the `--kubeconfig` parameter specified on the command line when starting Kop.
68
+ includes typo suggestion and validation.
69
+ """
70
+
71
+ parser = argparse.ArgumentParser(description="Kop CLI")
72
+
73
+ parser.add_argument(
74
+ "--kubeconfig",
75
+ type=valid_file,
76
+ help="Path to kubeconfig file"
77
+ )
78
+
79
+ parser.add_argument(
80
+ "--version",
81
+ action="version",
82
+ version=f"%(prog)s {get_app_version()}"
83
+ )
84
+
85
+ valid_args = ["--kubeconfig"]
86
+ for action in parser._actions:
87
+ valid_args.extend(action.option_strings)
88
+
89
+ args, unknown = parser.parse_known_args()
90
+
91
+ if unknown:
92
+ for arg in unknown:
93
+ if arg.startswith("--"):
94
+ suggestion = difflib.get_close_matches(arg, valid_args, n=1)
95
+ if suggestion:
96
+ parser.error(
97
+ f"unknown argument: {arg}\nDid you mean {suggestion[0]}?"
98
+ )
99
+ else:
100
+ parser.error(f"unknown argument: {arg}")
101
+ return
102
+
103
+ return args.kubeconfig
104
+
105
+
106
+ def valid_file(path: str) -> str:
107
+ if not os.path.exists(path):
108
+ raise argparse.ArgumentTypeError(f"Path does not exist: {path}")
109
+ if not os.path.isfile(path):
110
+ raise argparse.ArgumentTypeError(f"Not a file: {path}")
111
+ valid, _ = Config().validate_config(path)
112
+ if not valid:
113
+ raise argparse.ArgumentTypeError(f"Invalid kubeconfig file: {path}")
114
+ return path
115
+
116
+
117
+ def run() -> None:
118
+ print(f"\033]0;kop\007", end="", flush=True)
119
+ kop = Kop(config_file=get_args())
120
+ kop.run()
121
+
122
+
123
+ if __name__ == "__main__":
124
+ run()