10 raise ValueError("can't accept negative value: %s" % (num,))
13 retry_opt = argparse.ArgumentParser(add_help=False)
14 retry_opt.add_argument('--retries', type=_pos_int, default=3, help="""
15 Maximum number of times to retry server requests that encounter temporary
16 failures (e.g., server down). Default 3.""")
18 def _ignore_error(error):
21 def _raise_error(error):
24 def make_home_conf_dir(path, mode=None, errors='ignore'):
25 # Make the directory path under the user's home directory, making parent
26 # directories as needed.
27 # If the directory is newly created, and a mode is specified, chmod it
28 # with those permissions.
29 # If there's an error, return None if errors is 'ignore', else raise an
31 error_handler = _ignore_error if (errors == 'ignore') else _raise_error
32 tilde_path = os.path.join('~', path)
33 abs_path = os.path.expanduser(tilde_path)
34 if abs_path == tilde_path:
35 return error_handler(ValueError("no home directory available"))
38 except OSError as error:
39 if error.errno != errno.EEXIST:
40 return error_handler(error)
43 os.chmod(abs_path, mode)