networka 0.1.9__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 (93) hide show
  1. network_toolkit/__about__.py +4 -0
  2. network_toolkit/__init__.py +8 -0
  3. network_toolkit/__main__.py +10 -0
  4. network_toolkit/builtin_sequences/arista_eos/common.yml +53 -0
  5. network_toolkit/builtin_sequences/mikrotik_routeros/common.yml +52 -0
  6. network_toolkit/cli.py +265 -0
  7. network_toolkit/commands/__init__.py +8 -0
  8. network_toolkit/commands/backup.py +441 -0
  9. network_toolkit/commands/complete.py +172 -0
  10. network_toolkit/commands/config.py +1068 -0
  11. network_toolkit/commands/diff.py +485 -0
  12. network_toolkit/commands/download.py +197 -0
  13. network_toolkit/commands/firmware.py +780 -0
  14. network_toolkit/commands/info.py +377 -0
  15. network_toolkit/commands/list.py +345 -0
  16. network_toolkit/commands/routerboard_upgrade.py +204 -0
  17. network_toolkit/commands/run.py +839 -0
  18. network_toolkit/commands/schema_unified.py +91 -0
  19. network_toolkit/commands/sequence.py +17 -0
  20. network_toolkit/commands/ssh.py +540 -0
  21. network_toolkit/commands/ssh_engines.py +0 -0
  22. network_toolkit/commands/ssh_fallback.py +97 -0
  23. network_toolkit/commands/ssh_platform.py +120 -0
  24. network_toolkit/commands/upload.py +237 -0
  25. network_toolkit/commands/vendor_config_backup.py +378 -0
  26. network_toolkit/common/color_magic.py +177 -0
  27. network_toolkit/common/command.py +135 -0
  28. network_toolkit/common/command_base.py +135 -0
  29. network_toolkit/common/command_helpers.py +214 -0
  30. network_toolkit/common/credentials.py +86 -0
  31. network_toolkit/common/defaults.py +17 -0
  32. network_toolkit/common/errors.py +130 -0
  33. network_toolkit/common/interactive_confirmation.py +144 -0
  34. network_toolkit/common/logging.py +47 -0
  35. network_toolkit/common/output.py +594 -0
  36. network_toolkit/common/output_clean.py +244 -0
  37. network_toolkit/common/paths.py +86 -0
  38. network_toolkit/common/resolver.py +207 -0
  39. network_toolkit/common/styles.py +199 -0
  40. network_toolkit/common/table_generator.py +169 -0
  41. network_toolkit/common/table_providers.py +716 -0
  42. network_toolkit/config.py +1506 -0
  43. network_toolkit/credentials.py +288 -0
  44. network_toolkit/device.py +1658 -0
  45. network_toolkit/device_transfers.py +170 -0
  46. network_toolkit/exceptions.py +78 -0
  47. network_toolkit/ip_device.py +241 -0
  48. network_toolkit/platforms/__init__.py +21 -0
  49. network_toolkit/platforms/base.py +267 -0
  50. network_toolkit/platforms/cisco_ios/__init__.py +6 -0
  51. network_toolkit/platforms/cisco_ios/constants.py +15 -0
  52. network_toolkit/platforms/cisco_ios/operations.py +426 -0
  53. network_toolkit/platforms/cisco_iosxe/__init__.py +6 -0
  54. network_toolkit/platforms/cisco_iosxe/constants.py +15 -0
  55. network_toolkit/platforms/cisco_iosxe/operations.py +580 -0
  56. network_toolkit/platforms/cisco_shared/__init__.py +0 -0
  57. network_toolkit/platforms/cisco_shared/operations.py +0 -0
  58. network_toolkit/platforms/factory.py +190 -0
  59. network_toolkit/platforms/mikrotik_routeros/__init__.py +8 -0
  60. network_toolkit/platforms/mikrotik_routeros/confirmation_patterns.py +24 -0
  61. network_toolkit/platforms/mikrotik_routeros/constants.py +31 -0
  62. network_toolkit/platforms/mikrotik_routeros/operations.py +686 -0
  63. network_toolkit/results_enhanced.py +364 -0
  64. network_toolkit/schemas/__init__.py +8 -0
  65. network_toolkit/sequence_manager.py +239 -0
  66. network_toolkit/shell_completion/bash_completion_nw.sh +339 -0
  67. network_toolkit/shell_completion/zsh_completion_nw.zsh +136 -0
  68. network_toolkit/transport/__init__.py +15 -0
  69. network_toolkit/transport/factory.py +113 -0
  70. network_toolkit/transport/interfaces.py +46 -0
  71. network_toolkit/transport/nornir_inventory.py +173 -0
  72. network_toolkit/transport/nornir_netmiko.py +277 -0
  73. network_toolkit/transport/scrapli_sync.py +36 -0
  74. network_toolkit/tui/__init__.py +18 -0
  75. network_toolkit/tui/app.py +1275 -0
  76. network_toolkit/tui/clipboard.py +46 -0
  77. network_toolkit/tui/compat.py +111 -0
  78. network_toolkit/tui/constants.py +111 -0
  79. network_toolkit/tui/controller.py +550 -0
  80. network_toolkit/tui/data.py +149 -0
  81. network_toolkit/tui/dialogs.py +196 -0
  82. network_toolkit/tui/helpers.py +55 -0
  83. network_toolkit/tui/keymap.py +31 -0
  84. network_toolkit/tui/layout.py +111 -0
  85. network_toolkit/tui/models.py +93 -0
  86. network_toolkit/tui/output_manager.py +372 -0
  87. network_toolkit/tui/prompt.py +172 -0
  88. network_toolkit/tui/services.py +285 -0
  89. networka-0.1.9.dist-info/METADATA +316 -0
  90. networka-0.1.9.dist-info/RECORD +93 -0
  91. networka-0.1.9.dist-info/WHEEL +4 -0
  92. networka-0.1.9.dist-info/entry_points.txt +2 -0
  93. networka-0.1.9.dist-info/licenses/LICENSE +73 -0
@@ -0,0 +1,199 @@
1
+ # SPDX-License-Identifier: MIT
2
+ """Centralized styling and theming system for Network Toolkit."""
3
+
4
+ from __future__ import annotations
5
+
6
+ from enum import Enum
7
+
8
+ from rich.console import Console
9
+ from rich.table import Table
10
+ from rich.theme import Theme
11
+
12
+ from network_toolkit.common.output import OutputMode
13
+
14
+
15
+ class StyleName(str, Enum):
16
+ """Semantic style names used throughout the application."""
17
+
18
+ # Core semantic styles
19
+ INFO = "info"
20
+ WARNING = "warning"
21
+ ERROR = "error"
22
+ SUCCESS = "success"
23
+
24
+ # Entity styles
25
+ DEVICE = "device"
26
+ HOST = "host"
27
+ PORT = "port"
28
+ PLATFORM = "platform"
29
+ GROUP = "group"
30
+ SEQUENCE = "sequence"
31
+ COMMAND = "command"
32
+ OUTPUT = "output"
33
+
34
+ # UI styles
35
+ SUMMARY = "summary"
36
+ DIM = "dim"
37
+ BOLD = "bold"
38
+ TRANSPORT = "transport"
39
+ RUNNING = "running"
40
+ CONNECTED = "connected"
41
+ FAILED = "failed"
42
+ DOWNLOADING = "downloading"
43
+ CREDENTIAL = "credential"
44
+ UNKNOWN = "unknown"
45
+
46
+
47
+ class StyleManager:
48
+ """Centralized style and theme management."""
49
+
50
+ def __init__(self, mode: OutputMode):
51
+ """Initialize style manager with output mode."""
52
+ self.mode = mode
53
+
54
+ # Theme definitions - must be defined before _create_console
55
+ self.themes = {
56
+ OutputMode.LIGHT: {
57
+ StyleName.INFO.value: "blue",
58
+ StyleName.WARNING.value: "dark_orange",
59
+ StyleName.ERROR.value: "red",
60
+ StyleName.SUCCESS.value: "green",
61
+ StyleName.DEVICE.value: "cyan",
62
+ StyleName.HOST.value: "blue",
63
+ StyleName.PORT.value: "blue",
64
+ StyleName.PLATFORM.value: "green",
65
+ StyleName.GROUP.value: "cyan",
66
+ StyleName.SEQUENCE.value: "magenta",
67
+ StyleName.COMMAND.value: "magenta",
68
+ StyleName.OUTPUT.value: "black", # Dark text for light background
69
+ StyleName.SUMMARY.value: "blue",
70
+ StyleName.DIM.value: "dim",
71
+ StyleName.BOLD.value: "bold blue",
72
+ StyleName.TRANSPORT.value: "purple",
73
+ StyleName.RUNNING.value: "blue",
74
+ StyleName.CONNECTED.value: "green",
75
+ StyleName.FAILED.value: "red",
76
+ StyleName.DOWNLOADING.value: "cyan",
77
+ StyleName.CREDENTIAL.value: "cyan",
78
+ StyleName.UNKNOWN.value: "yellow",
79
+ },
80
+ OutputMode.DARK: {
81
+ StyleName.INFO.value: "bright_blue",
82
+ StyleName.WARNING.value: "yellow",
83
+ StyleName.ERROR.value: "bright_red",
84
+ StyleName.SUCCESS.value: "bright_green",
85
+ StyleName.DEVICE.value: "bright_cyan",
86
+ StyleName.HOST.value: "cyan",
87
+ StyleName.PORT.value: "blue",
88
+ StyleName.PLATFORM.value: "green",
89
+ StyleName.GROUP.value: "bright_cyan",
90
+ StyleName.SEQUENCE.value: "bright_magenta",
91
+ StyleName.COMMAND.value: "bright_magenta",
92
+ StyleName.OUTPUT.value: "white", # Light text for dark background
93
+ StyleName.SUMMARY.value: "bright_blue",
94
+ StyleName.DIM.value: "dim",
95
+ StyleName.BOLD.value: "bold bright_white",
96
+ StyleName.TRANSPORT.value: "bright_magenta",
97
+ StyleName.RUNNING.value: "bright_blue",
98
+ StyleName.CONNECTED.value: "bright_green",
99
+ StyleName.FAILED.value: "bright_red",
100
+ StyleName.DOWNLOADING.value: "bright_cyan",
101
+ StyleName.CREDENTIAL.value: "bright_cyan",
102
+ StyleName.UNKNOWN.value: "bright_yellow",
103
+ },
104
+ OutputMode.DEFAULT: {
105
+ StyleName.INFO.value: "blue",
106
+ StyleName.WARNING.value: "yellow",
107
+ StyleName.ERROR.value: "red",
108
+ StyleName.SUCCESS.value: "green",
109
+ StyleName.DEVICE.value: "cyan",
110
+ StyleName.HOST.value: "cyan",
111
+ StyleName.PORT.value: "blue",
112
+ StyleName.PLATFORM.value: "green",
113
+ StyleName.GROUP.value: "cyan",
114
+ StyleName.SEQUENCE.value: "magenta",
115
+ StyleName.COMMAND.value: "magenta",
116
+ StyleName.OUTPUT.value: "default",
117
+ StyleName.SUMMARY.value: "blue",
118
+ StyleName.DIM.value: "dim",
119
+ StyleName.BOLD.value: "bold",
120
+ StyleName.TRANSPORT.value: "magenta",
121
+ StyleName.RUNNING.value: "blue",
122
+ StyleName.CONNECTED.value: "green",
123
+ StyleName.FAILED.value: "red",
124
+ StyleName.DOWNLOADING.value: "cyan",
125
+ StyleName.CREDENTIAL.value: "cyan",
126
+ StyleName.UNKNOWN.value: "yellow",
127
+ },
128
+ }
129
+
130
+ self._console = self._create_console()
131
+
132
+ def _create_console(self) -> Console:
133
+ """Create a console instance based on the current mode."""
134
+ if self.mode == OutputMode.RAW:
135
+ # Raw mode uses no styling at all
136
+ return Console(
137
+ color_system=None,
138
+ force_terminal=False,
139
+ stderr=False,
140
+ width=None,
141
+ height=None,
142
+ )
143
+ elif self.mode == OutputMode.NO_COLOR:
144
+ # No color mode disables colors but keeps other formatting
145
+ return Console(color_system=None, force_terminal=True, stderr=False)
146
+ else:
147
+ # Themed modes
148
+ theme_styles = self.themes.get(self.mode, self.themes[OutputMode.DEFAULT])
149
+ theme = Theme(theme_styles)
150
+ return Console(
151
+ theme=theme,
152
+ stderr=False,
153
+ force_terminal=True,
154
+ color_system="standard",
155
+ )
156
+
157
+ @property
158
+ def console(self) -> Console:
159
+ """Get the console instance."""
160
+ return self._console
161
+
162
+ def get_style(self, style_name: StyleName) -> str | None:
163
+ """Get the actual style string for a semantic style name.
164
+
165
+ Returns None for NO_COLOR and RAW modes to disable styling.
166
+ """
167
+ if self.mode in [OutputMode.NO_COLOR, OutputMode.RAW]:
168
+ return None
169
+
170
+ theme_styles = self.themes.get(self.mode, self.themes[OutputMode.DEFAULT])
171
+ return theme_styles.get(style_name.value)
172
+
173
+ def create_table(self, title: str = "") -> Table:
174
+ """Create a Rich Table with appropriate styling for the current mode."""
175
+ if self.mode in [OutputMode.NO_COLOR, OutputMode.RAW]:
176
+ # For no-color modes, create table without styling
177
+ return Table(title=title, show_header=True, show_lines=False)
178
+ else:
179
+ # For colored modes, use themed table
180
+ return Table(title=title)
181
+
182
+ def add_column(
183
+ self, table: Table, header: str, style_name: StyleName | None = None
184
+ ) -> None:
185
+ """Add a column to a table with appropriate styling."""
186
+ style = self.get_style(style_name) if style_name else None
187
+ table.add_column(header, style=style)
188
+
189
+ def format_message(self, message: str, style_name: StyleName) -> str:
190
+ """Format a message with semantic styling."""
191
+ if self.mode in [OutputMode.NO_COLOR, OutputMode.RAW]:
192
+ return message
193
+ else:
194
+ return f"[{style_name.value}]{message}[/{style_name.value}]"
195
+
196
+
197
+ def create_style_manager(mode: OutputMode) -> StyleManager:
198
+ """Create a style manager for the given output mode."""
199
+ return StyleManager(mode)
@@ -0,0 +1,169 @@
1
+ # SPDX-License-Identifier: MIT
2
+ """Centralized table generation system for Network Toolkit."""
3
+
4
+ from __future__ import annotations
5
+
6
+ from abc import ABC, abstractmethod
7
+ from typing import Protocol
8
+
9
+ from pydantic import BaseModel
10
+ from rich.table import Table
11
+
12
+ from network_toolkit.common.output import OutputManager, OutputMode
13
+ from network_toolkit.common.styles import StyleManager, StyleName
14
+
15
+
16
+ class TableColumn(BaseModel):
17
+ """Table column definition with semantic styling."""
18
+
19
+ header: str
20
+ style: StyleName | None = None
21
+ no_wrap: bool = False
22
+
23
+
24
+ class TableDefinition(BaseModel):
25
+ """Complete table definition with metadata."""
26
+
27
+ title: str
28
+ columns: list[TableColumn]
29
+ show_header: bool = True
30
+
31
+
32
+ class TableDataProvider(Protocol):
33
+ """Protocol for objects that can provide table data."""
34
+
35
+ def get_table_definition(self) -> TableDefinition:
36
+ """Get the table structure definition."""
37
+ ...
38
+
39
+ def get_table_rows(self) -> list[list[str]]:
40
+ """Get the table data rows."""
41
+ ...
42
+
43
+ def get_raw_output(self) -> str | None:
44
+ """Get raw mode output. Return None to use default raw formatting."""
45
+ ...
46
+
47
+ def get_verbose_info(self) -> list[str] | None:
48
+ """Get additional verbose information. Return None if no verbose info."""
49
+ ...
50
+
51
+
52
+ class TableGenerator:
53
+ """Centralized table generation with consistent styling and output modes."""
54
+
55
+ def __init__(self, style_manager: StyleManager, output_manager: OutputManager):
56
+ """Initialize table generator."""
57
+ self.style_manager = style_manager
58
+ self.output_manager = output_manager
59
+
60
+ def create_table(self, definition: TableDefinition) -> Table:
61
+ """Create a styled table from definition."""
62
+ table = self.style_manager.create_table(title=definition.title)
63
+
64
+ for column in definition.columns:
65
+ self.style_manager.add_column(
66
+ table, column.header, column.style if column.style else None
67
+ )
68
+
69
+ return table
70
+
71
+ def render_table(self, provider: TableDataProvider, verbose: bool = False) -> None:
72
+ """Generate and print table from data provider."""
73
+ # Handle raw mode
74
+ if self.output_manager.mode == OutputMode.RAW:
75
+ raw_output = provider.get_raw_output()
76
+ if raw_output:
77
+ # Provider has custom raw output
78
+ self.output_manager.print_output(raw_output.rstrip())
79
+ else:
80
+ # Generate default raw output
81
+ self._print_default_raw(provider)
82
+ return
83
+
84
+ # Handle normal table rendering
85
+ definition = provider.get_table_definition()
86
+ rows = provider.get_table_rows()
87
+
88
+ if not rows:
89
+ self.output_manager.print_text(
90
+ self.style_manager.format_message(definition.title, StyleName.BOLD)
91
+ )
92
+ self.output_manager.print_blank_line()
93
+ self.output_manager.print_text(
94
+ self.style_manager.format_message(
95
+ "No data available", StyleName.WARNING
96
+ )
97
+ )
98
+ return
99
+
100
+ # Display title
101
+ self.output_manager.print_text(
102
+ self.style_manager.format_message(definition.title, StyleName.BOLD)
103
+ )
104
+ self.output_manager.print_blank_line()
105
+
106
+ # Create and populate table
107
+ table = self.create_table(definition)
108
+ for row in rows:
109
+ table.add_row(*row)
110
+
111
+ # Print table
112
+ self.output_manager.print_table(table)
113
+ self.output_manager.print_blank_line()
114
+
115
+ # Print summary
116
+ self.output_manager.print_text(
117
+ self.style_manager.format_message(
118
+ f"Total items: {len(rows)}", StyleName.INFO
119
+ )
120
+ )
121
+
122
+ # Print verbose information if requested
123
+ if verbose:
124
+ verbose_info = provider.get_verbose_info()
125
+ if verbose_info:
126
+ self.output_manager.print_blank_line()
127
+ for info_line in verbose_info:
128
+ self.output_manager.print_text(info_line)
129
+
130
+ def _print_default_raw(self, provider: TableDataProvider) -> None:
131
+ """Print default raw mode output."""
132
+ definition = provider.get_table_definition()
133
+ rows = provider.get_table_rows()
134
+
135
+ if not rows:
136
+ return
137
+
138
+ # Simple key=value format for raw mode
139
+ for row in rows:
140
+ values: list[str] = []
141
+ for column, value in zip(definition.columns, row, strict=True):
142
+ # Convert header to lowercase key
143
+ key = column.header.lower().replace(" ", "_")
144
+ # Escape spaces and special chars in values
145
+ clean_value = str(value).replace(" ", "_").replace(",", ";")
146
+ values.append(f"{key}={clean_value}")
147
+ self.output_manager.print_output(" ".join(values))
148
+
149
+
150
+ class BaseTableProvider(ABC):
151
+ """Abstract base class for table data providers."""
152
+
153
+ @abstractmethod
154
+ def get_table_definition(self) -> TableDefinition:
155
+ """Get the table structure definition."""
156
+ ...
157
+
158
+ @abstractmethod
159
+ def get_table_rows(self) -> list[list[str]]:
160
+ """Get the table data rows."""
161
+ ...
162
+
163
+ def get_raw_output(self) -> str | None:
164
+ """Default implementation returns None for default raw formatting."""
165
+ return None
166
+
167
+ def get_verbose_info(self) -> list[str] | None:
168
+ """Default implementation returns None for no verbose info."""
169
+ return None