get config only if exist.
This commit is contained in:
parent
28191883a2
commit
af59f5e316
@ -15,7 +15,9 @@ 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:
|
||||||
@ -149,9 +151,11 @@ 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):
|
||||||
|
if self.config:
|
||||||
return {
|
return {
|
||||||
**self.system(),
|
**self.system(),
|
||||||
**self.cpu(), **self.ram(), **self.swap(),
|
**self.cpu(), **self.ram(), **self.swap(),
|
||||||
@ -189,6 +193,7 @@ class SystemStats:
|
|||||||
}
|
}
|
||||||
|
|
||||||
def disk(self):
|
def disk(self):
|
||||||
|
if 'media_disk' in self.config and self.config['media_disk']:
|
||||||
root = psutil.disk_usage(self.config['media_disk'])
|
root = psutil.disk_usage(self.config['media_disk'])
|
||||||
return {
|
return {
|
||||||
'disk_total': [root.total, sizeof_fmt(root.total)],
|
'disk_total': [root.total, sizeof_fmt(root.total)],
|
||||||
@ -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!',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user