From 3f3d6d88d64c428923ad0a6c9d7500ce619f0850 Mon Sep 17 00:00:00 2001 From: Eliot Berriot <contact@eliotberriot.com> Date: Sat, 21 Apr 2018 16:02:56 +0200 Subject: [PATCH] Make music directory configurable in development --- .../audiofile/management/commands/import_files.py | 14 +++++++------- api/funkwhale_api/providers/audiofile/tasks.py | 3 +++ dev.yml | 4 ++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/api/funkwhale_api/providers/audiofile/management/commands/import_files.py b/api/funkwhale_api/providers/audiofile/management/commands/import_files.py index 0be73c2dae..fca98ccd3c 100644 --- a/api/funkwhale_api/providers/audiofile/management/commands/import_files.py +++ b/api/funkwhale_api/providers/audiofile/management/commands/import_files.py @@ -61,7 +61,7 @@ class Command(BaseCommand): if options['recursive']: glob_kwargs['recursive'] = True try: - matching = glob.glob(options['path'], **glob_kwargs) + matching = sorted(glob.glob(options['path'], **glob_kwargs)) except TypeError: raise Exception('You need Python 3.5 to use the --recursive flag') @@ -110,13 +110,13 @@ class Command(BaseCommand): if options['async']: message = 'Successfully launched import for {} tracks' - self.stdout.write(message.format(len(matching))) + self.stdout.write(message.format(len(filtered['new']))) if len(errors) > 0: self.stderr.write( '{} tracks could not be imported:'.format(len(errors))) for path, error in errors: - self.stderr('- {}: {}'.format(path, error)) + self.stderr.write('- {}: {}'.format(path, error)) self.stdout.write( "For details, please refer to import batch #{}".format(batch.pk)) @@ -130,8 +130,8 @@ class Command(BaseCommand): skipped = set(matching) & existing result = { 'initial': matching, - 'skipped': list(skipped), - 'new': list(set(matching) - skipped) + 'skipped': list(sorted(skipped)), + 'new': list(sorted(set(matching) - skipped)), } return result @@ -146,7 +146,7 @@ class Command(BaseCommand): batch = user.imports.create(source='shell') total = len(paths) errors = [] - for i, path in enumerate(paths): + for i, path in list(enumerate(paths)): try: self.stdout.write( message.format(path=path, i=i+1, total=len(paths))) @@ -157,7 +157,7 @@ class Command(BaseCommand): m = 'Error while importing {}: {} {}'.format( path, e.__class__.__name__, e) self.stderr.write(m) - errors.append((m, path)) + errors.append((path, '{} {}'.format(e.__class__.__name__, e))) return batch, errors def import_file(self, path, batch, import_handler, options): diff --git a/api/funkwhale_api/providers/audiofile/tasks.py b/api/funkwhale_api/providers/audiofile/tasks.py index bc18456c30..40114c8774 100644 --- a/api/funkwhale_api/providers/audiofile/tasks.py +++ b/api/funkwhale_api/providers/audiofile/tasks.py @@ -2,12 +2,14 @@ import acoustid import os import datetime from django.core.files import File +from django.db import transaction from funkwhale_api.taskapp import celery from funkwhale_api.providers.acoustid import get_acoustid_client from funkwhale_api.music import models, metadata +@transaction.atomic def import_track_data_from_path(path): data = metadata.Metadata(path) artist = models.Artist.objects.get_or_create( @@ -45,6 +47,7 @@ def import_track_data_from_path(path): def import_metadata_with_musicbrainz(path): pass + @celery.app.task(name='audiofile.from_path') def from_path(path): acoustid_track_id = None diff --git a/dev.yml b/dev.yml index 2df7b44e60..3f67af7983 100644 --- a/dev.yml +++ b/dev.yml @@ -65,7 +65,7 @@ services: - "CACHE_URL=redis://redis:6379/0" volumes: - ./api:/app - - ./data/music:/music + - "${MUSIC_DIRECTORY-./data/music}:/music" networks: - internal api: @@ -78,7 +78,7 @@ services: command: python /app/manage.py runserver 0.0.0.0:12081 volumes: - ./api:/app - - ./data/music:/music + - "${MUSIC_DIRECTORY-./data/music}:/music" environment: - "FUNKWHALE_HOSTNAME=${FUNKWHALE_HOSTNAME-localhost}" - "FUNKWHALE_HOSTNAME_SUFFIX=funkwhale.test" -- GitLab