Change the default location for gertty config file

This change changes the default location for the gertty configuration
file that takes precedence if none is supplied on the command line to
~/.config/gertty/gertty.yaml.  If that file does not exist, the previous
location of ~/.gertty.yaml is consulted as a fallback.

Change-Id: I5ee6224219b0229c7b1ba17205c3f4cf8fb1d62b
Story: 2002119
Task: 19798
This commit is contained in:
Nate Johnston 2018-07-11 14:35:27 -04:00 committed by James E. Blair
parent 0ecbd95a93
commit ea67716536
9 changed files with 39 additions and 34 deletions

View File

@ -84,14 +84,14 @@ To install from a git checkout::
pip install .
Gertty uses a YAML based configuration file that it looks for at
``~/.gertty.yaml``. Several sample configuration files are included.
You can find them in the examples/ directory of the
`source distribution <https://git.openstack.org/cgit/openstack/gertty/tree/examples>`_
``~/.config/gertty/gertty.yaml``. Several sample configuration files are
included. You can find them in the examples/ directory of the `source
distribution <https://git.openstack.org/cgit/openstack/gertty/tree/examples>`_
or the share/gertty/examples directory after installation.
Select one of the sample config files, copy it to ~/.gertty.yaml and
edit as necessary. Search for ``CHANGEME`` to find parameters that
need to be supplied. The sample config files are as follows:
Select one of the sample config files, copy it to ~/.config/gertty/gertty.yaml
and edit as necessary. Search for ``CHANGEME`` to find parameters that need to
be supplied. The sample config files are as follows:
**minimal-gertty.yaml**
Only contains the parameters required for Gertty to actually run.

View File

@ -2,14 +2,14 @@ Configuration
-------------
Gertty uses a YAML based configuration file that it looks for at
``~/.gertty.yaml``. Several sample configuration files are included.
You can find them in the examples/ directory of the
`source distribution <https://git.openstack.org/cgit/openstack/gertty/tree/examples>`_
``~/.config/gertty/gertty.yaml``. Several sample configuration files are
included. You can find them in the examples/ directory of the `source
distribution <https://git.openstack.org/cgit/openstack/gertty/tree/examples>`_
or the share/gertty/examples directory after installation.
Select one of the sample config files, copy it to ~/.gertty.yaml and
edit as necessary. Search for ``CHANGEME`` to find parameters that
need to be supplied. The sample config files are as follows:
Select one of the sample config files, copy it to ~/.config/gertty/gertty.yaml
and edit as necessary. Search for ``CHANGEME`` to find parameters that need to
be supplied. The sample config files are as follows:
**minimal-gertty.yaml**
Only contains the parameters required for Gertty to actually run.

View File

@ -1,6 +1,6 @@
# This is an example ~/.gertty.yaml file for use with installations of
# Gerrit running on googlesource.com. Most of these options are not
# required, rather, they customize Gertty to better deal with the
# This is an example ~/.config/gertty/gertty.yaml file for use with
# installations of Gerrit running on googlesource.com. Most of these options
# are not required, rather, they customize Gertty to better deal with the
# particulars of Google's Gerrit configuration.
# This file does not list all of the available options. For a full

View File

@ -1,4 +1,4 @@
# This is an example ~/.gertty.yaml file with only the required
# This is an example ~/.config/gertty/gertty.yaml file with only the required
# settings.
# This file does not list all of the available options. For a full

View File

@ -1,7 +1,7 @@
# This is an example ~/.gertty.yaml file for use with OpenStack's
# Gerrit. Most of these options are not required, rather, they
# customize Gertty to better deal with the particulars of OpenStack's
# Gerrit configuration.
# This is an example ~/.config/gertty/gertty.yaml file for use with OpenStack's
# Gerrit. Most of these options are not required, rather, they customize
# Gertty to better deal with the particulars of OpenStack's Gerrit
# configuration.
# This file does not list all of the available options. For a full
# list with explanations, see the 'reference-gertty.yaml' file.

View File

@ -1,7 +1,7 @@
# This is an example ~/.gertty.yaml file for use with OpenStack's
# Gerrit. Most of these options are not required, rather, they
# customize Gertty to better deal with the particulars of OpenStack's
# Gerrit configuration.
# This is an example ~/.config/gertty/gertty.yaml file for use with OpenStack's
# Gerrit. Most of these options are not required, rather, they customize
# Gertty to better deal with the particulars of OpenStack's Gerrit
# configuration.
# This file does not list all of the available options. For a full
# list with explanations, see the 'reference-gertty.yaml' file.

View File

@ -1,4 +1,4 @@
# This is an example ~/.gertty.yaml with an exhaustive listing of
# This is an example ~/.config/gertty/gertty.yaml with an exhaustive listing of
# options with commentary.
# This section lists the servers that Gertty can talk to. Multiple

View File

@ -249,7 +249,7 @@ class App(object):
keymap='default', debug=False, verbose=False,
disable_sync=False, disable_background_sync=False,
fetch_missing_refs=False,
path=config.DEFAULT_CONFIG_PATH):
path=None):
self.server = server
self.config = config.Config(server, palette, keymap, path)
if debug:
@ -886,7 +886,6 @@ def main():
parser = argparse.ArgumentParser(
description='Console client for Gerrit Code Review.')
parser.add_argument('-c', dest='path',
default=config.DEFAULT_CONFIG_PATH,
help='path to config file')
parser.add_argument('-v', dest='verbose', action='store_true',
help='enable more verbose logging')

View File

@ -36,7 +36,8 @@ try:
except AttributeError:
OrderedDict = ordereddict.OrderedDict
DEFAULT_CONFIG_PATH='~/.gertty.yaml'
DEFAULT_CONFIG_PATH = '~/.config/gertty/gertty.yaml'
FALLBACK_CONFIG_PATH = '~/.gertty.yaml'
class ConfigSchema(object):
server = {v.Required('name'): str,
@ -142,12 +143,8 @@ class ConfigSchema(object):
class Config(object):
def __init__(self, server=None, palette='default', keymap='default',
path=DEFAULT_CONFIG_PATH):
self.path = os.path.expanduser(path)
if not os.path.exists(self.path):
self.printSample()
sys.exit(1)
path=None):
self.path = self.verifyConfigFile(path)
self.config = yaml.safe_load(open(self.path))
schema = ConfigSchema().getSchema(self.config)
@ -268,6 +265,15 @@ class Config(object):
self.size_column['thresholds'] = self.size_column.get('thresholds',
[1, 10, 100, 200, 400, 600, 800, 1000])
def verifyConfigFile(self, path):
for checkpath in [ path, DEFAULT_CONFIG_PATH, FALLBACK_CONFIG_PATH ]:
if checkpath is not None:
expandedpath = os.path.expanduser(checkpath)
if os.path.exists(expandedpath):
return expandedpath
self.printSample()
sys.exit(1)
def getServer(self, name=None):
for server in self.config['servers']:
if name is None or name == server['name']: