Merge lp:~achiang/laika/no-laikarc into lp:laika

Proposed by Alex Chiang on 2010-11-16
Status: Merged
Merged at revision: 15
Proposed branch: lp:~achiang/laika/no-laikarc
Merge into: lp:laika
Diff against target: 23 lines (+1/-5)
1 file modified
laika (+1/-5)
To merge this branch: bzr merge lp:~achiang/laika/no-laikarc
Reviewer Review Type Date Requested Status
Florian Boucault (community) 2010-11-16 Approve on 2010-11-21
Review via email: mp+40979@code.launchpad.net

Description of the change

  Handle lack of .laikarc properly

  If the user does not have a ~/.laikarc, the following error is displayed:

   Error: unsupported configuration file format

  and laika exits.

  This is improper behavior. Laika should gracefully use the built-in
  defaults if the user does not have a .laikarc.

  Remove the has_section check, as it causes us to exit prematurely.
  Instead, rewrite the try..except block more generally, so that on
  any exception (either a ConfigParser.NoOptionError or
  ConfigParser.NoSectionError), we fall back to the defaults.

  Fixes LP: #676112

To post a comment you must log in.
Florian Boucault (fboucault) wrote :

Works for me. Thanks Alex.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'laika'
2--- laika 2010-11-09 14:24:28 +0000
3+++ laika 2010-11-16 16:46:17 +0000
4@@ -195,10 +195,6 @@
5 laika_config = ConfigParser.ConfigParser()
6 laika_config.read(os.path.expanduser("~/.laikarc"))
7
8- if laika_config.has_section(FORMAT) == False:
9- print "Error: unsupported configuration file format"
10- sys.exit()
11-
12 def default_user():
13 return os.getenv("USER")
14 def default_window():
15@@ -209,7 +205,7 @@
16 for opt in opts:
17 try:
18 config[opt] = laika_config.get(FORMAT, opt)
19- except ConfigParser.NoOptionError:
20+ except:
21 config[opt] = locals()["default_%s" % opt]()
22
23 return config

Subscribers

People subscribed via source and target branches

to all changes: