Commit d3b467ae authored by fred's avatar fred

add "create_jingles" management command, to create them from filesystem

parent e8cd54a9
import datetime
import os
from django.core.management.base import BaseCommand, CommandError
from ...app_settings import app_settings
from ...models import Jingle
from emissions.utils import get_duration
class Command(BaseCommand):
def handle(self, verbosity, **kwargs):
self.verbose = (int(verbosity) > 1)
base_path = os.path.abspath(os.path.join(app_settings.LOCAL_BASE_PATH, app_settings.JINGLES_PREFIX))
for basedir, dirnames, filenames in os.walk(base_path):
for filename in filenames:
fullpath = os.path.join(basedir, filename)
filepath = fullpath[len(base_path)+1:]
if Jingle.objects.filter(filepath=filepath).exists():
continue
jingle = Jingle(label=filename, filepath=filepath)
jingle.duration = datetime.timedelta(seconds=float(get_duration(fullpath)))
jingle.save()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment