diff --git a/README.rst b/README.rst index d08d020..7bf08ae 100644 --- a/README.rst +++ b/README.rst @@ -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 `_ +``~/.config/gertty/gertty.yaml``. Several sample configuration files are +included. You can find them in the examples/ directory of the `source +distribution `_ 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. diff --git a/doc/source/configuration.rst b/doc/source/configuration.rst index 3a29377..4d365bd 100644 --- a/doc/source/configuration.rst +++ b/doc/source/configuration.rst @@ -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 `_ +``~/.config/gertty/gertty.yaml``. Several sample configuration files are +included. You can find them in the examples/ directory of the `source +distribution `_ 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. diff --git a/examples/googlesource-gertty.yaml b/examples/googlesource-gertty.yaml index 0663e48..c749cab 100644 --- a/examples/googlesource-gertty.yaml +++ b/examples/googlesource-gertty.yaml @@ -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 diff --git a/examples/minimal-gertty.yaml b/examples/minimal-gertty.yaml index c61e943..22a9aa3 100644 --- a/examples/minimal-gertty.yaml +++ b/examples/minimal-gertty.yaml @@ -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 diff --git a/examples/openstack-gertty.yaml b/examples/openstack-gertty.yaml index bcf11bf..632b4f0 100644 --- a/examples/openstack-gertty.yaml +++ b/examples/openstack-gertty.yaml @@ -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. diff --git a/examples/rdo-gertty.yaml b/examples/rdo-gertty.yaml index cf7dbdd..9417fb9 100644 --- a/examples/rdo-gertty.yaml +++ b/examples/rdo-gertty.yaml @@ -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. diff --git a/examples/reference-gertty.yaml b/examples/reference-gertty.yaml index fcdab93..b6f65b7 100644 --- a/examples/reference-gertty.yaml +++ b/examples/reference-gertty.yaml @@ -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 diff --git a/gertty/app.py b/gertty/app.py index 190f61d..b70f0ef 100644 --- a/gertty/app.py +++ b/gertty/app.py @@ -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') diff --git a/gertty/config.py b/gertty/config.py index 3f7f711..4f38d14 100644 --- a/gertty/config.py +++ b/gertty/config.py @@ -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']: