From 6adc8f0cde39e6ff7a7b64229d009c5a899ac8a4 Mon Sep 17 00:00:00 2001
From: Eliot Berriot <contact@eliotberriot.com>
Date: Thu, 20 Jul 2017 23:25:01 +0200
Subject: [PATCH] Fixed #37: do not pass recursive flag on import unless needed

---
 .../audiofile/management/commands/import_files.py    | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

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 8a99156c..a34e36b4 100644
--- a/api/funkwhale_api/providers/audiofile/management/commands/import_files.py
+++ b/api/funkwhale_api/providers/audiofile/management/commands/import_files.py
@@ -29,7 +29,17 @@ class Command(BaseCommand):
 
     def handle(self, *args, **options):
         # self.stdout.write(self.style.SUCCESS('Successfully closed poll "%s"' % poll_id))
-        matching = glob.glob(options['path'], recursive=options['recursive'])
+
+        # Recursive is supported only on Python 3.5+, so we pass the option
+        # only if it's True to avoid breaking on older versions of Python
+        glob_kwargs = {}
+        if options['recursive']:
+            glob_kwargs['recursive'] = True
+        try:
+            matching = glob.glob(options['path'], **glob_kwargs)
+        except TypeError:
+            raise Exception('You need Python 3.5 to use the --recursive flag')
+
         self.stdout.write('This will import {} files matching this pattern: {}'.format(
             len(matching), options['path']))
 
-- 
GitLab