forked from rc/aircox
use logging
This commit is contained in:
@ -15,11 +15,15 @@ planified before the (given) month.
|
||||
- "check" will remove all diffusions that are unconfirmed and have been planified
|
||||
from the (given) month and later.
|
||||
"""
|
||||
import logging
|
||||
from argparse import RawTextHelpFormatter
|
||||
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.utils import timezone as tz
|
||||
|
||||
from aircox.programs.models import *
|
||||
|
||||
logger = logging.getLogger('aircox.programs.' + __name__)
|
||||
|
||||
class Actions:
|
||||
@staticmethod
|
||||
@ -66,11 +70,11 @@ class Actions:
|
||||
item.save()
|
||||
saved_items.add(item)
|
||||
|
||||
print('> {} new diffusions for schedule #{} ({})'.format(
|
||||
logger.info('[update] {} new diffusions for schedule #{} ({})'.format(
|
||||
len(items), schedule.id, str(schedule)
|
||||
))
|
||||
|
||||
print('total of {} diffusions have been created,'.format(count[0]),
|
||||
logger.info('[update] total of {} diffusions have been created,'.format(count[0]),
|
||||
'do not forget manual approval' if manual else
|
||||
'{} conflicts found'.format(count[1]))
|
||||
|
||||
@ -78,7 +82,7 @@ class Actions:
|
||||
def clean (date):
|
||||
qs = Diffusion.objects.filter(type = Diffusion.Type['unconfirmed'],
|
||||
date__lt = date)
|
||||
print('{} diffusions will be removed'.format(qs.count()))
|
||||
logger.info('[clean] {} diffusions will be removed'.format(qs.count()))
|
||||
qs.delete()
|
||||
|
||||
@staticmethod
|
||||
@ -92,10 +96,9 @@ class Actions:
|
||||
if schedule.match(diffusion.date):
|
||||
break
|
||||
else:
|
||||
print('> #{}: {}'.format(diffusion.pk, str(diffusion)))
|
||||
items.append(diffusion.id)
|
||||
|
||||
print('{} diffusions will be removed'.format(len(items)))
|
||||
logger.info('[check] {} diffusions will be removed'.format(len(items)))
|
||||
if len(items):
|
||||
Diffusion.objects.filter(id__in = items).delete()
|
||||
|
||||
|
@ -23,6 +23,7 @@ Sox (and soxi).
|
||||
"""
|
||||
import os
|
||||
import re
|
||||
import logging
|
||||
import subprocess
|
||||
from argparse import RawTextHelpFormatter
|
||||
|
||||
@ -32,15 +33,16 @@ from aircox.programs.models import *
|
||||
import aircox.programs.settings as settings
|
||||
import aircox.programs.utils as utils
|
||||
|
||||
logger = logging.getLogger('aircox.programs.' + __name__)
|
||||
|
||||
class Command (BaseCommand):
|
||||
help= __doc__
|
||||
|
||||
def report (self, program = None, component = None, *content):
|
||||
if not component:
|
||||
print('{}: '.format(program), *content)
|
||||
logger.info('{}: '.format(program), *content)
|
||||
else:
|
||||
print('{}, {}: '.format(program, component), *content)
|
||||
logger.info('{}, {}: '.format(program, component), *content)
|
||||
|
||||
def add_arguments (self, parser):
|
||||
parser.formatter_class=RawTextHelpFormatter
|
||||
@ -130,11 +132,11 @@ class Command (BaseCommand):
|
||||
"""
|
||||
For all programs, scan dirs
|
||||
"""
|
||||
print('scan files for all programs...')
|
||||
logger.info('scan files for all programs...')
|
||||
programs = Program.objects.filter()
|
||||
|
||||
for program in programs:
|
||||
print('- program', program.name)
|
||||
logger.info('program', program.name)
|
||||
self.scan_for_program(
|
||||
program, settings.AIRCOX_SOUND_ARCHIVES_SUBDIR,
|
||||
type = Sound.Type['archive'],
|
||||
@ -149,7 +151,7 @@ class Command (BaseCommand):
|
||||
Scan a given directory that is associated to the given program, and
|
||||
update sounds information.
|
||||
"""
|
||||
print(' - scan files in', subdir)
|
||||
logger.info('scan files in', subdir)
|
||||
if not program.ensure_dir(subdir):
|
||||
return
|
||||
|
||||
@ -203,12 +205,12 @@ class Command (BaseCommand):
|
||||
else:
|
||||
files = [ sound.path for sound in sounds.filter(removed = False) ]
|
||||
|
||||
print('start quality check...')
|
||||
logger.info('start quality check...')
|
||||
cmd = quality_check.Command()
|
||||
cmd.handle( files = files,
|
||||
**settings.AIRCOX_SOUND_QUALITY )
|
||||
|
||||
print('- update sounds in database')
|
||||
logger.info('update sounds in database')
|
||||
def update_stats(sound_info, sound):
|
||||
stats = sound_info.get_file_stats()
|
||||
if stats:
|
||||
|
@ -2,12 +2,15 @@
|
||||
Analyse and check files using Sox, prints good and bad files.
|
||||
"""
|
||||
import sys
|
||||
import logging
|
||||
import re
|
||||
import subprocess
|
||||
|
||||
from argparse import RawTextHelpFormatter
|
||||
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
|
||||
logger = logging.getLogger('aircox.programs.' + __name__)
|
||||
|
||||
class Stats:
|
||||
attributes = [
|
||||
'DC offset', 'Min level', 'Max level',
|
||||
@ -72,7 +75,7 @@ class Sound:
|
||||
return self.stats and self.stats[0]
|
||||
|
||||
def analyse (self):
|
||||
print('- complete file analysis')
|
||||
logger.info('complete file analysis')
|
||||
self.stats = [ Stats(self.path) ]
|
||||
position = 0
|
||||
length = self.stats[0].get('length')
|
||||
@ -80,13 +83,11 @@ class Sound:
|
||||
if not self.sample_length:
|
||||
return
|
||||
|
||||
print('- samples analysis: ', end=' ')
|
||||
logger.info('start samples analysis...')
|
||||
while position < length:
|
||||
print(len(self.stats), end=' ')
|
||||
stats = Stats(self.path, at = position, length = self.sample_length)
|
||||
self.stats.append(stats)
|
||||
position += self.sample_length
|
||||
print()
|
||||
|
||||
def check (self, name, min_val, max_val):
|
||||
self.good = [ index for index, stats in enumerate(self.stats)
|
||||
@ -103,9 +104,11 @@ class Sound:
|
||||
]
|
||||
|
||||
if self.good:
|
||||
print('- good:\033[92m', ', '.join( view(self.good) ), '\033[0m')
|
||||
logger.info(self.path, ': good samples:\033[92m',
|
||||
', '.join( view(self.good) ), '\033[0m')
|
||||
if self.bad:
|
||||
print('- bad:\033[91m', ', '.join( view(self.bad) ), '\033[0m')
|
||||
loggeer.info(self.path ': bad samples:\033[91m',
|
||||
', '.join( view(self.bad) ), '\033[0m')
|
||||
|
||||
class Command (BaseCommand):
|
||||
help = __doc__
|
||||
@ -154,10 +157,9 @@ class Command (BaseCommand):
|
||||
self.bad = []
|
||||
self.good = []
|
||||
for sound in self.sounds:
|
||||
print(sound.path)
|
||||
logger.info('analyse ', sound.path)
|
||||
sound.analyse()
|
||||
sound.check(attr, minmax[0], minmax[1])
|
||||
print()
|
||||
if sound.bad:
|
||||
self.bad.append(sound)
|
||||
else:
|
||||
@ -166,10 +168,12 @@ class Command (BaseCommand):
|
||||
# resume
|
||||
if options.get('resume'):
|
||||
if self.good:
|
||||
print('files that did not failed the test:\033[92m\n ',
|
||||
'\n '.join([sound.path for sound in self.good]), '\033[0m')
|
||||
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
|
||||
print('files that failed the test:\033[91m\n ',
|
||||
'\n '.join([sound.path for sound in self.bad]),'\033[0m')
|
||||
logger.info('files that failed the test:\033[91m\n ',
|
||||
'\n '.join([sound.path for sound in self.bad]),
|
||||
'\033[0m')
|
||||
|
||||
|
Reference in New Issue
Block a user