This commit is contained in:
bkfox 2018-07-01 19:24:22 +02:00
parent 08f519451a
commit 34b72b4485
3 changed files with 60 additions and 86 deletions

View File

@ -258,42 +258,6 @@ class Command(BaseCommand):
logger.info('%s, %s: %s', str(program), str(component),
' '.join([str(c) for c in content]))
def add_arguments(self, parser):
parser.formatter_class=RawTextHelpFormatter
parser.add_argument(
'-q', '--quality_check', action='store_true',
help='Enable quality check using sound_quality_check on all ' \
'sounds marqued as not good'
)
parser.add_argument(
'-s', '--scan', action='store_true',
help='Scan programs directories for changes, plus check for a '
' matching diffusion on sounds that have not been yet assigned'
)
parser.add_argument(
'-m', '--monitor', action='store_true',
help='Run in monitor mode, watch for modification in the filesystem '
'and react in consequence'
)
def handle(self, *args, **options):
if options.get('scan'):
self.scan()
if options.get('quality_check'):
self.check_quality(check = (not options.get('scan')) )
if options.get('monitor'):
self.monitor()
@staticmethod
def check_sounds(qs):
"""
Only check for the sound existence or update
"""
# check files
for sound in qs:
if sound.check_on_file():
sound.save(check = False)
def scan(self):
"""
For all programs, scan dirs
@ -314,10 +278,6 @@ class Command(BaseCommand):
)
dirs.append(os.path.join(program.path))
# extra scan for files that are not in programs' dir anymore
# TODO
def scan_for_program(self, program, subdir, **sound_kwargs):
"""
Scan a given directory that is associated to the given program, and
@ -350,6 +310,16 @@ class Command(BaseCommand):
exclude(pk__in = sounds)
self.check_sounds(sounds)
@staticmethod
def check_sounds(qs):
"""
Only check for the sound existence or update
"""
# check files
for sound in qs:
if sound.check_on_file():
sound.save(check = False)
def check_quality(self, check = False):
"""
Check all files where quality has been set to bad
@ -419,4 +389,29 @@ class Command(BaseCommand):
while True:
time.sleep(1)
def add_arguments(self, parser):
parser.formatter_class=RawTextHelpFormatter
parser.add_argument(
'-q', '--quality_check', action='store_true',
help='Enable quality check using sound_quality_check on all ' \
'sounds marqued as not good'
)
parser.add_argument(
'-s', '--scan', action='store_true',
help='Scan programs directories for changes, plus check for a '
' matching diffusion on sounds that have not been yet assigned'
)
parser.add_argument(
'-m', '--monitor', action='store_true',
help='Run in monitor mode, watch for modification in the filesystem '
'and react in consequence'
)
def handle(self, *args, **options):
if options.get('scan'):
self.scan()
if options.get('quality_check'):
self.check_quality(check = (not options.get('scan')) )
if options.get('monitor'):
self.monitor()

View File

@ -94,8 +94,6 @@ class Monitor:
self.station = station
self.__dict__.update(kwargs)
now = tz.now()
def monitor(self):
"""
Run all monitoring functions.
@ -191,16 +189,18 @@ class Monitor:
comment = current_sound,
)
# tracks -- only for streams
if not log.diffusion:
# trace tracks
self.trace_sound_tracks(log)
def trace_sound_tracks(self, log):
"""
Log tracks for the given sound log (for streamed programs).
Log tracks for the given sound log (for streamed programs only).
Called by self.trace
"""
if log.diffusion:
return
tracks = Track.objects.get_for(object = log.sound) \
.filter(in_seconds = True)
if not tracks.exists():

View File

@ -15,6 +15,7 @@ from django.template.defaultfilters import slugify
from django.utils.translation import ugettext as _, ugettext_lazy
from django.utils import timezone as tz
from django.utils.html import strip_tags
from django.utils.functional import cached_property
from taggit.managers import TaggableManager
@ -68,6 +69,9 @@ class Related(models.Model):
'related_type', 'related_id',
)
class Meta:
abstract = True
objects = RelatedManager()
@classmethod
@ -77,9 +81,6 @@ class Related(models.Model):
"""
return GenericRelation(cl, 'related_id', 'related_type')
class Meta:
abstract = True
class Nameable(models.Model):
name = models.CharField (
@ -87,6 +88,9 @@ class Nameable(models.Model):
max_length = 128,
)
class Meta:
abstract = True
@property
def slug(self):
"""
@ -99,9 +103,6 @@ class Nameable(models.Model):
# return '#{} {}'.format(self.pk, self.name)
return '{}'.format(self.name)
class Meta:
abstract = True
#
# Small common models
@ -460,6 +461,8 @@ class Stream(models.Model):
)
# BIG FIXME: self.date is still used as datetime
class Schedule(models.Model):
"""
A Schedule defines time slots of programs' diffusions. It can be an initial
@ -499,8 +502,9 @@ class Schedule(models.Model):
)
timezone = models.CharField(
_('timezone'),
default = pytz.UTC,
choices = [(x, x) for x in pytz.all_timezones],
max_length = 100, blank=True,
max_length = 100,
help_text = _('timezone used for the date')
)
duration = models.TimeField(
@ -529,35 +533,17 @@ class Schedule(models.Model):
verbose_name = _('initial schedule'),
blank = True, null = True,
on_delete=models.SET_NULL,
help_text = 'this schedule is a rerun of this one',
help_text = _('this schedule is a rerun of this one'),
)
@property
def local_date(self):
"""
Return a version of self.date that is localized to self.timezone;
This is needed since datetime are stored as UTC date and we want
to get it as local time.
"""
if not hasattr(self, '_local_date') or \
self.changed(fields = ('timezone','date')):
self._local_date = tz.localtime(self.date, self.tz)
return self._local_date
@property
@cached_property
def tz(self):
"""
Pytz timezone of the schedule.
"""
if not hasattr(self, '_tz') or self._tz.zone != self.timezone:
import pytz
if not self.timezone:
self.timezone = \
self.date.tzinfo.zone \
if self.date and hasattr(self.date, 'tzinfo') else \
tz.get_current_timezone_name()
self._tz = pytz.timezone(self.timezone or self.date.tzinfo.zone)
return self._tz
return pytz.timezone(self.timezone)
# initial cached data
__initial = None
@ -881,16 +867,14 @@ class Diffusion(models.Model):
"""
return self.start
@property
@cached_property
def local_date(self):
"""
Return a version of self.date that is localized to self.timezone;
This is needed since datetime are stored as UTC date and we want
to get it as local time.
"""
if not hasattr(self, '_local_date'):
self._local_date = tz.localtime(self.date, tz.get_current_timezone())
return self._local_date
return tz.localtime(self.date, tz.get_current_timezone())
@property
def local_end(self):
@ -899,9 +883,7 @@ class Diffusion(models.Model):
This is needed since datetime are stored as UTC date and we want
to get it as local time.
"""
if not hasattr(self, '_local_end'):
self._local_end = tz.localtime(self.end, tz.get_current_timezone())
return self._local_end
return tz.localtime(self.end, tz.get_current_timezone())
def is_live(self):
return self.type == self.Type.normal and \
@ -1289,7 +1271,6 @@ class LogQuerySet(models.QuerySet):
# models.Q(date__lte = end))
return self.filter(date__gte = start, date__lte = end)
# TODO: rename on_air + rename Station.on_air into sth like regular_on_air
def on_air(self, date = None):
"""
Return a queryset of the played elements' log for the given
@ -1528,9 +1509,7 @@ class Log(models.Model):
This is needed since datetime are stored as UTC date and we want
to get it as local time.
"""
if not hasattr(self, '_local_date'):
self._local_date = tz.localtime(self.date, tz.get_current_timezone())
return self._local_date
return tz.localtime(self.date, tz.get_current_timezone())
def is_expired(self, date = None):
"""