I think this line should be:

    try:
        os.makedirs(...)
    finally:
       os.umask(old_umask)

so the umask is reset in case of an exception