Skip to content

Commit 2b79dc0

Browse files
committed
Prepare 1.0
* Remove deprecated * fix docs * fix exceptions hierarchy * paramiko>=2.4 & support of passphrase for keyfiles * align requirements
1 parent ac16876 commit 2b79dc0

12 files changed

+283
-160
lines changed

Diff for: doc/source/ExecResult.rst

+13-10
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,20 @@ API: ExecResult
66
.. py:module:: exec_helpers
77
.. py:currentmodule:: exec_helpers
88
9-
.. py:class:: ExecResult(cmd, stdout=None, stderr=None, exit_code=proc_enums.ExitCodes.EX_INVALID)
9+
.. py:class:: ExecResult(object)
1010
1111
Command execution result.
1212

13-
:param cmd: command
14-
:type cmd: ``str``
15-
:param stdout: binary STDOUT
16-
:type stdout: ``typing.Optional[typing.Iterable[bytes]]``
17-
:param stderr: binary STDERR
18-
:type stderr: ``typing.Optional[typing.Iterable[bytes]]``
19-
:param exit_code: Exit code. If integer - try to convert to BASH enum.
20-
:type exit_code: ``typing.Union[int, proc_enums.ExitCodes]``
13+
.. py:method:: __init__(cmd, stdout=None, stderr=None, exit_code=ExitCodes.EX_INVALID)
14+
15+
:param cmd: command
16+
:type cmd: ``str``
17+
:param stdout: binary STDOUT
18+
:type stdout: ``typing.Optional[typing.Iterable[bytes]]``
19+
:param stderr: binary STDERR
20+
:type stderr: ``typing.Optional[typing.Iterable[bytes]]``
21+
:param exit_code: Exit code. If integer - try to convert to BASH enum.
22+
:type exit_code: typing.Union[int, ExitCodes]
2123

2224
.. py:attribute:: lock
2325
@@ -76,9 +78,10 @@ API: ExecResult
7678

7779
.. py:attribute:: exit_code
7880
79-
``typing.Union[int, proc_enums.ExitCodes]``
8081
Return(exit) code of command.
8182

83+
:rtype: typing.Union[int, ExitCodes]
84+
8285
.. py:attribute:: stdout_json
8386
8487
``typing.Any``

Diff for: doc/source/SSHClient.rst

+71-29
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,24 @@ API: SSHClient and SSHAuth.
66
.. py:module:: exec_helpers
77
.. py:currentmodule:: exec_helpers
88
9-
.. py:class:: SSHClient(host, port=22, username=None, password=None, private_keys=None, auth=None, )
9+
.. py:class:: SSHClient
1010
1111
SSHClient helper.
1212

13-
:param host: remote hostname
14-
:type host: ``str``
15-
:param port: remote ssh port
16-
:type port: ``int``
17-
:param username: remote username.
18-
:type username: ``typing.Optional[str]``
19-
:param password: remote password
20-
:type password: ``typing.Optional[str]``
21-
:param private_keys: private keys for connection
22-
:type private_keys: ``typing.Optional[typing.Iterable[paramiko.RSAKey]]``
23-
:param auth: credentials for connection
24-
:type auth: ``typing.Optional[SSHAuth]``
13+
.. py:method:: __init__(host, port=22, username=None, password=None, private_keys=None, auth=None, )
14+
15+
:param host: remote hostname
16+
:type host: ``str``
17+
:param port: remote ssh port
18+
:type port: ``int``
19+
:param username: remote username.
20+
:type username: ``typing.Optional[str]``
21+
:param password: remote password
22+
:type password: ``typing.Optional[str]``
23+
:param private_keys: private keys for connection
24+
:type private_keys: ``typing.Optional[typing.Iterable[paramiko.RSAKey]]``
25+
:param auth: credentials for connection
26+
:type auth: typing.Optional[SSHAuth]
2527

2628
.. note:: auth has priority over username/password/private_keys
2729

@@ -37,9 +39,10 @@ API: SSHClient and SSHAuth.
3739

3840
.. py:attribute:: auth
3941
40-
``SSHAuth``
4142
Internal authorisation object
4243

44+
:rtype: SSHAuth
45+
4346
.. py:attribute:: hostname
4447
4548
``str``
@@ -72,6 +75,16 @@ API: SSHClient and SSHAuth.
7275
7376
Reconnect SSH session
7477

78+
.. py:method:: __enter__()
79+
80+
Open context manager
81+
82+
.. py:method:: __exit__(self, exc_type, exc_val, exc_tb)
83+
84+
Close context manager and disconnect
85+
86+
.. versionchanged:: 1.0 - disconnect enforced on close
87+
7588
.. py:method:: sudo(enforce=None)
7689
7790
Context manager getter for sudo operation
@@ -99,7 +112,7 @@ API: SSHClient and SSHAuth.
99112
:type verbose: ``bool``
100113
:param timeout: Timeout for command execution.
101114
:type timeout: ``typing.Optional[int]``
102-
:rtype: ``ExecResult``
115+
:rtype: ExecResult
103116
:raises: ExecHelperTimeoutError
104117

105118
.. py:method:: check_call(command, verbose=False, timeout=None, error_info=None, expected=None, raise_on_err=True, **kwargs)
@@ -118,7 +131,7 @@ API: SSHClient and SSHAuth.
118131
:type expected: ``typing.Optional[typing.Iterable[int]]``
119132
:param raise_on_err: Raise exception on unexpected return code
120133
:type raise_on_err: ``bool``
121-
:rtype: ``ExecResult``
134+
:rtype: ExecResult
122135
:raises: CalledProcessError
123136

124137
.. py:method:: check_stderr(command, verbose=False, timeout=None, error_info=None, raise_on_err=True, **kwargs)
@@ -135,7 +148,7 @@ API: SSHClient and SSHAuth.
135148
:type error_info: ``typing.Optional[str]``
136149
:param raise_on_err: Raise exception on unexpected return code
137150
:type raise_on_err: ``bool``
138-
:rtype: ``ExecResult``
151+
:rtype: ExecResult
139152
:raises: CalledProcessError
140153

141154
.. note:: expected return codes can be overridden via kwargs.
@@ -149,7 +162,7 @@ API: SSHClient and SSHAuth.
149162
:param command: Command for execution
150163
:type command: ``str``
151164
:param auth: credentials for target machine
152-
:type auth: ``typing.Optional[SSHAuth]``
165+
:type auth: typing.Optional[SSHAuth]
153166
:param target_port: target port
154167
:type target_port: ``int``
155168
:param verbose: Produce log.info records for command call and output
@@ -158,7 +171,7 @@ API: SSHClient and SSHAuth.
158171
:type timeout: ``typing.Optional[int]``
159172
:param get_pty: open PTY on target machine
160173
:type get_pty: ``bool``
161-
:rtype: ``ExecResult``
174+
:rtype: ExecResult
162175
:raises: ExecHelperTimeoutError
163176

164177
.. py:classmethod:: execute_together(remotes, command, timeout=None, expected=None, raise_on_err=True, **kwargs)
@@ -176,7 +189,7 @@ API: SSHClient and SSHAuth.
176189
:param raise_on_err: Raise exception on unexpected return code
177190
:type raise_on_err: ``bool``
178191
:return: dictionary {(hostname, port): result}
179-
:rtype: ``typing.Dict[typing.Tuple[str, int], exec_result.ExecResult]``
192+
:rtype: typing.Dict[typing.Tuple[str, int], ExecResult]
180193
:raises: ParallelCallProcessError
181194
:raises: ParallelCallExceptions
182195

@@ -201,6 +214,17 @@ API: SSHClient and SSHAuth.
201214
:type path: ``str``
202215
:rtype: ``paramiko.sftp_attr.SFTPAttributes``
203216

217+
.. py:method:: utime(path, times=None):
218+
219+
Set atime, mtime.
220+
221+
:param path: filesystem object path
222+
:type path: str
223+
:param times: (atime, mtime)
224+
:type times: typing.Optional[typing.Tuple[int, int]]
225+
226+
.. versionadded:: 1.0.0
227+
204228
.. py:method:: isfile(path)
205229
206230
Check, that path is file using SFTP session.
@@ -215,6 +239,8 @@ API: SSHClient and SSHAuth.
215239
:type path: ``str``
216240
:rtype: ``bool``
217241

242+
**Non standard methods:**
243+
218244
.. py:method:: mkdir(path)
219245
220246
run 'mkdir -p path' on remote.
@@ -244,22 +270,31 @@ API: SSHClient and SSHAuth.
244270
:rtype: ``bool``
245271

246272

247-
.. py:class:: SSHAuth(username=None, password=None, key=None, keys=None, )
273+
.. py:class:: SSHAuth(object)
248274
249275
SSH credentials object.
250276

251277
Used to authorize SSHClient.
252278
Single SSHAuth object is associated with single host:port.
253279
Password and key is private, other data is read-only.
254280

255-
:param username: remote username.
256-
:type username: ``typing.Optional[str]``
257-
:param password: remote password
258-
:type password: ``typing.Optional[str]``
259-
:param key: Main connection key
260-
:type key: ``typing.Optional[paramiko.RSAKey]``
261-
:param keys: Alternate connection keys
262-
:type keys: ``typing.Optional[typing.Iterable[paramiko.RSAKey]]``
281+
.. py:method:: __init__(username=None, password=None, key=None, keys=None, )
282+
283+
:param username: remote username.
284+
:type username: ``typing.Optional[str]``
285+
:param password: remote password
286+
:type password: ``typing.Optional[str]``
287+
:param key: Main connection key
288+
:type key: ``typing.Optional[paramiko.RSAKey]``
289+
:param keys: Alternate connection keys
290+
:type keys: ``typing.Optional[typing.Iterable[paramiko.RSAKey]]``
291+
:param key_filename: filename(s) for additional key files
292+
:type key_filename: ``typing.Union[typing.List[str], str, None]``
293+
:param passphrase: passphrase for keys. Need, if differs from password
294+
:type passphrase: ``typing.Optional[str]``
295+
296+
.. versionchanged:: 1.0
297+
added: key_filename, passphrase arguments
263298

264299
.. py:attribute:: username
265300
@@ -270,6 +305,13 @@ API: SSHClient and SSHAuth.
270305
``typing.Optional[str]``
271306
public key for stored private key if presents else None
272307

308+
.. py:attribute:: key_filename
309+
310+
``typing.Union[typing.List[str], str, None]``
311+
Key filename(s).
312+
313+
.. versionadded:: 1.0
314+
273315
.. py:method:: enter_password(self, tgt)
274316
Enter password to STDIN.
275317

Diff for: doc/source/Subprocess.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ API: Subprocess
1818
:type verbose: ``bool``
1919
:param timeout: Timeout for command execution.
2020
:type timeout: ``typing.Optional[int]``
21-
:rtype: ``ExecResult``
21+
:rtype: ExecResult
2222
:raises: ExecHelperTimeoutError
2323

2424
.. py:classmethod:: check_call(command, verbose=False, timeout=None, error_info=None, expected=None, raise_on_err=True, **kwargs)
@@ -37,7 +37,7 @@ API: Subprocess
3737
:type expected: ``typing.Optional[typing.Iterable[int]]``
3838
:param raise_on_err: Raise exception on unexpected return code
3939
:type raise_on_err: ``bool``
40-
:rtype: ``ExecResult``
40+
:rtype: ExecResult
4141
:raises: CalledProcessError
4242

4343
.. py:classmethod:: check_stderr(command, verbose=False, timeout=None, error_info=None, raise_on_err=True, **kwargs)
@@ -54,7 +54,7 @@ API: Subprocess
5454
:type error_info: ``typing.Optional[str]``
5555
:param raise_on_err: Raise exception on unexpected return code
5656
:type raise_on_err: ``bool``
57-
:rtype: ``ExecResult``
57+
:rtype: ExecResult
5858
:raises: CalledProcessError
5959

6060
.. note:: expected return codes can be overridden via kwargs.

Diff for: doc/source/exceptions.rst

+44-34
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,34 @@ API: exceptions
66
.. py:module:: exec_helpers
77
.. py:currentmodule:: exec_helpers
88
9-
.. py:exception:: ExecHelperError
9+
.. py:exception:: ExecHelperError(Exception)
1010
1111
Base class for all exceptions raised inside.
1212

13-
.. py:exception:: ExecHelperTimeoutError
13+
.. py:exception:: ExecHelperTimeoutError(ExecHelperError)
1414
1515
Execution timeout.
1616

17-
.. py:exception:: ExecCalledProcessError
17+
.. py:exception:: ExecCalledProcessError(ExecHelperError)
1818
1919
Base class for process call errors.
2020

21-
.. py:exception:: CalledProcessError(command, returncode, expected=None, stdout=None, stderr=None)
21+
.. py:exception:: CalledProcessError(ExecCalledProcessError)
2222
2323
Exception for error on process calls.
2424

25-
:param command: command
26-
:type command: str
27-
:param returncode: return code
28-
:type returncode: typing.Union[int, proc_enums.ExitCodes]
29-
:param expected: expected return codes
30-
:type expected: typing.Optional[typing.List[typing.Union[int, proc_enums.ExitCodes]]]
31-
:param stdout: stdout string or brief string
32-
:type stdout: typing.Any
33-
:param stderr: stderr string or brief string
34-
:type stderr: typing.Any
25+
.. py:method:: __init__(command, returncode, expected=None, stdout=None, stderr=None)
26+
27+
:param command: command
28+
:type command: str
29+
:param returncode: return code
30+
:type returncode: typing.Union[int, proc_enums.ExitCodes]
31+
:param expected: expected return codes
32+
:type expected: typing.Optional[typing.List[typing.Union[int, proc_enums.ExitCodes]]]
33+
:param stdout: stdout string or brief string
34+
:type stdout: typing.Any
35+
:param stderr: stderr string or brief string
36+
:type stderr: typing.Any
3537

3638
.. py:attribute:: cmd
3739
@@ -58,20 +60,24 @@ API: exceptions
5860
``typing.Any``
5961
stdout string or brief string
6062

61-
.. py:exception:: ParallelCallExceptions(command, exceptions, errors, results, expected=None, )
63+
.. py:exception:: ParallelCallExceptions(ExecCalledProcessError)
6264
6365
Exception raised during parallel call as result of exceptions.
6466

65-
:param command: command
66-
:type command: ``str``
67-
:param exceptions: Exception on connections
68-
:type exceptions: ``typing.Dict[typing.Tuple[str, int], Exception]``
69-
:param errors: results with errors
70-
:type errors: ``typing.Dict[typing.Tuple[str, int], ExecResult]``
71-
:param results: all results
72-
:type results: ``typing.Dict[typing.Tuple[str, int], ExecResult]``
73-
:param expected: expected return codes
74-
:type expected: ``typing.Optional[typing.List[typing.List[typing.Union[int, proc_enums.ExitCodes]]]``
67+
.. py:method:: __init__(command, exceptions, errors, results, expected=None, )
68+
69+
:param command: command
70+
:type command: ``str``
71+
:param exceptions: Exception on connections
72+
:type exceptions: ``typing.Dict[typing.Tuple[str, int], Exception]``
73+
:param errors: results with errors
74+
:type errors: ``typing.Dict[typing.Tuple[str, int], ExecResult]``
75+
:param results: all results
76+
:type results: ``typing.Dict[typing.Tuple[str, int], ExecResult]``
77+
:param expected: expected return codes
78+
:type expected: ``typing.Optional[typing.List[typing.List[typing.Union[int, proc_enums.ExitCodes]]]``
79+
80+
.. versionchanged:: 1.0 - fixed inheritance
7581

7682
.. py:attribute:: cmd
7783
@@ -98,18 +104,22 @@ API: exceptions
98104
``typing.List[typing.Union[int, proc_enums.ExitCodes]]``
99105
expected return codes
100106

101-
.. py:exception:: ParallelCallProcessError(command, errors, results, expected=None, )
107+
.. py:exception:: ParallelCallProcessError(ExecCalledProcessError)
102108
103109
Exception during parallel execution.
104110

105-
:param command: command
106-
:type command: ``str``
107-
:param errors: results with errors
108-
:type errors: ``typing.Dict[typing.Tuple[str, int], ExecResult]``
109-
:param results: all results
110-
:type results: ``typing.Dict[typing.Tuple[str, int], ExecResult]``
111-
:param expected: expected return codes
112-
:type expected: ``typing.Optional[typing.List[typing.List[typing.Union[int, proc_enums.ExitCodes]]]``
111+
.. py:method:: __init__(command, errors, results, expected=None, )
112+
113+
:param command: command
114+
:type command: ``str``
115+
:param errors: results with errors
116+
:type errors: ``typing.Dict[typing.Tuple[str, int], ExecResult]``
117+
:param results: all results
118+
:type results: ``typing.Dict[typing.Tuple[str, int], ExecResult]``
119+
:param expected: expected return codes
120+
:type expected: ``typing.Optional[typing.List[typing.List[typing.Union[int, proc_enums.ExitCodes]]]``
121+
122+
.. versionchanged:: 1.0 - fixed inheritance
113123

114124
.. py:attribute:: cmd
115125

Diff for: doc/source/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Contents:
1414
Subprocess
1515
ExecResult
1616
exceptions
17+
proc_enums
1718

1819
Indices and tables
1920
==================

0 commit comments

Comments
 (0)