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

Proposed by Alex Chiang
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) Approve
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.
Revision history for this message
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
=== modified file 'laika'
--- laika 2010-11-09 14:24:28 +0000
+++ laika 2010-11-16 16:46:17 +0000
@@ -195,10 +195,6 @@
195 laika_config = ConfigParser.ConfigParser()195 laika_config = ConfigParser.ConfigParser()
196 laika_config.read(os.path.expanduser("~/.laikarc"))196 laika_config.read(os.path.expanduser("~/.laikarc"))
197197
198 if laika_config.has_section(FORMAT) == False:
199 print "Error: unsupported configuration file format"
200 sys.exit()
201
202 def default_user():198 def default_user():
203 return os.getenv("USER")199 return os.getenv("USER")
204 def default_window():200 def default_window():
@@ -209,7 +205,7 @@
209 for opt in opts:205 for opt in opts:
210 try:206 try:
211 config[opt] = laika_config.get(FORMAT, opt)207 config[opt] = laika_config.get(FORMAT, opt)
212 except ConfigParser.NoOptionError:208 except:
213 config[opt] = locals()["default_%s" % opt]()209 config[opt] = locals()["default_%s" % opt]()
214210
215 return config211 return config

Subscribers

People subscribed via source and target branches

to all changes: