forked from rc/aircox
bug fix
This commit is contained in:
@ -23,7 +23,7 @@ from django.utils import timezone as tz
|
||||
|
||||
from aircox.programs.models import *
|
||||
|
||||
logger = logging.getLogger('aircox.programs.' + __name__)
|
||||
logger = logging.getLogger('aircox.tools')
|
||||
|
||||
class Actions:
|
||||
@staticmethod
|
||||
@ -33,19 +33,28 @@ class Actions:
|
||||
items if they have been generated during this
|
||||
update.
|
||||
|
||||
It set an attribute 'do_not_save' if the item should not
|
||||
be saved. FIXME: find proper way
|
||||
|
||||
Return the number of conflicts
|
||||
"""
|
||||
conflicts = item.get_conflicts()
|
||||
for i, conflict in enumerate(conflicts):
|
||||
if conflict.program == item.program:
|
||||
item.do_not_save = True
|
||||
del conflicts[i]
|
||||
continue
|
||||
|
||||
if conflict.pk in saved_items and \
|
||||
conflict.type != Diffusion.Type['unconfirmed']:
|
||||
conflict.type = Diffusion.Type['unconfirmed']
|
||||
conflict.save()
|
||||
|
||||
if not conflicts:
|
||||
item.type = Diffusion.Type['normal']
|
||||
return 0
|
||||
|
||||
item.type = Diffusion.Type['unconfirmed']
|
||||
for conflict in conflicts:
|
||||
if conflict.pk in saved_items and \
|
||||
conflict.type != Diffusion.Type['unconfirmed']:
|
||||
conflict.type = Diffusion.Type['unconfirmed']
|
||||
conflict.save()
|
||||
return len(conflicts)
|
||||
|
||||
@classmethod
|
||||
@ -67,14 +76,18 @@ class Actions:
|
||||
else:
|
||||
for item in items:
|
||||
count[1] += cl.__check_conflicts(item, saved_items)
|
||||
if hasattr(item, 'do_not_save'):
|
||||
count[0] -= 1
|
||||
continue
|
||||
|
||||
item.save()
|
||||
saved_items.add(item)
|
||||
|
||||
logger.info('[update] {} new diffusions for schedule #{} ({})'.format(
|
||||
len(items), schedule.id, str(schedule)
|
||||
))
|
||||
logger.info('[update] schedule %s: %d new diffusions',
|
||||
str(schedule), len(items),
|
||||
)
|
||||
|
||||
logger.info('[update] total of {} diffusions have been created,'.format(count[0]),
|
||||
logger.info('[update] %d diffusions have been created, %s', count[0],
|
||||
'do not forget manual approval' if manual else
|
||||
'{} conflicts found'.format(count[1]))
|
||||
|
||||
@ -82,7 +95,7 @@ class Actions:
|
||||
def clean (date):
|
||||
qs = Diffusion.objects.filter(type = Diffusion.Type['unconfirmed'],
|
||||
date__lt = date)
|
||||
logger.info('[clean] {} diffusions will be removed'.format(qs.count()))
|
||||
logger.info('[clean] %d diffusions will be removed', qs.count())
|
||||
qs.delete()
|
||||
|
||||
@staticmethod
|
||||
@ -98,7 +111,7 @@ class Actions:
|
||||
else:
|
||||
items.append(diffusion.id)
|
||||
|
||||
logger.info('[check] {} diffusions will be removed'.format(len(items)))
|
||||
logger.info('[check] %d diffusions will be removed', len(items))
|
||||
if len(items):
|
||||
Diffusion.objects.filter(id__in = items).delete()
|
||||
|
||||
|
@ -33,16 +33,17 @@ from aircox.programs.models import *
|
||||
import aircox.programs.settings as settings
|
||||
import aircox.programs.utils as utils
|
||||
|
||||
logger = logging.getLogger('aircox.programs.' + __name__)
|
||||
logger = logging.getLogger('aircox.tools')
|
||||
|
||||
class Command (BaseCommand):
|
||||
help= __doc__
|
||||
|
||||
def report (self, program = None, component = None, *content):
|
||||
if not component:
|
||||
logger.info('{}: '.format(program), *content)
|
||||
logger.info('%s: %s', str(program), ' '.join([str(c) for c in content]))
|
||||
else:
|
||||
logger.info('{}, {}: '.format(program, component), *content)
|
||||
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
|
||||
@ -70,7 +71,7 @@ class Command (BaseCommand):
|
||||
if not err:
|
||||
return utils.seconds_to_time(int(float(out)))
|
||||
|
||||
def get_sound_info (self, program, path):
|
||||
def _get_sound_info (self, program, path):
|
||||
"""
|
||||
Parse file name to get info on the assumption it has the correct
|
||||
format (given in Command.help)
|
||||
@ -92,7 +93,6 @@ class Command (BaseCommand):
|
||||
else:
|
||||
r = r.groupdict()
|
||||
|
||||
r['duration'] = self._get_duration(path)
|
||||
r['name'] = r['name'].replace('_', ' ').capitalize()
|
||||
r['path'] = path
|
||||
return r
|
||||
@ -132,11 +132,11 @@ class Command (BaseCommand):
|
||||
"""
|
||||
For all programs, scan dirs
|
||||
"""
|
||||
logger.info('scan files for all programs...')
|
||||
logger.info('scan all programs...')
|
||||
programs = Program.objects.filter()
|
||||
|
||||
for program in programs:
|
||||
logger.info('program', program.name)
|
||||
logger.info('#%d %s', program.id, program.name)
|
||||
self.scan_for_program(
|
||||
program, settings.AIRCOX_SOUND_ARCHIVES_SUBDIR,
|
||||
type = Sound.Type['archive'],
|
||||
@ -151,7 +151,7 @@ class Command (BaseCommand):
|
||||
Scan a given directory that is associated to the given program, and
|
||||
update sounds information.
|
||||
"""
|
||||
logger.info('scan files in', subdir)
|
||||
logger.info('- %s/', subdir)
|
||||
if not program.ensure_dir(subdir):
|
||||
return
|
||||
|
||||
@ -163,14 +163,17 @@ class Command (BaseCommand):
|
||||
if not path.endswith(settings.AIRCOX_SOUND_FILE_EXT):
|
||||
continue
|
||||
|
||||
sound_info = self.get_sound_info(program, path)
|
||||
sound = Sound.objects.get_or_create(
|
||||
sound, created = Sound.objects.get_or_create(
|
||||
path = path,
|
||||
defaults = { 'name': sound_info['name'],
|
||||
'duration': sound_info['duration'] or None }
|
||||
)[0]
|
||||
sound.__dict__.update(sound_kwargs)
|
||||
sound.save(check = False)
|
||||
defaults = sound_kwargs,
|
||||
)
|
||||
|
||||
sound_info = self._get_sound_info(program, path)
|
||||
|
||||
if created or sound.check_on_file():
|
||||
sound_info['duration'] = self._get_duration()
|
||||
sound.__dict__.update(sound_info)
|
||||
sound.save(check = False)
|
||||
|
||||
# initial diffusion association
|
||||
if 'year' in sound_info:
|
||||
@ -181,12 +184,12 @@ class Command (BaseCommand):
|
||||
self.report(program, path,
|
||||
'the diffusion must be an initial diffusion')
|
||||
else:
|
||||
sound = initial.sounds.get_queryset() \
|
||||
.filter(path == sound.path)
|
||||
if not sound:
|
||||
sound_ = initial.sounds.get_queryset() \
|
||||
.filter(path = sound.path)
|
||||
if not sound_:
|
||||
self.report(program, path,
|
||||
'add sound to diffusion ', initial.id)
|
||||
initial.sounds.add(sound)
|
||||
initial.sounds.add(sound.pk)
|
||||
initial.save()
|
||||
|
||||
self.check_sounds(Sound.objects.filter(path__startswith = subdir))
|
||||
@ -201,16 +204,18 @@ class Command (BaseCommand):
|
||||
sounds = Sound.objects.filter(good_quality = False)
|
||||
if check:
|
||||
self.check_sounds(sounds)
|
||||
files = [ sound.path for sound in sounds if not sound.removed ]
|
||||
files = [ sound.path for sound in sounds
|
||||
if not sound.removed and os.path.exists(sound.path) ]
|
||||
else:
|
||||
files = [ sound.path for sound in sounds.filter(removed = False) ]
|
||||
files = [ sound.path for sound in sounds.filter(removed = False)
|
||||
if os.path.exists(sound.path) ]
|
||||
|
||||
logger.info('start quality check...')
|
||||
logger.info('quality check...',)
|
||||
cmd = quality_check.Command()
|
||||
cmd.handle( files = files,
|
||||
**settings.AIRCOX_SOUND_QUALITY )
|
||||
|
||||
logger.info('update sounds in database')
|
||||
logger.info('update database')
|
||||
def update_stats(sound_info, sound):
|
||||
stats = sound_info.get_file_stats()
|
||||
if stats:
|
||||
|
@ -9,7 +9,7 @@ from argparse import RawTextHelpFormatter
|
||||
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
|
||||
logger = logging.getLogger('aircox.programs.' + __name__)
|
||||
logger = logging.getLogger('aircox.tools')
|
||||
|
||||
class Stats:
|
||||
attributes = [
|
||||
@ -104,11 +104,11 @@ class Sound:
|
||||
]
|
||||
|
||||
if self.good:
|
||||
logger.info(self.path, ': good samples:\033[92m',
|
||||
', '.join( view(self.good) ), '\033[0m')
|
||||
logger.info(self.path + ': good samples:\033[92m%s\033[0m',
|
||||
', '.join(view(self.good)))
|
||||
if self.bad:
|
||||
loggeer.info(self.path ': bad samples:\033[91m',
|
||||
', '.join( view(self.bad) ), '\033[0m')
|
||||
logger.info(self.path + ': good samples:\033[91m%s\033[0m',
|
||||
', '.join(view(self.bad)))
|
||||
|
||||
class Command (BaseCommand):
|
||||
help = __doc__
|
||||
@ -157,7 +157,7 @@ class Command (BaseCommand):
|
||||
self.bad = []
|
||||
self.good = []
|
||||
for sound in self.sounds:
|
||||
logger.info('analyse ', sound.path)
|
||||
logger.info('analyse ' + sound.path)
|
||||
sound.analyse()
|
||||
sound.check(attr, minmax[0], minmax[1])
|
||||
if sound.bad:
|
||||
@ -167,13 +167,8 @@ class Command (BaseCommand):
|
||||
|
||||
# resume
|
||||
if options.get('resume'):
|
||||
if self.good:
|
||||
logger.info('files that did not failed the test:\033[92m\n ',
|
||||
'\n '.join([sound.path for sound in self.good]),
|
||||
'\033[0m')
|
||||
if self.bad:
|
||||
# bad at the end for ergonomy
|
||||
logger.info('files that failed the test:\033[91m\n ',
|
||||
'\n '.join([sound.path for sound in self.bad]),
|
||||
'\033[0m')
|
||||
for sound in self.good:
|
||||
logger.info('\033[92m+ %s\033[0m', sound.path)
|
||||
for sound in self.bad:
|
||||
logger.info('\033[91m+ %s\033[0m', sound.path)
|
||||
|
||||
|
Reference in New Issue
Block a user