kopia lustrzana https://dev.funkwhale.audio/funkwhale/funkwhale
Merge branch '242-nargs-import' into 'develop'
Resolve "Make the import command accept unlimited argument" Closes #242 See merge request funkwhale/funkwhale!261merge-requests/267/head
commit
7f16491525
|
@ -13,7 +13,7 @@ class Command(BaseCommand):
|
|||
help = "Import audio files mathinc given glob pattern"
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument("path", type=str)
|
||||
parser.add_argument("path", nargs="+", type=str)
|
||||
parser.add_argument(
|
||||
"--recursive",
|
||||
action="store_true",
|
||||
|
@ -65,10 +65,13 @@ class Command(BaseCommand):
|
|||
|
||||
def handle(self, *args, **options):
|
||||
glob_kwargs = {}
|
||||
matching = []
|
||||
if options["recursive"]:
|
||||
glob_kwargs["recursive"] = True
|
||||
try:
|
||||
matching = sorted(glob.glob(options["path"], **glob_kwargs))
|
||||
for import_path in options["path"]:
|
||||
matching += glob.glob(import_path, **glob_kwargs)
|
||||
matching = sorted(list(set(matching)))
|
||||
except TypeError:
|
||||
raise Exception("You need Python 3.5 to use the --recursive flag")
|
||||
|
||||
|
@ -109,7 +112,7 @@ class Command(BaseCommand):
|
|||
"No superuser available, please provide a --username"
|
||||
)
|
||||
|
||||
filtered = self.filter_matching(matching, options)
|
||||
filtered = self.filter_matching(matching)
|
||||
self.stdout.write("Import summary:")
|
||||
self.stdout.write(
|
||||
"- {} files found matching this pattern: {}".format(
|
||||
|
@ -153,7 +156,7 @@ class Command(BaseCommand):
|
|||
"For details, please refer to import batch #{}".format(batch.pk)
|
||||
)
|
||||
|
||||
def filter_matching(self, matching, options):
|
||||
def filter_matching(self, matching):
|
||||
sources = ["file://{}".format(p) for p in matching]
|
||||
# we skip reimport for path that are already found
|
||||
# as a TrackFile.source
|
||||
|
|
|
@ -103,6 +103,18 @@ def test_in_place_import_only_from_music_dir(factories, settings):
|
|||
)
|
||||
|
||||
|
||||
def test_import_with_multiple_argument(factories, mocker):
|
||||
factories["users.User"](username="me")
|
||||
path1 = os.path.join(DATA_DIR, "dummy_file.ogg")
|
||||
path2 = os.path.join(DATA_DIR, "utf8-éà◌.ogg")
|
||||
mocked_filter = mocker.patch(
|
||||
"funkwhale_api.providers.audiofile.management.commands.import_files.Command.filter_matching",
|
||||
return_value=({"new": [], "skipped": []}),
|
||||
)
|
||||
call_command("import_files", path1, path2, username="me", interactive=False)
|
||||
mocked_filter.assert_called_once_with([path1, path2])
|
||||
|
||||
|
||||
def test_import_files_creates_a_batch_and_job(factories, mocker):
|
||||
m = mocker.patch("funkwhale_api.music.tasks.import_job_run")
|
||||
user = factories["users.User"](username="me")
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Command line import now accepts unlimited args (#242)
|
Ładowanie…
Reference in New Issue