1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: Apache-2.0
12 raise ValueError("can't accept negative value: %s" % (num,))
15 retry_opt = argparse.ArgumentParser(add_help=False)
16 retry_opt.add_argument('--retries', type=_pos_int, default=3, help="""
17 Maximum number of times to retry server requests that encounter temporary
18 failures (e.g., server down). Default 3.""")
20 def _ignore_error(error):
23 def _raise_error(error):
26 def make_home_conf_dir(path, mode=None, errors='ignore'):
27 # Make the directory path under the user's home directory, making parent
28 # directories as needed.
29 # If the directory is newly created, and a mode is specified, chmod it
30 # with those permissions.
31 # If there's an error, return None if errors is 'ignore', else raise an
33 error_handler = _ignore_error if (errors == 'ignore') else _raise_error
34 tilde_path = os.path.join('~', path)
35 abs_path = os.path.expanduser(tilde_path)
36 if abs_path == tilde_path:
37 return error_handler(ValueError("no home directory available"))
40 except OSError as error:
41 if error.errno != errno.EEXIST:
42 return error_handler(error)
45 os.chmod(abs_path, mode)