parent
f88e5602a7
commit
0d13262229
5 changed files with 30 additions and 5 deletions
|
@ -6,7 +6,7 @@ from tempfile import mkstemp
|
|||
|
||||
from pytimeparse.timeparse import timeparse
|
||||
|
||||
from larigira.fsutils import scan_dir
|
||||
from larigira.fsutils import scan_dir, shortname
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
@ -64,7 +64,7 @@ def generate(spec):
|
|||
|
||||
for path in picked:
|
||||
tmp = mkstemp(suffix=os.path.splitext(path)[-1],
|
||||
prefix='audiogen-randomdir-')
|
||||
prefix='randomdir-%s-' % shortname(path))
|
||||
os.close(tmp[0])
|
||||
shutil.copy(path, tmp[1])
|
||||
log.info("copying %s -> %s", path, os.path.basename(tmp[1]))
|
||||
|
|
|
@ -4,7 +4,7 @@ import shutil
|
|||
import random
|
||||
from tempfile import mkstemp
|
||||
|
||||
from larigira.fsutils import scan_dir
|
||||
from larigira.fsutils import scan_dir, shortname
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
@ -35,7 +35,7 @@ def generate(spec):
|
|||
|
||||
for path in picked:
|
||||
tmp = mkstemp(suffix=os.path.splitext(path)[-1],
|
||||
prefix='randomdir-')
|
||||
prefix='randomdir-%s-' % shortname(path))
|
||||
os.close(tmp[0])
|
||||
shutil.copy(path, tmp[1])
|
||||
log.info("copying %s -> %s", path, os.path.basename(tmp[1]))
|
||||
|
|
|
@ -2,6 +2,8 @@ import os
|
|||
import logging
|
||||
import shutil
|
||||
from tempfile import mkstemp
|
||||
|
||||
from larigira.fsutils import shortname
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
@ -19,7 +21,7 @@ def generate(spec):
|
|||
log.warning("Can't find requested path: %s", path)
|
||||
continue
|
||||
tmp = mkstemp(suffix=os.path.splitext(path)[-1],
|
||||
prefix='audiogen-static-')
|
||||
prefix='static-%s-' % shortname(path))
|
||||
os.close(tmp[0])
|
||||
log.info("copying %s -> %s", path, os.path.basename(tmp[1]))
|
||||
shutil.copy(path, tmp[1])
|
||||
|
|
|
@ -22,3 +22,10 @@ def scan_dir_audio(dirname, extensions=('mp3', 'oga', 'wav', 'ogg')):
|
|||
for fname in filenames:
|
||||
if multi_fnmatch(fname, extensions):
|
||||
yield os.path.join(root, fname)
|
||||
|
||||
|
||||
def shortname(path):
|
||||
name = os.path.basename(path) # filename
|
||||
name = name.rsplit('.', 1)[0] # no extension
|
||||
name = ''.join(c for c in name if c.isalnum()) # no strange chars
|
||||
return name
|
||||
|
|
16
larigira/tests/test_fsutils.py
Normal file
16
larigira/tests/test_fsutils.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
from larigira.fsutils import shortname
|
||||
|
||||
|
||||
def test_shortname_self():
|
||||
'''sometimes, shortname is just filename without extension'''
|
||||
assert shortname('/tmp/asd/foo.bar') == 'foo'
|
||||
|
||||
|
||||
def test_shortname_has_numbers():
|
||||
'''shortname will preserve numbers'''
|
||||
assert shortname('/tmp/asd/foo1.bar') == 'foo1'
|
||||
|
||||
|
||||
def test_shortname_has_no_hyphen():
|
||||
'''shortname will not preserve hyphens'''
|
||||
assert shortname('/tmp/asd/foo-1.bar') == 'foo1'
|
Loading…
Reference in a new issue