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