Fix support for Python 3.5 in import script

This commit is contained in:
Ciarán Ainsworth 2020-06-05 05:38:05 +02:00 committed by Agate
parent 79753d7752
commit 8116e7339c
2 changed files with 21 additions and 11 deletions

View File

@ -23,21 +23,30 @@ from funkwhale_api.common import utils as common_utils
from funkwhale_api.music import models, tasks, utils from funkwhale_api.music import models, tasks, utils
def dir_scanner(scanner, extensions, recursive, ignored):
for entry in scanner:
if entry.is_file():
for e in extensions:
if entry.name.lower().endswith(".{}".format(e.lower())):
if entry.path not in ignored:
yield entry.path
elif recursive and entry.is_dir():
yield from dir_scanner(
entry, extensions, recursive=recursive, ignored=ignored
)
def crawl_dir(dir, extensions, recursive=True, ignored=[]): def crawl_dir(dir, extensions, recursive=True, ignored=[]):
if os.path.isfile(dir): if os.path.isfile(dir):
yield dir yield dir
return return
with os.scandir(dir) as scanner: else:
for entry in scanner: try:
if entry.is_file(): scanner = os.scandir(dir)
for e in extensions: yield from dir_scanner(scanner, extensions, recursive, ignored)
if entry.name.lower().endswith(".{}".format(e.lower())): finally:
if entry.path not in ignored: if hasattr(scanner, "close"):
yield entry.path scanner.close()
elif recursive and entry.is_dir():
yield from crawl_dir(
entry, extensions, recursive=recursive, ignored=ignored
)
def batch(iterable, n=1): def batch(iterable, n=1):

View File

@ -0,0 +1 @@
Fixed an issue where in-place importing didn't work for directories on machines running Python 3.5 (#1148, #1147)