clean-up
This commit is contained in:
parent
08f519451a
commit
34b72b4485
|
@ -258,42 +258,6 @@ class Command(BaseCommand):
|
||||||
logger.info('%s, %s: %s', str(program), str(component),
|
logger.info('%s, %s: %s', str(program), str(component),
|
||||||
' '.join([str(c) for c in content]))
|
' '.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):
|
def scan(self):
|
||||||
"""
|
"""
|
||||||
For all programs, scan dirs
|
For all programs, scan dirs
|
||||||
|
@ -314,10 +278,6 @@ class Command(BaseCommand):
|
||||||
)
|
)
|
||||||
dirs.append(os.path.join(program.path))
|
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):
|
def scan_for_program(self, program, subdir, **sound_kwargs):
|
||||||
"""
|
"""
|
||||||
Scan a given directory that is associated to the given program, and
|
Scan a given directory that is associated to the given program, and
|
||||||
|
@ -350,6 +310,16 @@ class Command(BaseCommand):
|
||||||
exclude(pk__in = sounds)
|
exclude(pk__in = sounds)
|
||||||
self.check_sounds(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):
|
def check_quality(self, check = False):
|
||||||
"""
|
"""
|
||||||
Check all files where quality has been set to bad
|
Check all files where quality has been set to bad
|
||||||
|
@ -419,4 +389,29 @@ class Command(BaseCommand):
|
||||||
while True:
|
while True:
|
||||||
time.sleep(1)
|
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()
|
||||||
|
|
||||||
|
|
|
@ -94,8 +94,6 @@ class Monitor:
|
||||||
self.station = station
|
self.station = station
|
||||||
self.__dict__.update(kwargs)
|
self.__dict__.update(kwargs)
|
||||||
|
|
||||||
now = tz.now()
|
|
||||||
|
|
||||||
def monitor(self):
|
def monitor(self):
|
||||||
"""
|
"""
|
||||||
Run all monitoring functions.
|
Run all monitoring functions.
|
||||||
|
@ -191,16 +189,18 @@ class Monitor:
|
||||||
comment = current_sound,
|
comment = current_sound,
|
||||||
)
|
)
|
||||||
|
|
||||||
# tracks -- only for streams
|
# trace tracks
|
||||||
if not log.diffusion:
|
self.trace_sound_tracks(log)
|
||||||
self.trace_sound_tracks(log)
|
|
||||||
|
|
||||||
|
|
||||||
def trace_sound_tracks(self, 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
|
Called by self.trace
|
||||||
"""
|
"""
|
||||||
|
if log.diffusion:
|
||||||
|
return
|
||||||
|
|
||||||
tracks = Track.objects.get_for(object = log.sound) \
|
tracks = Track.objects.get_for(object = log.sound) \
|
||||||
.filter(in_seconds = True)
|
.filter(in_seconds = True)
|
||||||
if not tracks.exists():
|
if not tracks.exists():
|
||||||
|
|
|
@ -15,6 +15,7 @@ from django.template.defaultfilters import slugify
|
||||||
from django.utils.translation import ugettext as _, ugettext_lazy
|
from django.utils.translation import ugettext as _, ugettext_lazy
|
||||||
from django.utils import timezone as tz
|
from django.utils import timezone as tz
|
||||||
from django.utils.html import strip_tags
|
from django.utils.html import strip_tags
|
||||||
|
from django.utils.functional import cached_property
|
||||||
|
|
||||||
from taggit.managers import TaggableManager
|
from taggit.managers import TaggableManager
|
||||||
|
|
||||||
|
@ -68,6 +69,9 @@ class Related(models.Model):
|
||||||
'related_type', 'related_id',
|
'related_type', 'related_id',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
abstract = True
|
||||||
|
|
||||||
objects = RelatedManager()
|
objects = RelatedManager()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -77,9 +81,6 @@ class Related(models.Model):
|
||||||
"""
|
"""
|
||||||
return GenericRelation(cl, 'related_id', 'related_type')
|
return GenericRelation(cl, 'related_id', 'related_type')
|
||||||
|
|
||||||
class Meta:
|
|
||||||
abstract = True
|
|
||||||
|
|
||||||
|
|
||||||
class Nameable(models.Model):
|
class Nameable(models.Model):
|
||||||
name = models.CharField (
|
name = models.CharField (
|
||||||
|
@ -87,6 +88,9 @@ class Nameable(models.Model):
|
||||||
max_length = 128,
|
max_length = 128,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
abstract = True
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def slug(self):
|
def slug(self):
|
||||||
"""
|
"""
|
||||||
|
@ -99,9 +103,6 @@ class Nameable(models.Model):
|
||||||
# return '#{} {}'.format(self.pk, self.name)
|
# return '#{} {}'.format(self.pk, self.name)
|
||||||
return '{}'.format(self.name)
|
return '{}'.format(self.name)
|
||||||
|
|
||||||
class Meta:
|
|
||||||
abstract = True
|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Small common models
|
# Small common models
|
||||||
|
@ -460,6 +461,8 @@ class Stream(models.Model):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# BIG FIXME: self.date is still used as datetime
|
||||||
class Schedule(models.Model):
|
class Schedule(models.Model):
|
||||||
"""
|
"""
|
||||||
A Schedule defines time slots of programs' diffusions. It can be an initial
|
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 = models.CharField(
|
||||||
_('timezone'),
|
_('timezone'),
|
||||||
|
default = pytz.UTC,
|
||||||
choices = [(x, x) for x in pytz.all_timezones],
|
choices = [(x, x) for x in pytz.all_timezones],
|
||||||
max_length = 100, blank=True,
|
max_length = 100,
|
||||||
help_text = _('timezone used for the date')
|
help_text = _('timezone used for the date')
|
||||||
)
|
)
|
||||||
duration = models.TimeField(
|
duration = models.TimeField(
|
||||||
|
@ -529,35 +533,17 @@ class Schedule(models.Model):
|
||||||
verbose_name = _('initial schedule'),
|
verbose_name = _('initial schedule'),
|
||||||
blank = True, null = True,
|
blank = True, null = True,
|
||||||
on_delete=models.SET_NULL,
|
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):
|
def tz(self):
|
||||||
"""
|
"""
|
||||||
Pytz timezone of the schedule.
|
Pytz timezone of the schedule.
|
||||||
"""
|
"""
|
||||||
if not hasattr(self, '_tz') or self._tz.zone != self.timezone:
|
import pytz
|
||||||
import pytz
|
return pytz.timezone(self.timezone)
|
||||||
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
|
|
||||||
|
|
||||||
# initial cached data
|
# initial cached data
|
||||||
__initial = None
|
__initial = None
|
||||||
|
@ -881,16 +867,14 @@ class Diffusion(models.Model):
|
||||||
"""
|
"""
|
||||||
return self.start
|
return self.start
|
||||||
|
|
||||||
@property
|
@cached_property
|
||||||
def local_date(self):
|
def local_date(self):
|
||||||
"""
|
"""
|
||||||
Return a version of self.date that is localized to self.timezone;
|
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
|
This is needed since datetime are stored as UTC date and we want
|
||||||
to get it as local time.
|
to get it as local time.
|
||||||
"""
|
"""
|
||||||
if not hasattr(self, '_local_date'):
|
return tz.localtime(self.date, tz.get_current_timezone())
|
||||||
self._local_date = tz.localtime(self.date, tz.get_current_timezone())
|
|
||||||
return self._local_date
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def local_end(self):
|
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
|
This is needed since datetime are stored as UTC date and we want
|
||||||
to get it as local time.
|
to get it as local time.
|
||||||
"""
|
"""
|
||||||
if not hasattr(self, '_local_end'):
|
return tz.localtime(self.end, tz.get_current_timezone())
|
||||||
self._local_end = tz.localtime(self.end, tz.get_current_timezone())
|
|
||||||
return self._local_end
|
|
||||||
|
|
||||||
def is_live(self):
|
def is_live(self):
|
||||||
return self.type == self.Type.normal and \
|
return self.type == self.Type.normal and \
|
||||||
|
@ -1289,7 +1271,6 @@ class LogQuerySet(models.QuerySet):
|
||||||
# models.Q(date__lte = end))
|
# models.Q(date__lte = end))
|
||||||
return self.filter(date__gte = start, 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):
|
def on_air(self, date = None):
|
||||||
"""
|
"""
|
||||||
Return a queryset of the played elements' log for the given
|
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
|
This is needed since datetime are stored as UTC date and we want
|
||||||
to get it as local time.
|
to get it as local time.
|
||||||
"""
|
"""
|
||||||
if not hasattr(self, '_local_date'):
|
return tz.localtime(self.date, tz.get_current_timezone())
|
||||||
self._local_date = tz.localtime(self.date, tz.get_current_timezone())
|
|
||||||
return self._local_date
|
|
||||||
|
|
||||||
def is_expired(self, date = None):
|
def is_expired(self, date = None):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user