diff --git a/api/funkwhale_api/common/management/commands/gitpod.py b/api/funkwhale_api/common/management/commands/gitpod.py index 007be0eff..2712c673d 100644 --- a/api/funkwhale_api/common/management/commands/gitpod.py +++ b/api/funkwhale_api/common/management/commands/gitpod.py @@ -37,10 +37,15 @@ class Command(BaseCommand): try: user = User.objects.get(username="gitpod") except Exception: - call_command("createsuperuser", username="gitpod", email="gitpod@example.com", no_input=False) + call_command( + "createsuperuser", + username="gitpod", + email="gitpod@example.com", + no_input=False, + ) user = User.objects.get(username="gitpod") - user.set_password('gitpod') + user.set_password("gitpod") if not user.actor: user.create_actor() @@ -50,7 +55,9 @@ class Command(BaseCommand): preferences.set("common__api_authentication_required", False) # Download music catalog - os.system("git clone https://dev.funkwhale.audio/funkwhale/catalog.git /tmp/catalog") + os.system( + "git clone https://dev.funkwhale.audio/funkwhale/catalog.git /tmp/catalog" + ) os.system("mv -f /tmp/catalog/music /workspace/funkwhale/data") os.system("rm -rf /tmp/catalog/music") @@ -59,7 +66,7 @@ class Command(BaseCommand): "create_library", "gitpod", name="funkwhale/catalog", - privacy_level="everyone" + privacy_level="everyone", ) call_command( "import_files", @@ -77,5 +84,8 @@ class Command(BaseCommand): host="0.0.0.0", port=5000, reload=True, - reload_dirs=["/workspace/funkwhale/api/config/", "/workspace/funkwhale/api/funkwhale_api/"], + reload_dirs=[ + "/workspace/funkwhale/api/config/", + "/workspace/funkwhale/api/funkwhale_api/", + ], ) diff --git a/api/funkwhale_api/music/management/commands/rebuild_music_permissions.py b/api/funkwhale_api/music/management/commands/rebuild_music_permissions.py index 9a3e849d2..6f02e51ce 100644 --- a/api/funkwhale_api/music/management/commands/rebuild_music_permissions.py +++ b/api/funkwhale_api/music/management/commands/rebuild_music_permissions.py @@ -26,34 +26,44 @@ class Command(BaseCommand): def add_arguments(self, parser): parser.add_argument( "username", - nargs='*', + nargs="*", help="Rebuild only for given users", ) @transaction.atomic def handle(self, *args, **options): actor_ids = [] - if options['username']: + if options["username"]: actors = Actor.objects.all().local(True) - actor_ids = list(actors.filter(preferred_username__in=options['username']).values_list('id', flat=True)) - if len(actor_ids) < len(options['username']): - raise CommandError('Invalid username') - print('Emptying permission table for specified users…') - qs = TrackActor.objects.all().filter(Q(actor__pk__in=actor_ids) | Q(actor=None)) + actor_ids = list( + actors.filter(preferred_username__in=options["username"]).values_list( + "id", flat=True + ) + ) + if len(actor_ids) < len(options["username"]): + raise CommandError("Invalid username") + print("Emptying permission table for specified users…") + qs = TrackActor.objects.all().filter( + Q(actor__pk__in=actor_ids) | Q(actor=None) + ) qs._raw_delete(qs.db) else: - print('Emptying permission table…') + print("Emptying permission table…") qs = TrackActor.objects.all() qs._raw_delete(qs.db) libraries = Library.objects.all() objs = [] total_libraries = len(libraries) for i, library in enumerate(libraries): - print('[{}/{}] Populating permission table for library {}'.format(i + 1, total_libraries, library.pk)) + print( + "[{}/{}] Populating permission table for library {}".format( + i + 1, total_libraries, library.pk + ) + ) objs += TrackActor.get_objs( library=library, actor_ids=actor_ids, upload_and_track_ids=[], ) - print('Commiting changes…') + print("Commiting changes…") TrackActor.objects.bulk_create(objs, batch_size=5000, ignore_conflicts=True)