Skip to content

Commit 3511933

Browse files
committed
solve pylint issues and add result context to filesystem operations
1 parent 433008a commit 3511933

7 files changed

Lines changed: 34 additions & 21 deletions

File tree

cterasdk/core/ssl.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ class SSL(BaseCommand):
1111
Portal SSL Certificate APIs
1212
"""
1313

14-
def __init__(self, portal):
15-
super().__init__(portal)
16-
1714
def get(self):
1815
"""
1916
Retrieve details of the current installed SSL certificate
@@ -46,7 +43,8 @@ def export(self, destination=None):
4643
logging.getLogger('cterasdk.core').info('Exported SSL certificate. %s', {'filepath': filepath})
4744
return filepath
4845

49-
def create_zip_archive(self, private_key, *certificates):
46+
@staticmethod
47+
def create_zip_archive(private_key, *certificates):
5048
"""
5149
Create a ZIP archive that can be imported to CTERA Portal
5250
@@ -92,7 +90,7 @@ def import_from_chain(self, private_key, *certificates):
9290
:param str private_key: The PEM-encoded private key, or a path to the PEM-encoded private key file
9391
:param list[str] certificates: The PEM-encoded certificates, or a list of paths of the PEM-encoded certificate files
9492
"""
95-
zipflie = self.create_zip_archive(private_key, *certificates)
93+
zipflie = SSL.create_zip_archive(private_key, *certificates)
9694
return self.import_from_zip(zipflie)
9795

9896
def _import_certificate(self, zipfile):

cterasdk/edge/config.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
class Config(BaseCommand):
1717
""" Edge Filer General Configuration APIs """
1818

19-
def __init__(self, edge):
20-
super().__init__(edge)
21-
2219
def get_location(self):
2320
"""
2421
Get the location of the Edge Filer
@@ -67,7 +64,7 @@ def import_config(self, config, exclude=None):
6764
if isinstance(config, Device):
6865
database = copy.deepcopy(config)
6966
elif isinstance(config, str):
70-
database = self.load_config(config)
67+
database = Config.load_config(config)
7168

7269
if exclude:
7370
delete_attrs(database, exclude)
@@ -92,7 +89,8 @@ def _import_configuration(self, path):
9289
logger.info('Imported Edge Filer configuration.')
9390
return response
9491

95-
def load_config(self, config):
92+
@staticmethod
93+
def load_config(config):
9694
"""
9795
Load the Edge Filer configuration
9896
@@ -126,6 +124,7 @@ def export(self, destination=None):
126124
handle = self._edge.api.handle('/export')
127125
filepath = synfs.write(directory, filename, handle)
128126
logger.info('Exported configuration. %s', {'filepath': filepath})
127+
return filepath
129128

130129
def is_wizard_enabled(self):
131130
"""

cterasdk/edge/files/browser.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
class FileBrowser(BaseCommand):
88
""" Edge Filer File Browser APIs """
99

10-
def __init__(self, edge):
11-
super().__init__(edge)
12-
1310
def listdir(self, path):
1411
"""
1512
List Directory

cterasdk/edge/firmware.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ class UploadTaskStatus():
1212
class Firmware(BaseCommand):
1313
""" Edge Filer Firmware upgrade API """
1414

15-
def __init__(self, edge):
16-
super().__init__(edge)
17-
1815
def upgrade(self, file_path, reboot=True, wait_for_reboot=True):
1916
"""
2017
Upgrade the Filer firmware with the provided file

cterasdk/lib/storage/asynfs.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import logging
22
import aiofiles
3-
from .commonfs import write_new_version
3+
from .commonfs import write_new_version, ResultContext
44

55

66
logger = logging.getLogger('cterasdk.filesystem')
@@ -16,8 +16,10 @@ async def write(directory, name, handle):
1616
:returns: Path
1717
:rtype: str
1818
"""
19+
ctx = ResultContext()
1920
with write_new_version(directory, name) as tempfile:
2021
await overwrite(tempfile, handle)
22+
return ctx.value
2123

2224

2325
async def overwrite(p, handle):

cterasdk/lib/storage/commonfs.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,29 @@ def rename(source, new_name):
140140
return destination.as_posix()
141141

142142

143+
class ResultContext:
144+
"""Context Manager Result Context"""
145+
146+
def __init__(self):
147+
self._value = None
148+
149+
@property
150+
def value(self):
151+
return self._value
152+
153+
@value.setter
154+
def value(self, v):
155+
self._value = v
156+
157+
143158
@contextmanager
144-
def write_new_version(directory, name):
159+
def write_new_version(directory, name, *, ctx=None):
145160
"""
146161
Context manager for writing a file without conflicts.
147162
148163
:param str directory: Parent directory
149164
:param str name: File name
165+
:param ResultContext,optional ctx: Result Context
150166
:returns: Path
151167
:rtype: str
152168
:raises: FileNotFoundError
@@ -171,7 +187,9 @@ def write_new_version(directory, name):
171187

172188
p = parent.joinpath(name)
173189
logger.info('Saved: %s', p.as_posix())
174-
return p.as_posix()
190+
191+
if ctx and isinstance(ctx, ResultContext):
192+
ctx.value = p.as_posix()
175193

176194

177195
def split_file_directory(location):

cterasdk/lib/storage/synfs.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import logging
2-
from .commonfs import write_new_version
2+
from .commonfs import write_new_version, ResultContext
33

44

55
logger = logging.getLogger('cterasdk.filesystem')
@@ -15,8 +15,10 @@ def write(directory, name, handle):
1515
:returns: Path
1616
:rtype: str
1717
"""
18-
with write_new_version(directory, name) as tempfile:
18+
ctx = ResultContext()
19+
with write_new_version(directory, name, ctx=ctx) as tempfile:
1920
overwrite(tempfile, handle)
21+
return ctx.value
2022

2123

2224
def overwrite(p, handle):

0 commit comments

Comments
 (0)