@@ -140,6 +140,36 @@ def parse_reference_expression(expression):
140
140
return PackageReference .parse (expression )
141
141
142
142
143
+ def get_cli_plugin_directory (command : str ) -> str :
144
+ """ Returns a plugins package directory for command group.
145
+
146
+ Args:
147
+ command: SONiC command: "show"/"config"/"clear".
148
+ Returns:
149
+ Path to plugins package directory.
150
+ """
151
+
152
+ pkg_loader = pkgutil .get_loader (f'{ command } .plugins' )
153
+ if pkg_loader is None :
154
+ raise PackageManagerError (f'Failed to get plugins path for { command } CLI' )
155
+ plugins_pkg_path = os .path .dirname (pkg_loader .path )
156
+ return plugins_pkg_path
157
+
158
+
159
+ def get_cli_plugin_path (package : Package , command : str ) -> str :
160
+ """ Returns a path where to put CLI plugin code.
161
+
162
+ Args:
163
+ package: Package to generate this path for.
164
+ command: SONiC command: "show"/"config"/"clear".
165
+ Returns:
166
+ Path generated for this package.
167
+ """
168
+
169
+ plugin_module_file = package .name + '.py'
170
+ return os .path .join (get_cli_plugin_directory (command ), plugin_module_file )
171
+
172
+
143
173
def validate_package_base_os_constraints (package : Package , sonic_version_info : Dict [str , str ]):
144
174
""" Verify that all dependencies on base OS components are met.
145
175
Args:
@@ -917,18 +947,6 @@ def _systemctl_action(self, package: Package, action: str):
917
947
for npu in range (self .num_npus ):
918
948
run_command (f'systemctl { action } { name } @{ npu } ' )
919
949
920
- @staticmethod
921
- def _get_cli_plugin_name (package : Package ):
922
- return utils .make_python_identifier (package .name ) + '.py'
923
-
924
- @classmethod
925
- def _get_cli_plugin_path (cls , package : Package , command ):
926
- pkg_loader = pkgutil .get_loader (f'{ command } .plugins' )
927
- if pkg_loader is None :
928
- raise PackageManagerError (f'Failed to get plugins path for { command } CLI' )
929
- plugins_pkg_path = os .path .dirname (pkg_loader .path )
930
- return os .path .join (plugins_pkg_path , cls ._get_cli_plugin_name (package ))
931
-
932
950
def _install_cli_plugins (self , package : Package ):
933
951
for command in ('show' , 'config' , 'clear' ):
934
952
self ._install_cli_plugin (package , command )
@@ -941,14 +959,14 @@ def _install_cli_plugin(self, package: Package, command: str):
941
959
image_plugin_path = package .manifest ['cli' ][command ]
942
960
if not image_plugin_path :
943
961
return
944
- host_plugin_path = self . _get_cli_plugin_path (package , command )
962
+ host_plugin_path = get_cli_plugin_path (package , command )
945
963
self .docker .extract (package .entry .image_id , image_plugin_path , host_plugin_path )
946
964
947
965
def _uninstall_cli_plugin (self , package : Package , command : str ):
948
966
image_plugin_path = package .manifest ['cli' ][command ]
949
967
if not image_plugin_path :
950
968
return
951
- host_plugin_path = self . _get_cli_plugin_path (package , command )
969
+ host_plugin_path = get_cli_plugin_path (package , command )
952
970
if os .path .exists (host_plugin_path ):
953
971
os .remove (host_plugin_path )
954
972
0 commit comments