6 def _ignore_error(error):
9 def _raise_error(error):
12 def make_home_conf_dir(path, mode=None, errors='ignore'):
13 # Make the directory path under the user's home directory, making parent
14 # directories as needed.
15 # If the directory is newly created, and a mode is specified, chmod it
16 # with those permissions.
17 # If there's an error, return None if errors is 'ignore', else raise an
19 error_handler = _ignore_error if (errors == 'ignore') else _raise_error
20 tilde_path = os.path.join('~', path)
21 abs_path = os.path.expanduser(tilde_path)
22 if abs_path == tilde_path:
23 return error_handler(ValueError("no home directory available"))
26 except OSError as error:
27 if error.errno != errno.EEXIST:
28 return error_handler(error)
31 os.chmod(abs_path, mode)