mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-27 19:08:38 -06:00
18423 fix load_yaml / load_json
This commit is contained in:
parent
3ade819706
commit
099242e821
@ -560,12 +560,6 @@ class BaseScript:
|
|||||||
# Convenience functions
|
# Convenience functions
|
||||||
#
|
#
|
||||||
|
|
||||||
def get_storage(self):
|
|
||||||
if self.storage is None:
|
|
||||||
self.storage = storages.create_storage(storages.backends["scripts"])
|
|
||||||
|
|
||||||
return self.storage
|
|
||||||
|
|
||||||
def load_yaml(self, filename):
|
def load_yaml(self, filename):
|
||||||
"""
|
"""
|
||||||
Return data from a YAML file
|
Return data from a YAML file
|
||||||
@ -575,9 +569,8 @@ class BaseScript:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
from yaml import Loader
|
from yaml import Loader
|
||||||
|
|
||||||
storage = self.get_storage()
|
|
||||||
file_path = os.path.join(settings.SCRIPTS_ROOT, filename)
|
file_path = os.path.join(settings.SCRIPTS_ROOT, filename)
|
||||||
with storage.open(file_path, 'r') as datafile:
|
with open(file_path, 'r') as datafile:
|
||||||
data = yaml.load(datafile, Loader=Loader)
|
data = yaml.load(datafile, Loader=Loader)
|
||||||
|
|
||||||
return data
|
return data
|
||||||
@ -586,10 +579,8 @@ class BaseScript:
|
|||||||
"""
|
"""
|
||||||
Return data from a JSON file
|
Return data from a JSON file
|
||||||
"""
|
"""
|
||||||
|
|
||||||
storage = self.get_storage()
|
|
||||||
file_path = os.path.join(settings.SCRIPTS_ROOT, filename)
|
file_path = os.path.join(settings.SCRIPTS_ROOT, filename)
|
||||||
with storage.open(file_path, 'r') as datafile:
|
with open(file_path, 'r') as datafile:
|
||||||
data = json.load(datafile)
|
data = json.load(datafile)
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
Loading…
Reference in New Issue
Block a user