Skip to content

Commit 06e86fd

Browse files
IsaacVReyrichp405fernandofloresg
authored
[Documentation][backup] Add and standarize docstrings on module-utils/backup.py (#1384)
* Modify google style docstrings to numpy * Add changelog fragment * Update backup.py Added ending linefeed to address pep8 issue * Update backup.py fix pep8 (extra whitespace at end of file) * modified docstring --------- Co-authored-by: Rich Parker <[email protected]> Co-authored-by: Fernando Flores <[email protected]>
1 parent 3fa4697 commit 06e86fd

File tree

2 files changed

+134
-41
lines changed

2 files changed

+134
-41
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
trivial:
2+
- backup - Updated docstrings to numpy style for visual aid to developers.
3+
(https://github.com/ansible-collections/ibm_zos_core/pull/1384).

plugins/module_utils/backup.py

Lines changed: 131 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,46 @@
5151

5252

5353
def _validate_data_set_name(ds):
54+
"""Validate data set name.
55+
56+
Parameters
57+
----------
58+
ds : str
59+
The source dataset.
60+
61+
Returns
62+
-------
63+
str
64+
Parsed dataset.
65+
"""
5466
arg_defs = dict(ds=dict(arg_type="data_set"))
5567
parser = BetterArgParser(arg_defs)
5668
parsed_args = parser.parse_args({"ds": ds})
5769
return parsed_args.get("ds")
5870

5971

6072
def mvs_file_backup(dsn, bk_dsn=None, tmphlq=None):
61-
"""Create a backup data set for an MVS data set
62-
63-
Arguments:
64-
dsn {str} -- The name of the data set to backup.
65-
It could be an MVS PS/PDS/PDSE/VSAM(KSDS), etc.
66-
bk_dsn {str} -- The name of the backup data set.
67-
68-
Raises:
69-
BackupError: When backup data set exists.
70-
BackupError: When creation of backup data set fails.
73+
"""Create a backup data set for an MVS data set.
74+
75+
Parameters
76+
----------
77+
dsn : str
78+
The name of the data set to backup.
79+
It could be an MVS PS/PDS/PDSE/VSAM(KSDS), etc.
80+
bk_dsn : str
81+
The name of the backup data set.
82+
83+
Returns
84+
-------
85+
str
86+
The backup dataset
87+
88+
Raises
89+
------
90+
BackupError
91+
When backup data set exists.
92+
BackupError
93+
When creation of backup data set fails.
7194
"""
7295
dsn = _validate_data_set_name(dsn).upper()
7396
if is_member(dsn):
@@ -98,7 +121,7 @@ def mvs_file_backup(dsn, bk_dsn=None, tmphlq=None):
98121

99122
# In case the backup ds is a member we trust that the PDS attributes are ok to fit the src content.
100123
# This should not delete a PDS just to create a backup member.
101-
# Otherwise, we allocate the appropiate space for the backup ds based on src.
124+
# Otherwise, we allocate the appropriate space for the backup ds based on src.
102125
if is_member(bk_dsn):
103126
try:
104127
cp_rc = datasets.copy(dsn, bk_dsn)
@@ -122,20 +145,29 @@ def mvs_file_backup(dsn, bk_dsn=None, tmphlq=None):
122145

123146

124147
def uss_file_backup(path, backup_name=None, compress=False):
125-
"""Create a backup file for a USS file or path
126-
127-
Arguments:
128-
path {str} -- The name of the USS file or path to backup.
129-
backup_name {str} -- The name of the backup file.
130-
131-
Keyword Arguments:
132-
compress {bool} -- Determines if the backup be compressed. (default: {False})
133-
134-
Raises:
135-
BackupError: When creating compressed backup fails.
136-
137-
Returns:
138-
str -- Name of the backup file.
148+
"""Create a backup file for a USS file or path.
149+
150+
Parameters
151+
----------
152+
path : str
153+
The name of the USS file or path to backup.
154+
backup_name : str
155+
The name of the backup file.
156+
157+
Keyword Parameters
158+
------------------
159+
compress : bool
160+
Determines if the backup be compressed. (default: {False})
161+
162+
Returns
163+
-------
164+
str
165+
Name of the backup file.
166+
167+
Raises
168+
------
169+
BackupError
170+
When creating compressed backup fails.
139171
"""
140172
abs_path = os.path.abspath(path)
141173

@@ -188,14 +220,24 @@ def uss_file_backup(path, backup_name=None, compress=False):
188220

189221

190222
def _copy_ds(ds, bk_ds):
191-
"""Copy the contents of a data set to another
192-
193-
Arguments:
194-
ds {str} -- The source data set to be copied from. Should be SEQ or VSAM
195-
bk_dsn {str} -- The destination data set to copy to.
196-
197-
Raises:
198-
BackupError: When copying data fails
223+
"""Copy the contents of a data set to another.
224+
225+
Parameters
226+
----------
227+
ds : str
228+
The source data set to be copied from. Should be SEQ or VSAM.
229+
bk_dsn : str
230+
The destination data set to copy to.
231+
232+
Returns
233+
-------
234+
int
235+
Return code.
236+
237+
Raises
238+
------
239+
BackupError
240+
When copying data fails.
199241
"""
200242
module = AnsibleModuleHelper(argument_spec={})
201243
_allocate_model(bk_ds, ds)
@@ -220,14 +262,24 @@ def _copy_ds(ds, bk_ds):
220262

221263

222264
def _allocate_model(ds, model):
223-
"""Allocate a data set using allocation information of a model data set
224-
225-
Arguments:
226-
ds {str} -- The name of the data set to be allocated.
227-
model {str} -- The name of the data set whose allocation parameters should be used.
228-
229-
Raises:
230-
BackupError: When allocation fails
265+
"""Allocate a data set using allocation information of a model data set.
266+
267+
Parameters
268+
----------
269+
ds : str
270+
The name of the data set to be allocated.
271+
model : str
272+
The name of the data set whose allocation parameters should be used.
273+
274+
Returns
275+
-------
276+
int
277+
Return code.
278+
279+
Raises
280+
------
281+
BackupError
282+
When allocation fails.
231283
"""
232284
module = AnsibleModuleHelper(argument_spec={})
233285
alloc_cmd = """ ALLOC -
@@ -247,13 +299,51 @@ def _allocate_model(ds, model):
247299

248300

249301
def _copy_pds(ds, bk_dsn):
302+
"""Copy a dataset.
303+
304+
Parameters
305+
----------
306+
ds : str
307+
The name of the data set to be allocated.
308+
bk_dsn : str
309+
The destination data set to copy to.
310+
311+
Returns
312+
-------
313+
str
314+
Copied dataset.
315+
"""
250316
dds = dict(OUTPUT=bk_dsn, INPUT=ds)
251317
copy_cmd = " COPY OUTDD=OUTPUT,INDD=((INPUT,R))"
252318
return iebcopy(copy_cmd, dds=dds)
253319

254320

255321
class BackupError(Exception):
256322
def __init__(self, message, rc=None, stdout=None, stderr=None):
323+
"""Error during backup.
324+
325+
Parameters
326+
----------
327+
message : str
328+
Human readable string describing the exception.
329+
rc : int
330+
Return code.
331+
stdout : str
332+
Standard output.
333+
stderr : str
334+
Standard error.
335+
336+
Attributes
337+
----------
338+
msg : str
339+
Human readable string describing the exception.
340+
rc : int
341+
Return code.
342+
stdout : str
343+
Standard output.
344+
stderr : str
345+
Standard error.
346+
"""
257347
self.msg = 'An error occurred during backup: "{0}"'.format(message)
258348
self.rc = rc
259349
self.stdout = stdout

0 commit comments

Comments
 (0)