def _get_dir(toml_config_setting,
sawtooth_home_dir,
windows_dir,
default_dir):
"""Determines the directory path based on configuration.
Arguments:
toml_config_setting (str): The name of the config setting related
to the directory which will appear in path.toml.
sawtooth_home_dir (str): The directory under the SAWTOOTH_HOME
environment variable. For example, for 'data' if the data
directory is $SAWTOOTH_HOME/data.
windows_dir (str): The windows path relative to the computed base
directory.
default_dir (str): The default path on Linux.
Returns:
directory (str): The path.
"""
conf_file = os.path.join(get_config_dir(), 'path.toml')
if os.path.exists(conf_file):
with open(conf_file) as fd:
raw_config = fd.read()
toml_config = toml.loads(raw_config)
if toml_config_setting in toml_config:
return toml_config[toml_config_setting]
if 'SAWTOOTH_HOME' in os.environ:
return os.path.join(os.environ['SAWTOOTH_HOME'], sawtooth_home_dir)
if os.name == 'nt':
base_dir = \
os.path.dirname(os.path.dirname(os.path.abspath(sys.argv[0])))
return os.path.join(base_dir, windows_dir)
return default_dir
评论列表
文章目录