Commit 86856829 authored by fred's avatar fred

raise errors when soma directory is not available

parent da515380
......@@ -69,12 +69,20 @@ def add_diffusion(diffusion, **kwargs):
diffusion_path = get_diffusion_file_path(diffusion)
# copy file
if os.path.exists(LOCAL_BASE_PATH):
if os.path.exists(os.path.join(LOCAL_BASE_PATH, diffusion_path)):
raise DuplicateDiffusionSlot()
os.mkdir(os.path.join(LOCAL_BASE_PATH, diffusion_path))
if not os.path.exists(LOCAL_BASE_PATH):
raise SomaException('soma directory is not available')
if os.path.exists(os.path.join(LOCAL_BASE_PATH, diffusion_path)):
raise DuplicateDiffusionSlot()
os.mkdir(os.path.join(LOCAL_BASE_PATH, diffusion_path))
try:
shutil.copyfile(soundfile.file.path,
os.path.join(LOCAL_BASE_PATH, diffusion_path, os.path.basename(soundfile.file.path)))
except IOError:
try:
os.rmdir(os.path.join(LOCAL_BASE_PATH, diffusion_path))
except IOError:
pass
raise SomaException('error copying file to soma')
context['diffusion_path'] = diffusion_path
# end should be a bit before the real end of file so the same file doesn't
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment