Skip to content

Commit a135ca3

Browse files
author
Brian Russell
committed
Correcting linting issues
1 parent 302028c commit a135ca3

File tree

1 file changed

+32
-17
lines changed

1 file changed

+32
-17
lines changed

examples/python_client_library/file_operations.py

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Demonstrates creating writing, and deleting files/ folders on a NetApp volume.
2+
"""
13
import logging
24
from netapp_ontap import NetAppRestError
35
from netapp_ontap.resources import Volume
@@ -15,13 +17,13 @@
1517
def list_files(volume, path):
1618
"""Recursively list files on a volume"""
1719
files = FileInfo.get_collection(volume.uuid, path)
18-
for f in files:
19-
if f.name != "." and f.name != "..":
20-
if f.type == "file":
21-
print(f"{path}{f.name}")
22-
elif f.type == "directory" and f.name != ".snapshot":
23-
print(f"{path}{f.name}/")
24-
list_files(volume, f"{path}{f.name}/")
20+
for file_info in files:
21+
if file_info.name not in (".", ".."):
22+
if file_info.type == "file":
23+
print(f"{path}{file_info.name}")
24+
elif file_info.type == "directory" and file_info.name != ".snapshot":
25+
print(f"{path}{file_info.name}/")
26+
list_files(volume, f"{path}{file_info.name}/")
2527

2628

2729
def delete(volume, pathname, recursive=False):
@@ -34,8 +36,8 @@ def delete(volume, pathname, recursive=False):
3436
extra = "(recursively) "
3537
else:
3638
extra = ""
37-
logging.critical(
38-
f"delete: File or directory {pathname} was not deleted {extra}on {volume.name} ({error})")
39+
message = f"delete: File or dir {pathname} wasn't deleted {extra}on {volume.name} ({error})"
40+
logging.critical(message)
3941

4042

4143
def create_directory(volume, pathname):
@@ -46,22 +48,35 @@ def create_directory(volume, pathname):
4648
try:
4749
resource.post()
4850
except NetAppRestError as error:
49-
logging.critical(
50-
f"create_directory: Directory {pathname} was not created on {volume.name} ({error})")
51+
message = f"create_directory: dir {pathname} wasn't created on {volume.name} ({error})"
52+
logging.critical(message)
5153

5254

53-
def create_file(volume, pathname, contents):
55+
def create_file(volume, pathname, contents=""):
56+
"""Create a file on a volume
57+
58+
Args:
59+
volume (string): volume object to create file on
60+
pathname (string): path to file that is to be created
61+
contents (string): contents of file to be written
62+
"""
5463
try:
5564
resource = FileInfo(volume.uuid, pathname)
5665
resource.post(
57-
hydrate=True, data="the data to be written to the new file")
66+
hydrate=True, data=contents)
5867
resource.patch()
5968
except NetAppRestError as error:
60-
logging.critical(
61-
f"create_file: File {pathname} was not created on {volume.name} ({error})")
69+
message = f"create_file: File {pathname} was not created on {volume.name} ({error})"
70+
logging.critical(message)
6271

6372

6473
def file_handling(volume_name):
74+
"""Demonstrate file handling on NetApp
75+
Writes some files and directories to the volume then cleans up what it has written
76+
Note: Does not check for existing content.
77+
Args:
78+
volume_name (string): Volume name to us
79+
"""
6580
try:
6681
all_volumes = list(Volume.get_collection(name=volume_name))
6782
for vol in all_volumes:
@@ -96,7 +111,7 @@ def main() -> None:
96111
Argument("-c", "--cluster", "API server IP:port details"),
97112
Argument("-v", "--volume_name", "Volume Name")]
98113
args = parse_args(
99-
"This script will demonstrate enumerating volumes, file and directory creation, file and directory creation deletion",
114+
"Demonstrates file and directory creation, file and directory creation deletion",
100115
arguments,
101116
)
102117

@@ -105,4 +120,4 @@ def main() -> None:
105120

106121

107122
if __name__ == "__main__":
108-
main()
123+
main()

0 commit comments

Comments
 (0)