get config only if exist.

This commit is contained in:
Jonathan Baecker 2020-05-08 15:22:00 +02:00
parent 28191883a2
commit af59f5e316

View File

@ -15,11 +15,13 @@ from pymediainfo import MediaInfo
def read_yaml(): def read_yaml():
config = GuiSettings.objects.filter(id=1).values()[0] setting = GuiSettings.objects.filter(id=1).values()
if setting:
config = setting[0]
if config and os.path.isfile(config['playout_config']): if config and os.path.isfile(config['playout_config']):
with open(config['playout_config'], 'r') as config_file: with open(config['playout_config'], 'r') as config_file:
return yaml.safe_load(config_file) return yaml.safe_load(config_file)
def write_yaml(data): def write_yaml(data):
@ -149,14 +151,16 @@ class PlayoutService:
class SystemStats: class SystemStats:
def __init__(self): def __init__(self):
self.config = GuiSettings.objects.filter(id=1).values()[0] settings = GuiSettings.objects.filter(id=1).values()
self.config = settings[0] if settings else []
def all(self): def all(self):
return { if self.config:
**self.system(), return {
**self.cpu(), **self.ram(), **self.swap(), **self.system(),
**self.disk(), **self.net(), **self.net_speed() **self.cpu(), **self.ram(), **self.swap(),
} **self.disk(), **self.net(), **self.net_speed()
}
def system(self): def system(self):
return { return {
@ -189,12 +193,13 @@ class SystemStats:
} }
def disk(self): def disk(self):
root = psutil.disk_usage(self.config['media_disk']) if 'media_disk' in self.config and self.config['media_disk']:
return { root = psutil.disk_usage(self.config['media_disk'])
'disk_total': [root.total, sizeof_fmt(root.total)], return {
'disk_used': [root.used, sizeof_fmt(root.used)], 'disk_total': [root.total, sizeof_fmt(root.total)],
'disk_free': [root.free, sizeof_fmt(root.free)] 'disk_used': [root.used, sizeof_fmt(root.used)],
} 'disk_free': [root.free, sizeof_fmt(root.free)]
}
def net(self): def net(self):
net = psutil.net_io_counters() net = psutil.net_io_counters()
@ -208,6 +213,10 @@ class SystemStats:
def net_speed(self): def net_speed(self):
net = psutil.net_if_stats() net = psutil.net_if_stats()
if not 'net_interface' in self.config or \
not self.config['net_interface']:
return
if self.config['net_interface'] not in net: if self.config['net_interface'] not in net:
return { return {
'net_speed_send': 'no network interface set!', 'net_speed_send': 'no network interface set!',