]> git.parisson.com Git - telecaster-client.git/commitdiff
cleanup status
authorGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Tue, 15 Jun 2021 08:22:11 +0000 (10:22 +0200)
committerGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Tue, 15 Jun 2021 08:22:11 +0000 (10:22 +0200)
telecaster/tools/status.py
telecaster/views.py

index 676aa73d32706907d9dbcb7edd5795c5779e89ee..2ee33fe3a07c007959234ba51efe8127cea336cd 100644 (file)
@@ -39,10 +39,13 @@ import os
 from telecaster.tools import *
 from django.conf import settings
 
+
 class Status(object):
 
-    interfaces = ['eth0', 'eth1', 'eth2', 'eth0-eth2', 'eth3', 'eth4', 'eth5', 'eth6', 'eth7', 'eth8', 'eth9',
+    interfaces = ['eth0', 'eth1', 'eth2', 'eth0-eth2', 'eth3', 'eth4', 'eth5',
+                  'eth6', 'eth7', 'eth8', 'eth9', 'eno0', 'eno1',
                   'wlan0', 'wlan1', 'wlan2', 'wlan3', 'wlan4']
+
     acpi_states = {0: 'battery', 1: 'battery', 2: 'AC'}
 
     def __init__(self):
@@ -62,7 +65,7 @@ class Status(object):
             self.temperature = self.acpi.temperature(0)
         except:
             self.temperature = 'N/A'
-        self.get_ids()
+        self.get_pids()
         self.get_hosts()
 
     def to_dict(self):
@@ -106,7 +109,7 @@ class Status(object):
         self.url = 'http://' + self.ip
         self.name = get_hostname()
 
-    def get_ids(self):
+    def get_pids(self):
         self.jacking = get_pid('jackd', args=False) != None
 
         self.audio_encoding = get_pid('gst-launch-1.0', args='lamemp3enc') != None
index 218e3110e897b9fd8232cf04cfc251916cdb6c4d..41c6cabee2ca6d2837c0c1c8fea9fb31a38a6cc0 100644 (file)
@@ -42,87 +42,7 @@ def get_host(request):
         host = host.split(':')[0]
     return host
 
-
-class Status(object):
-
-    interfaces = ['eth0', 'eth1', 'eth2', 'eth0-eth2', 'eth3', 'eth4', 'eth5',
-                  'eth6', 'eth7', 'eth8', 'eth9', 'eno0', 'eno1',
-                  'wlan0', 'wlan1', 'wlan2', 'wlan3', 'wlan4']
-    
-    acpi_states = {0: 'battery', 1: 'battery', 2: 'AC'}
-
-    def __init__(self):
-        self.acpi = acpi.Acpi()
-        self.uid = os.getuid()
-        self.user = pwd.getpwuid(os.getuid())[0]
-        self.cache = settings.MEDIA_ROOT + 'cache/'
-        self.monitoring_conf_dir = '/etc/telecaster/deefuzzer/'
-        self.mp3_monitoring_conf = self.monitoring_conf_dir + 'telecaster_mp3_monitor.yaml'
-        self.webm_monitoring_conf = self.monitoring_conf_dir + 'telecaster_webm_monitor.yaml'
-        self.mp3_streaming_conf = self.cache + 'station_mp3.xml'
-        self.webm_streaming_conf = self.cache + 'station_webm.xml'
-
-    def update(self):
-        self.acpi.update()
-        try:
-            self.temperature = self.acpi.temperature(0)
-        except:
-            self.temperature = 'N/A'
-        self.get_pids()
-        self.get_hosts()
-
-    def to_dict(self):
-        status = [
-          {'id': 'name', 'class': 'default', 'value': self.name, 'label': 'Name'},
-          {'id': 'ip', 'class': 'default', 'value': self.ip, 'label': 'IP address'},
-          {'id': 'acpi_state','class': 'default', 'value': 'AC', 'label': 'Power'},
-          {'id': 'acpi_percent', 'class': 'default', 'value': str(self.acpi.percent()), 'label': 'Charge (%)'},
-          {'id': 'temperature', 'class': 'default', 'value': self.temperature, 'label': 'Temperature'},
-          {'id': 'jackd', 'class': 'default', 'value': self.jacking, 'label': 'Jack server'},
-          {'id': 'audio_encoding','class': 'default',
-                'value': self.audio_encoding, 'label': 'Audio encoding'},
-          {'id': 'video_encoding','class': 'default',
-                'value': self.video_encoding, 'label': 'Video encoding'},
-          {'id': 'audio_monitoring', 'class': 'default',
-                'value': self.audio_monitoring, 'label': 'Audio monitoring'},
-          {'id': 'video_monitoring', 'class': 'default',
-                'value': self.video_monitoring, 'label': 'Video monitoring'},
-          {'id': 'audio_streaming', 'class': 'default',
-                'value': self.audio_streaming, 'label': 'Audio streaming'},
-          {'id': 'video_streaming', 'class': 'default',
-                'value': self.video_streaming, 'label': 'Video streaming'},
-          ]
-
-        for stat in status:
-            if stat['value'] == False or stat['value'] == 'localhost' or stat['value'] == 'battery':
-                stat['class'] = 'warning'
-
-        return status
-
-    def get_hosts(self):
-        ip = ''
-        for interface in self.interfaces:
-            try:
-                ip = get_ip_address(interface)
-                if ip:
-                    self.ip = ip
-                    break
-            except:
-                self.ip = '127.0.0.1'
-        self.url = 'http://' + self.ip
-        self.name = get_hostname()
-
-    def get_pids(self):
-        self.jacking = get_pid('jackd', args=False) != None
-
-        self.audio_encoding = get_pid('gst-launch-1.0', args='lamemp3enc') != None
-        self.video_encoding = get_pid('gst-launch-1.0', args='vp8enc') != None
-
-        self.audio_monitoring = get_pid('deefuzzer', args=self.mp3_monitoring_conf) != None
-        self.video_monitoring = get_pid('deefuzzer', args=self.webm_monitoring_conf) != None
-
-        self.audio_streaming = get_pid('deefuzzer', args=self.mp3_streaming_conf) != None
-        self.video_streaming = get_pid('deefuzzer', args=self.webm_streaming_conf) != None
+status = Status()
 
 
 class StatusView(object):
@@ -149,5 +69,4 @@ class StatusView(object):
     def stop(request):
         pass
 
-status = Status()