diff --git a/gertty/config.py b/gertty/config.py index eb3fbb1..9ae342f 100644 --- a/gertty/config.py +++ b/gertty/config.py @@ -23,8 +23,14 @@ class Config(object): def __init__(self, server=None, path=DEFAULT_CONFIG_PATH): self.path = os.path.expanduser(path) self.config = ConfigParser.RawConfigParser() - with open(self.path, 'r') as f: - self.config.readfp(f, filename=f.name) + + try: + with open(self.path, 'r') as f: + self.config.readfp(f, filename=f.name) + except IOError: + self.print_sample() + exit(1) + if server is None: server = self.config.sections()[0] self.server = server @@ -50,3 +56,20 @@ class Config(object): self.log_file = os.path.expanduser(self.config.get(server, 'log_file')) else: self.log_file = os.path.expanduser('~/.gertty.log') + + def print_sample(self): + print """Please create a configuration file ~/.gerttyrc + +Example: + +-----8<-------8<-----8<-----8<--- +[gerrit] +url=https://review.example.org/ +username= +password= +git_root=~/git/ +-----8<-------8<-----8<-----8<--- + +Then invoke: + gertty gerrit + """