Browse Source

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
changes/96/624196/2
Michael Dong 6 months ago
parent
commit
8930d98a26
6 changed files with 54 additions and 29 deletions
  1. 7
    6
      README.rst
  2. 5
    4
      doc/source/installation.rst
  3. 2
    2
      doc/source/running.rst
  4. 13
    5
      syntribos/config.py
  5. 6
    2
      syntribos/runner.py
  6. 21
    10
      syntribos/utils/env.py

+ 7
- 6
README.rst View File

@@ -249,23 +249,24 @@ This can be done manually, or with the ``init`` command.
249 249
     ``syntribos download --payloads`` at any time.
250 250
 
251 251
 To specify a custom root for syntribos to be installed in,
252
-specify the ``--custom_install_root`` flag after ``init``. This will skip
252
+specify the ``--custom_root`` flag. This will skip
253 253
 prompts for information from the terminal, which can be handy for
254 254
 Jenkins jobs and other situations where user input cannot be retrieved.
255 255
 
256 256
 If you've already run the ``init`` command but want to start over with a fresh
257 257
 environment, you can specify the ``--force`` flag to overwrite existing files.
258
-The ``--custom_install_root`` and ``--force`` flags can be combined to
258
+The ``--custom_root`` and ``--force`` flags can be combined to
259 259
 overwrite files in a custom install root.
260 260
 
261 261
 Note: if you install syntribos to a custom install root, you must supply the
262
-``--custom_install_root`` flag when running syntribos.
262
+``--custom_root`` flag when running syntribos.
263 263
 
264 264
 **Example:**
265 265
 
266 266
 ::
267 267
 
268
-    $ syntribos init --custom_install_root /your/custom/path --force
268
+    $ syntribos --custom_root /your/custom/path init --force
269
+    $ syntribos --custom_root /your/custom/path run
269 270
 
270 271
 
271 272
 
@@ -528,8 +529,8 @@ Specifying a custom root directory
528 529
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
529 530
 
530 531
 If you set up the syntribos environment with a custom root (i.e. with
531
-``syntribos init --custom_install_root``), you can point to it with the
532
-``--syntribos-custom_root`` configuration option. Syntribos will look for a
532
+``syntribos --custom_root init``), you can point to it with the
533
+``--custom_root`` configuration option. Syntribos will look for a
533 534
 ``syntribos.conf`` file inside this directory, and will read further
534 535
 configuration information from there.
535 536
 

+ 5
- 4
doc/source/installation.rst View File

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

+ 2
- 2
doc/source/running.rst View File

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

+ 13
- 5
syntribos/config.py View File

@@ -71,14 +71,14 @@ def sub_commands(sub_parser):
71 71
         help=_(
72 72
             "Skip prompts for configurable options, force initialization "
73 73
             "even if syntribos believes it has already been initialized. If "
74
-            "--custom_install_root isn't specified, we will use the default "
74
+            "--custom_root isn't specified, we will use the default "
75 75
             "options. WARNING: This is potentially destructive! Use with "
76 76
             "caution."))
77 77
     init_parser.add_argument(
78 78
         "--custom_install_root", dest="custom_install_root",
79
-        help=_("Skip prompts for configurable options, and initialize "
80
-               "syntribos in the specified directory. Can be combined "
81
-               "with --force to overwrite existing files."))
79
+        help=_("(DEPRECATED) Skip prompts for configurable options, and "
80
+               "initialize  syntribos in the specified directory. Can be "
81
+               "combined with --force to overwrite existing files."))
82 82
     init_parser.add_argument(
83 83
         "--no_downloads", dest="no_downloads", action="store_true",
84 84
         help=_("Disable the downloading of payload files as part of the "
@@ -184,6 +184,13 @@ def list_cli_opts():
184 184
         cfg.BoolOpt("stacktrace", dest="stacktrace", default=True,
185 185
                     help=_("Select if Syntribos outputs a stacktrace "
186 186
                            " if an exception is raised")),
187
+        cfg.StrOpt(
188
+            "custom_root", dest="custom_root",
189
+            help=_("Filesystem location for syntribos root directory, "
190
+                   "containing logs, templates, payloads, config files. "
191
+                   "Creates directories and skips interactive prompts when "
192
+                   "used with 'syntribos init'"),
193
+            deprecated_group="init", deprecated_name="custom_install_root")
187 194
     ]
188 195
 
189 196
 
@@ -231,7 +238,8 @@ def list_syntribos_opts():
231 238
                 help=_(
232 239
                     "The root directory where the subfolders that make up"
233 240
                     " syntribos' environment (logs, templates, payloads, "
234
-                    "configuration files, etc.)")),
241
+                    "configuration files, etc.)"),
242
+                deprecated_for_removal=True),
235 243
         cfg.StrOpt("meta_vars", sample_default="/path/to/meta.json",
236 244
                    help=_(
237 245
                        "The path to a meta variable definitions file, which "

+ 6
- 2
syntribos/runner.py View File

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

+ 21
- 10
syntribos/utils/env.py View File

@@ -72,12 +72,13 @@ def get_syntribos_root():
72 72
     """This determines the proper path to use as syntribos' root directory."""
73 73
     path = ""
74 74
     try:
75
-        custom_root = CONF.syntribos.custom_root
75
+        custom_root = (
76
+            CONF.syntribos.custom_root or CONF.custom_root or ""
77
+        )
76 78
         if custom_root:
77 79
             return expand_path(custom_root)
78 80
     except Exception:
79
-        pass
80
-
81
+        raise
81 82
     home_root = get_user_home_root()
82 83
 
83 84
     # Virtualenv detection
@@ -110,6 +111,7 @@ def get_log_dir_name(log_path=""):
110 111
 
111 112
 
112 113
 def safe_makedirs(path, force=False):
114
+    path = os.path.abspath(path)
113 115
     if not os.path.exists(path):
114 116
         try:
115 117
             os.makedirs(path)
@@ -142,7 +144,8 @@ def create_env_dirs(root_dir, force=False):
142 144
     log_dir = os.path.join(root_dir, "logs")
143 145
     safe_makedirs(log_dir, force)
144 146
 
145
-    return (root_dir, payloads, templates, log_dir)
147
+    return tuple(os.path.abspath(x)
148
+                 for x in (root_dir, payloads, templates, log_dir))
146 149
 
147 150
 
148 151
 def create_conf_file(created_folders=None, remote_path=None):
@@ -151,17 +154,25 @@ def create_conf_file(created_folders=None, remote_path=None):
151 154
     conf_file = os.path.join(root, FILE)
152 155
     # Create default configuration file
153 156
     with open(conf_file, "w") as f:
154
-        custom_root = CONF.sub_command.custom_install_root or ""
157
+        custom_root = (
158
+            CONF.syntribos.custom_root or CONF.custom_root or ""
159
+        )
155 160
         if custom_root:
156
-            custom_root = "custom_root={0}".format(custom_root)
161
+            custom_root = (
162
+                "# Any changes in the [DEFAULT] section will overwrite all "
163
+                "command line options\n"
164
+                "# [DEFAULT]\n"
165
+                "# custom_root={0}"
166
+                "# force=true\n\n"
167
+            ).format(custom_root)
157 168
         template = (
158 169
             "# syntribos barebones configuration file\n"
159
-            "# You should update this with your desired options!\n"
170
+            "# You should update this with your desired options!\n\n"
171
+            "{custom_root}"
160 172
             "[syntribos]\n"
161 173
             "endpoint=http://127.0.0.1:8080\n"
162 174
             "payloads={payloads}\n"
163
-            "templates={templates}\n"
164
-            "{custom_root}\n\n"
175
+            "templates={templates}\n\n"
165 176
             "[logging]\n"
166 177
             "log_dir={logs}\n"
167 178
         ).format(
@@ -196,7 +207,7 @@ def initialize_syntribos_env():
196 207
     root_dir = get_venv_root() if is_venv() else get_user_home_root()
197 208
 
198 209
     force = CONF.sub_command.force
199
-    custom_root = CONF.sub_command.custom_install_root or ""
210
+    custom_root = CONF.syntribos.custom_root or CONF.custom_root or ""
200 211
     if custom_root:
201 212
         root_dir = custom_root
202 213
     elif CONF.sub_command.force:

Loading…
Cancel
Save