Skip to content

Commit 2c5eebb

Browse files
committed
Accept now any of CoreCli options on Python3Shell constructor
Signed-off-by: Estevan Vedovelli <evedovelli@gmail.com>
1 parent 8c5793d commit 2c5eebb

2 files changed

Lines changed: 29 additions & 18 deletions

File tree

climatic_python/Python3Shell.py

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from climatic.CoreCli import CoreCli
44
from climatic.connections.Ssh import Ssh, PTY_WINSIZE_COLS
5+
from typing import List, Optional
56

67

78
####################################################################################################
@@ -11,23 +12,21 @@ class Python3Shell(CoreCli):
1112
""" Extend CoreCli with Python3Shell customizations.
1213
"""
1314

14-
def run(self, cmds: str, **run_opts):
15-
""" Execute Python3 commands
16-
17-
@param cmds A multi-line string with commands to be executed.
18-
@param run_opts Same options as CoreCli run method.
15+
def __init__(self, connection, **opts):
16+
""" Initialize OcNOS CLI.
17+
@param connection The connection object to be used for accessing the CLI.
18+
@param opts Same options as CoreCli initializer.
1919
"""
20-
if not 'marker' in run_opts:
21-
run_opts['marker'] = '>>>|...'
22-
23-
if not 'error_marker' in run_opts:
24-
run_opts['error_marker'] = 'Error'
25-
26-
if not 'strip_cmds' in run_opts:
27-
run_opts['strip_cmds'] = False
28-
29-
return super(Python3Shell, self).run(cmds, **run_opts)
20+
if not 'marker' in opts:
21+
self.marker = '>>>|...'
22+
if not 'error_marker' in opts:
23+
self.error_marker = 'Error'
24+
if not 'strip_cmds' in opts:
25+
self.strip_cmds = False
3026

27+
CoreCli.__init__(self,
28+
connection,
29+
**opts)
3130

3231
####################################################################################################
3332
## SshPython3Shell
@@ -37,19 +36,31 @@ class SshPython3Shell(Python3Shell):
3736
Core implementation is done by Ssh and Python3Shell.
3837
"""
3938

40-
def __init__(self, ip: str, username: str, password: str, port=22, sh_markers=['#', '>']):
39+
def __init__(self,
40+
ip: str,
41+
username: str,
42+
password: str,
43+
port: Optional[int]=22,
44+
sh_markers: Optional[List[str]]=['#', '>'],
45+
**opts):
4146
""" Initialize Python3 Shell.
4247
@param ip IP address of target. Ex: '234.168.10.12'
4348
@param username username for opening SSH connection
4449
@param password password for authentication in SSH connection
4550
@param port Port used for SSH connection. Defaults to 22
4651
@param sh_markers List of accepted markers for the shell when the SSH is established and
4752
before launching python3 interpreter
53+
@param opts Same options as CoreCli initializer.
4854
"""
4955
self.sh_markers = sh_markers
5056
self.name = "Python3.SSH"
5157
ssh = Ssh(ip, username, port=port)
52-
Python3Shell.__init__(self, ssh, username=username, password=password, pty_winsize_cols=PTY_WINSIZE_COLS)
58+
Python3Shell.__init__(self,
59+
ssh,
60+
username=username,
61+
password=password,
62+
pty_winsize_cols=PTY_WINSIZE_COLS,
63+
**opts)
5364

5465
def login(self):
5566
""" Login to CLI interface.

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = climatic_python
3-
version = 0.0.1
3+
version = 0.0.2
44
author = Estevan Vedovelli
55
author_email = evedovelli@gmail.com
66
description = Tool to ease and automate CLI usage

0 commit comments

Comments
 (0)