Skip to content

Commit 4650c00

Browse files
committed
cli: support for PYRO_CONFIG_DIR environment variable
1 parent 9c50070 commit 4650c00

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

docs/setup.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ If you need several distinct configuration sets, just add the
7070
7171
pyroadmin --create-config --config-dir ~/rtorrent/special/.pyroscope
7272
73+
Alternatively, you can set the :envvar:`PYRO_CONFIG_DIR` environment variable
74+
to change the default of :file:`~/.pyrocscope`.
75+
7376
To view your loaded configuration with all the system defaults added,
7477
use this (again, the ``--config-dir`` option allows non-default
7578
configuration locations):

src/pyrocore/scripts/base.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ def mainloop(self):
331331
class ScriptBaseWithConfig(ScriptBase): # pylint: disable=abstract-method
332332
""" CLI tool with configuration support.
333333
"""
334+
CONFIG_DIR_DEFAULT = '~/.pyroscope'
334335
OPTIONAL_CFG_FILES = []
335336

336337

@@ -340,7 +341,7 @@ def add_options(self):
340341
super(ScriptBaseWithConfig, self).add_options()
341342

342343
self.add_value_option("--config-dir", "DIR",
343-
help="configuration directory [~/.pyroscope]")
344+
help="configuration directory [{}]".format(os.environ.get('PYRO_CONFIG_DIR', self.CONFIG_DIR_DEFAULT)))
344345
self.add_value_option("--config-file", "PATH",
345346
action="append", default=[],
346347
help="additional config file(s) to read")
@@ -353,7 +354,11 @@ def get_options(self):
353354
""" Get program options.
354355
"""
355356
super(ScriptBaseWithConfig, self).get_options()
356-
load_config.ConfigLoader(self.options.config_dir).load(self.OPTIONAL_CFG_FILES + self.options.config_file)
357+
358+
self.config_dir = os.path.abspath(os.path.expanduser(self.options.config_dir
359+
or os.environ.get('PYRO_CONFIG_DIR', None)
360+
or self.CONFIG_DIR_DEFAULT))
361+
load_config.ConfigLoader(self.config_dir).load(self.OPTIONAL_CFG_FILES + self.options.config_file)
357362
if self.options.debug:
358363
config.debug = True
359364

src/pyrocore/scripts/pyroadmin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def mainloop(self):
107107
"""
108108
if self.options.create_config:
109109
# Create configuration
110-
config_loader = load_config.ConfigLoader(self.options.config_dir)
110+
config_loader = load_config.ConfigLoader(self.config_dir)
111111
config_loader.create(self.options.remove_all_rc_files)
112112

113113
# Create directories

src/pyrocore/ui/theming.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ def add_options(self):
5454
def mainloop(self):
5555
""" Handle theme selection changes, or rotate through selection.
5656
"""
57-
config_dir = self.options.config_dir or os.path.expanduser("~/.pyroscope")
58-
themes_dir = os.path.join(config_dir, 'color-schemes')
57+
themes_dir = os.path.join(self.config_dir, 'color-schemes')
5958
selected_file = os.path.join(themes_dir, '.selected')
6059
current_file = os.path.join(themes_dir, '.current')
6160

0 commit comments

Comments
 (0)