Custom root configuration option

Instead of syntribos taking in ``--custom_install_root` during init and
``--syntribos-custom_root`` during run, which sometimes led to the custom root
option not being set correctly, the redundant config options have been
deprecated.

Change-Id: I95f4d345fe8a8608ff6d1daaf06ff49912917a3f
This commit is contained in:
Michael Dong 2018-12-10 14:46:10 -06:00
parent 6cf7bdab87
commit 8930d98a26
6 changed files with 54 additions and 29 deletions

View File

@ -249,23 +249,24 @@ This can be done manually, or with the ``init`` command.
``syntribos download --payloads`` at any time.
To specify a custom root for syntribos to be installed in,
specify the ``--custom_install_root`` flag after ``init``. This will skip
specify the ``--custom_root`` flag. This will skip
prompts for information from the terminal, which can be handy for
Jenkins jobs and other situations where user input cannot be retrieved.
If you've already run the ``init`` command but want to start over with a fresh
environment, you can specify the ``--force`` flag to overwrite existing files.
The ``--custom_install_root`` and ``--force`` flags can be combined to
The ``--custom_root`` and ``--force`` flags can be combined to
overwrite files in a custom install root.
Note: if you install syntribos to a custom install root, you must supply the
``--custom_install_root`` flag when running syntribos.
``--custom_root`` flag when running syntribos.
**Example:**
::
$ syntribos init --custom_install_root /your/custom/path --force
$ syntribos --custom_root /your/custom/path init --force
$ syntribos --custom_root /your/custom/path run
@ -528,8 +529,8 @@ Specifying a custom root directory
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If you set up the syntribos environment with a custom root (i.e. with
``syntribos init --custom_install_root``), you can point to it with the
``--syntribos-custom_root`` configuration option. Syntribos will look for a
``syntribos --custom_root init``), you can point to it with the
``--custom_root`` configuration option. Syntribos will look for a
``syntribos.conf`` file inside this directory, and will read further
configuration information from there.

View File

@ -40,22 +40,23 @@ This can be done manually, or with the ``init`` command.
``syntribos download --payloads`` at any time.
To specify a custom root for syntribos to be installed in,
specify the ``--custom_install_root`` flag after ``init``. This will skip
specify the ``--custom_root`` flag. This will skip
prompts for information from the terminal, which can be handy for
Jenkins jobs and other situations where user input cannot be retrieved.
If you've already run the ``init`` command but want to start over with a fresh
environment, you can specify the ``--force`` flag to overwrite existing files.
The ``--custom_install_root`` and ``--force`` flags can be combined to
The ``--custom_root`` and ``--force`` flags can be combined to
overwrite files in a custom install root.
Note: if you install syntribos to a custom install root, you must supply the
``--custom_install_root`` flag when running syntribos.
``--custom_root`` flag when running syntribos.
**Example:**
::
$ syntribos init --custom_install_root /your/custom/path --force
$ syntribos --custom_root /your/custom/path init --force
$ syntribos --custom_root /your/custom/path run

View File

@ -34,7 +34,7 @@ Specifying a custom root directory
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If you set up the syntribos environment with a custom root (i.e. with
``syntribos init --custom_install_root``), you can point to it with the
``--syntribos-custom_root`` configuration option. Syntribos will look for a
``syntribos --custom_root init``), you can point to it with the
``--custom_root`` configuration option. Syntribos will look for a
``syntribos.conf`` file inside this directory, and will read further
configuration information from there.

View File

@ -71,14 +71,14 @@ def sub_commands(sub_parser):
help=_(
"Skip prompts for configurable options, force initialization "
"even if syntribos believes it has already been initialized. If "
"--custom_install_root isn't specified, we will use the default "
"--custom_root isn't specified, we will use the default "
"options. WARNING: This is potentially destructive! Use with "
"caution."))
init_parser.add_argument(
"--custom_install_root", dest="custom_install_root",
help=_("Skip prompts for configurable options, and initialize "
"syntribos in the specified directory. Can be combined "
"with --force to overwrite existing files."))
help=_("(DEPRECATED) Skip prompts for configurable options, and "
"initialize syntribos in the specified directory. Can be "
"combined with --force to overwrite existing files."))
init_parser.add_argument(
"--no_downloads", dest="no_downloads", action="store_true",
help=_("Disable the downloading of payload files as part of the "
@ -184,6 +184,13 @@ def list_cli_opts():
cfg.BoolOpt("stacktrace", dest="stacktrace", default=True,
help=_("Select if Syntribos outputs a stacktrace "
" if an exception is raised")),
cfg.StrOpt(
"custom_root", dest="custom_root",
help=_("Filesystem location for syntribos root directory, "
"containing logs, templates, payloads, config files. "
"Creates directories and skips interactive prompts when "
"used with 'syntribos init'"),
deprecated_group="init", deprecated_name="custom_install_root")
]
@ -231,7 +238,8 @@ def list_syntribos_opts():
help=_(
"The root directory where the subfolders that make up"
" syntribos' environment (logs, templates, payloads, "
"configuration files, etc.)")),
"configuration files, etc.)"),
deprecated_for_removal=True),
cfg.StrOpt("meta_vars", sample_default="/path/to/meta.json",
help=_(
"The path to a meta variable definitions file, which "

View File

@ -139,6 +139,9 @@ class Runner(object):
try:
syntribos.config.register_opts()
if use_file:
# Parsing the args first in case a custom_install_root
# was specified.
CONF(argv, default_config_files=[])
CONF(argv, default_config_files=[ENV.get_default_conf_file()])
else:
CONF(argv, default_config_files=[])
@ -287,8 +290,9 @@ class Runner(object):
print(
"\n"
"*** The JSON parser raised an exception when parsing "
"{}. Check that the file contains correctly formatted "
"JSON data. *** \n".format(_full_path)
"{}. Check that the file contains "
"correctly formatted JSON data. ***\n".format(
_full_path)
)
for file_path, req_str in templates_dir:
if "meta.json" in file_path:

View File

@ -72,12 +72,13 @@ def get_syntribos_root():
"""This determines the proper path to use as syntribos' root directory."""
path = ""
try:
custom_root = CONF.syntribos.custom_root
custom_root = (
CONF.syntribos.custom_root or CONF.custom_root or ""
)
if custom_root:
return expand_path(custom_root)
except Exception:
pass
raise
home_root = get_user_home_root()
# Virtualenv detection
@ -110,6 +111,7 @@ def get_log_dir_name(log_path=""):
def safe_makedirs(path, force=False):
path = os.path.abspath(path)
if not os.path.exists(path):
try:
os.makedirs(path)
@ -142,7 +144,8 @@ def create_env_dirs(root_dir, force=False):
log_dir = os.path.join(root_dir, "logs")
safe_makedirs(log_dir, force)
return (root_dir, payloads, templates, log_dir)
return tuple(os.path.abspath(x)
for x in (root_dir, payloads, templates, log_dir))
def create_conf_file(created_folders=None, remote_path=None):
@ -151,17 +154,25 @@ def create_conf_file(created_folders=None, remote_path=None):
conf_file = os.path.join(root, FILE)
# Create default configuration file
with open(conf_file, "w") as f:
custom_root = CONF.sub_command.custom_install_root or ""
custom_root = (
CONF.syntribos.custom_root or CONF.custom_root or ""
)
if custom_root:
custom_root = "custom_root={0}".format(custom_root)
custom_root = (
"# Any changes in the [DEFAULT] section will overwrite all "
"command line options\n"
"# [DEFAULT]\n"
"# custom_root={0}"
"# force=true\n\n"
).format(custom_root)
template = (
"# syntribos barebones configuration file\n"
"# You should update this with your desired options!\n"
"# You should update this with your desired options!\n\n"
"{custom_root}"
"[syntribos]\n"
"endpoint=http://127.0.0.1:8080\n"
"payloads={payloads}\n"
"templates={templates}\n"
"{custom_root}\n\n"
"templates={templates}\n\n"
"[logging]\n"
"log_dir={logs}\n"
).format(
@ -196,7 +207,7 @@ def initialize_syntribos_env():
root_dir = get_venv_root() if is_venv() else get_user_home_root()
force = CONF.sub_command.force
custom_root = CONF.sub_command.custom_install_root or ""
custom_root = CONF.syntribos.custom_root or CONF.custom_root or ""
if custom_root:
root_dir = custom_root
elif CONF.sub_command.force: