mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-21 19:47:20 -06:00
Add convenience functions for loading YAML/JSON data from file
This commit is contained in:
parent
11e5e1c490
commit
7f65e009a8
@ -1,7 +1,10 @@
|
|||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
import inspect
|
import inspect
|
||||||
|
import json
|
||||||
|
import os
|
||||||
import pkgutil
|
import pkgutil
|
||||||
import time
|
import time
|
||||||
|
import yaml
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
@ -196,6 +199,28 @@ class Script:
|
|||||||
def log_failure(self, message):
|
def log_failure(self, message):
|
||||||
self.log.append((LOG_FAILURE, message))
|
self.log.append((LOG_FAILURE, message))
|
||||||
|
|
||||||
|
# Convenience functions
|
||||||
|
|
||||||
|
def load_yaml(self, filename):
|
||||||
|
"""
|
||||||
|
Return data from a YAML file
|
||||||
|
"""
|
||||||
|
file_path = os.path.join(settings.SCRIPTS_ROOT, filename)
|
||||||
|
with open(file_path, 'r') as datafile:
|
||||||
|
data = yaml.load(datafile)
|
||||||
|
|
||||||
|
return data
|
||||||
|
|
||||||
|
def load_json(self, filename):
|
||||||
|
"""
|
||||||
|
Return data from a JSON file
|
||||||
|
"""
|
||||||
|
file_path = os.path.join(settings.SCRIPTS_ROOT, filename)
|
||||||
|
with open(file_path, 'r') as datafile:
|
||||||
|
data = json.load(datafile)
|
||||||
|
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Functions
|
# Functions
|
||||||
|
Loading…
Reference in New Issue
Block a user