diff --git a/README.rst b/README.rst index cdddf530..fc9fd267 100644 --- a/README.rst +++ b/README.rst @@ -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. diff --git a/doc/source/installation.rst b/doc/source/installation.rst index 23deb172..2a335085 100644 --- a/doc/source/installation.rst +++ b/doc/source/installation.rst @@ -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 diff --git a/doc/source/running.rst b/doc/source/running.rst index b7b15186..7f9f539e 100644 --- a/doc/source/running.rst +++ b/doc/source/running.rst @@ -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. diff --git a/syntribos/config.py b/syntribos/config.py index 4afdffdc..b3b00743 100644 --- a/syntribos/config.py +++ b/syntribos/config.py @@ -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 " diff --git a/syntribos/runner.py b/syntribos/runner.py index 4bbfaef1..f44198c9 100644 --- a/syntribos/runner.py +++ b/syntribos/runner.py @@ -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: diff --git a/syntribos/utils/env.py b/syntribos/utils/env.py index f06540e8..f8f9b2d8 100644 --- a/syntribos/utils/env.py +++ b/syntribos/utils/env.py @@ -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: