- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
class FileCheckError(Exception):
def __init__(self, check, file):
self.check = check
self.file = file
self.exceptions = ['не является файлом',
'не является .wav файлом',
'не находится в списке требуемых сэмплов',]
def __str__(self):
return f'{self.file} {self.exceptions[self.check]}'
def validate_pack(pack) -> list:
"""
Checks for invalid files in a pack folder
Makes a list of invalid files if found any or
makes a list of accepted samples
"""
accepted_samples = []
found_errors = []
for sample in listdir(pack):
checks = [isfile(join(pack, sample)),
fnmatch(sample, '*.wav'),
Path(pack / sample).stem in required_samples, ]
try:
for check in range(len(checks)):
if not checks[check]:
raise FileCheckError(check=check, file=sample)
except FileCheckError as E:
found_errors.append(str(E))
continue
accepted_samples.append(sample)
if len(found_errors) != 0:
return found_errors
else:
return accepted_samples
result = validate_pack(Path('drumpacks/rock'))
print(result, sep='\n')