mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-09 01:49:35 -06:00
Init storage at class level of BaseScript instead of in findsource function (#20575)
This commit is contained in:
parent
2ae98f0353
commit
9cb2c78e34
@ -329,6 +329,9 @@ class BaseScript:
|
|||||||
# Declare the placeholder for the current request
|
# Declare the placeholder for the current request
|
||||||
self.request = None
|
self.request = None
|
||||||
|
|
||||||
|
# Initiate the storage backend (local, S3, etc) as a class attr
|
||||||
|
self.storage = storages.create_storage(storages.backends["scripts"])
|
||||||
|
|
||||||
# Compile test methods and initialize results skeleton
|
# Compile test methods and initialize results skeleton
|
||||||
for method in dir(self):
|
for method in dir(self):
|
||||||
if method.startswith('test_') and callable(getattr(self, method)):
|
if method.startswith('test_') and callable(getattr(self, method)):
|
||||||
@ -394,8 +397,7 @@ class BaseScript:
|
|||||||
return inspect.getfile(self.__class__)
|
return inspect.getfile(self.__class__)
|
||||||
|
|
||||||
def findsource(self, object):
|
def findsource(self, object):
|
||||||
storage = storages.create_storage(storages.backends["scripts"])
|
with self.storage.open(os.path.basename(self.filename), 'r') as f:
|
||||||
with storage.open(os.path.basename(self.filename), 'r') as f:
|
|
||||||
data = f.read()
|
data = f.read()
|
||||||
|
|
||||||
# Break the source code into lines
|
# Break the source code into lines
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user