Introduce safe_ensure_dirs as a safe os.makedirs replacement.

It only uses os.makedirs call, which is more atomic than calling 2 procs. Thus exception due to already existent directory should not longer occur.
Merge pull request #1882 from abergmeier/safe_ensure_dirs

Introduce safe_ensure_dirs as a safe os.makedirs replacement.