work on logging
This commit is contained in:
parent
4eb5e4a25c
commit
201353367d
|
@ -47,7 +47,7 @@ class Command (BaseCommand):
|
||||||
delay = options.get('delay') / 1000
|
delay = options.get('delay') / 1000
|
||||||
while True:
|
while True:
|
||||||
for controller in self.monitor.controllers.values():
|
for controller in self.monitor.controllers.values():
|
||||||
controller.dealer.monitor()
|
controller.monitor()
|
||||||
time.sleep(delay)
|
time.sleep(delay)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -241,13 +241,6 @@ class Dealer (Source):
|
||||||
def stream_info (self):
|
def stream_info (self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def get_next_diffusion (self):
|
|
||||||
diffusions = models.Diffusion.get_next(self.station)
|
|
||||||
if not diffusions.count():
|
|
||||||
return
|
|
||||||
diffusion = diffusions[0]
|
|
||||||
return diffusion
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def on (self):
|
def on (self):
|
||||||
r = self.connector.send('var.get ', self.id, '_on')
|
r = self.connector.send('var.get ', self.id, '_on')
|
||||||
|
@ -314,11 +307,18 @@ class Dealer (Source):
|
||||||
|
|
||||||
# run the diff
|
# run the diff
|
||||||
if self.playlist == diff.playlist and diff.date <= now:
|
if self.playlist == diff.playlist and diff.date <= now:
|
||||||
# FIXME: log
|
|
||||||
self.on = True
|
self.on = True
|
||||||
for source in self.controller.source:
|
for source in self.controller.source:
|
||||||
source.skip()
|
source.skip()
|
||||||
|
|
||||||
|
self.controller.log(
|
||||||
|
source = self.id,
|
||||||
|
diffusion = diff,
|
||||||
|
date = now,
|
||||||
|
comment = 'trigger the scheduled diffusion to liquidsoap; '
|
||||||
|
'skip all other sources',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class Controller:
|
class Controller:
|
||||||
connector = None
|
connector = None
|
||||||
|
@ -369,11 +369,13 @@ class Controller:
|
||||||
return self.dealer
|
return self.dealer
|
||||||
return self.streams.get(source_id)
|
return self.streams.get(source_id)
|
||||||
|
|
||||||
def next_diffusions (self, count = 5):
|
def log (self, **kwargs):
|
||||||
"""
|
"""
|
||||||
Return a list of the count next diffusions
|
Create a log using **kwargs, and print info
|
||||||
"""
|
"""
|
||||||
return models.Diffusion.get_next(self.station)[:count]
|
log = models.Log(**kwargs)
|
||||||
|
log.save()
|
||||||
|
log.print()
|
||||||
|
|
||||||
def update_all (self):
|
def update_all (self):
|
||||||
"""
|
"""
|
||||||
|
@ -384,6 +386,31 @@ class Controller:
|
||||||
for source in self.streams.values():
|
for source in self.streams.values():
|
||||||
source.update()
|
source.update()
|
||||||
|
|
||||||
|
def __change_log (self, source):
|
||||||
|
last_log = models.Log.objects.filter(
|
||||||
|
source = source.id,
|
||||||
|
).prefetch_related('sound').order('-date')
|
||||||
|
|
||||||
|
on_air = source.current_sound
|
||||||
|
if on_air == last_log.sound.path:
|
||||||
|
return
|
||||||
|
|
||||||
|
self.log(
|
||||||
|
source = source.id,
|
||||||
|
sound = models.Sound.objects.get(path = on_air),
|
||||||
|
start = tz.make_aware(tz.datetime.now()),
|
||||||
|
comment = 'sound has changed'
|
||||||
|
)
|
||||||
|
|
||||||
|
def monitor (self):
|
||||||
|
"""
|
||||||
|
Log changes in the sources, and call dealer.monitor.
|
||||||
|
"""
|
||||||
|
self.dealer.monitor()
|
||||||
|
self.__change_log(self.dealer)
|
||||||
|
for source in self.sources:
|
||||||
|
self.__change_log(source)
|
||||||
|
|
||||||
|
|
||||||
class Monitor:
|
class Monitor:
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -90,6 +90,20 @@ class DiffusionAdmin (admin.ModelAdmin):
|
||||||
list_filter = ('type', 'date', 'program')
|
list_filter = ('type', 'date', 'program')
|
||||||
list_editable = ('type', 'date')
|
list_editable = ('type', 'date')
|
||||||
|
|
||||||
|
fields = ['type', 'date', 'initial', 'sounds', 'program']
|
||||||
|
readonly_fields = ('duration',)
|
||||||
|
|
||||||
|
def get_form(self, request, obj=None, **kwargs):
|
||||||
|
if obj:
|
||||||
|
if obj.date < tz.make_aware(tz.datetime.now()):
|
||||||
|
self.readonly_fields = list(self.fields)
|
||||||
|
self.readonly_fields.remove('type')
|
||||||
|
elif obj.initial:
|
||||||
|
self.readonly_fields = ['program', 'sounds']
|
||||||
|
else:
|
||||||
|
self.readonly_fields = []
|
||||||
|
return super().get_form(request, obj, **kwargs)
|
||||||
|
|
||||||
def get_queryset(self, request):
|
def get_queryset(self, request):
|
||||||
qs = super(DiffusionAdmin, self).get_queryset(request)
|
qs = super(DiffusionAdmin, self).get_queryset(request)
|
||||||
if '_changelist_filters' in request.GET or \
|
if '_changelist_filters' in request.GET or \
|
||||||
|
|
|
@ -396,32 +396,6 @@ class Schedule (models.Model):
|
||||||
verbose_name_plural = _('Schedules')
|
verbose_name_plural = _('Schedules')
|
||||||
|
|
||||||
|
|
||||||
class Log (models.Model):
|
|
||||||
"""
|
|
||||||
Log a played sound start and stop, or a single message
|
|
||||||
"""
|
|
||||||
sound = models.ForeignKey(
|
|
||||||
'Sound',
|
|
||||||
help_text = 'Played sound',
|
|
||||||
blank = True, null = True,
|
|
||||||
)
|
|
||||||
stream = models.ForeignKey(
|
|
||||||
'Stream',
|
|
||||||
blank = True, null = True,
|
|
||||||
)
|
|
||||||
start = models.DateTimeField(
|
|
||||||
'start',
|
|
||||||
)
|
|
||||||
stop = models.DateTimeField(
|
|
||||||
'stop',
|
|
||||||
blank = True, null = True,
|
|
||||||
)
|
|
||||||
comment = models.CharField(
|
|
||||||
max_length = 512,
|
|
||||||
blank = True, null = True,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class Station (Nameable):
|
class Station (Nameable):
|
||||||
"""
|
"""
|
||||||
A Station regroup one or more programs (stream and normal), and is the top
|
A Station regroup one or more programs (stream and normal), and is the top
|
||||||
|
@ -607,11 +581,51 @@ class Diffusion (models.Model):
|
||||||
super(Diffusion, self).save(*args, **kwargs)
|
super(Diffusion, self).save(*args, **kwargs)
|
||||||
|
|
||||||
def __str__ (self):
|
def __str__ (self):
|
||||||
return self.program.name + ' on ' + str(self.date) \
|
return self.program.name + ', ' + \
|
||||||
+ str(self.type)
|
self.date.strftime('%Y-%m-%d %H:%M') +\
|
||||||
|
'' # FIXME str(self.type_display)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = _('Diffusion')
|
verbose_name = _('Diffusion')
|
||||||
verbose_name_plural = _('Diffusions')
|
verbose_name_plural = _('Diffusions')
|
||||||
|
|
||||||
|
|
||||||
|
class Log (models.Model):
|
||||||
|
"""
|
||||||
|
Log a played sound start and stop, or a single message
|
||||||
|
"""
|
||||||
|
source = models.CharField(
|
||||||
|
_('source'),
|
||||||
|
max_length = 64,
|
||||||
|
help_text = 'source information',
|
||||||
|
blank = True, null = True,
|
||||||
|
)
|
||||||
|
diffusion = models.ForeignKey(
|
||||||
|
'Diffusion',
|
||||||
|
help_text = _('related diffusion'),
|
||||||
|
blank = True, null = True,
|
||||||
|
)
|
||||||
|
sound = models.ForeignKey(
|
||||||
|
'Sound',
|
||||||
|
help_text = _('played sound'),
|
||||||
|
blank = True, null = True,
|
||||||
|
)
|
||||||
|
date = models.DateTimeField(
|
||||||
|
'date',
|
||||||
|
)
|
||||||
|
comment = models.CharField(
|
||||||
|
max_length = 512,
|
||||||
|
blank = True, null = True,
|
||||||
|
)
|
||||||
|
|
||||||
|
def print (self):
|
||||||
|
print(str(self), ':', self.comment or '')
|
||||||
|
if self.diffusion:
|
||||||
|
print(' - diffusion #' + str(self.diffusion.id))
|
||||||
|
if self.sound:
|
||||||
|
print(' - sound #' + str(self.sound.id), self.sound.path)
|
||||||
|
|
||||||
|
def __str__ (self):
|
||||||
|
return self.date.strftime('%Y-%m-%d %H:%M') + ', ' + self.source
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user