Merge lp:~achiang/laika/configparser into lp:laika

Proposed by Alex Chiang on 2010-10-11
Status: Merged
Merged at revision: 7
Proposed branch: lp:~achiang/laika/configparser
Merge into: lp:laika
Diff against target: 0 lines
To merge this branch: bzr merge lp:~achiang/laika/configparser
Reviewer Review Type Date Requested Status
Paul Hummer (community) 2010-10-11 Approve on 2010-10-13
Review via email: mp+38156@code.launchpad.net

Description of the change

Learn how to parse a configuration file.

The file supports the same options as the command line.

Removes support for reading username out of bazaar.conf.

To post a comment you must log in.
Paul Hummer (rockstar) wrote :

On Mon, 11 Oct 2010 20:43:44 -0000
Alex Chiang <email address hidden> wrote:

> === modified file 'laika.py'
> --- laika.py 2010-08-17 19:00:08 +0000
> +++ laika.py 2010-10-11 20:43:43 +0000
> @@ -11,10 +11,10 @@
> # This program is distributed under the terms of the
> # GNU General Public License version 2.
>
> +import ConfigParser
> import datetime
> from optparse import OptionParser
> -import ConfigParser
> -import os, os.path
> +import os
> import re
> import sys
>
> @@ -22,7 +22,6 @@
>
> UTCNOW = datetime.datetime.utcnow()
>
> -
> class Report(object):
> '''An activity report for a specified Launchpad user.
>

PEP 8 wants this extra line here. If PEP 8 is important to you, you'll
want to put it back.

> @@ -137,24 +136,40 @@
> self.print_comments()
> self.print_reported()
>
> -def get_launchpad_username_from_bazaar():
> - bazaar_config = ConfigParser.ConfigParser()
> - bazaar_config.read(os.path.expanduser("~/.bazaar/bazaar.conf"))
> - return bazaar_config.get("DEFAULT", "launchpad_username")

This is a not-so-good way of getting the bazaar username... I guess
I'm happy it's going away.

> +def get_config(opts):
> + config = {}
> + FORMAT = "1.0"
> + laika_config = ConfigParser.ConfigParser()
> + laika_config.read(os.path.expanduser("~/.laikarc"))
> +
> + if laika_config.has_section(FORMAT) == False:
> + print "Error: unsupported configuration file format"
> + sys.exit()
> +
> + def default_user():
> + return os.getenv("USER")
> + def default_window():
> + return 8
> +
> + for opt in opts:
> + try:
> + config[opt] = laika_config.get(FORMAT, opt)
> + except ConfigParser.NoOptionError:
> + config[opt] = locals()["default_%s" % opt]()
> +
> + return config
>

How does this new function introduce the same functionality as
get_launchpad_username_from_bazaar - It seems like we're regressing
here from that functionality.

 review approve

review: Approve
Alex Chiang (achiang) wrote :

Thanks for the review. I'll add the whitespace back.

I think the get_launchpad_username_from_bazaar thing was to cover the case where your unix login doesn't match your launchpad login. Instead of specifying it on the command line each time, it glommed onto something you would have set up for bazaar anyway.

But now that laika can read its own config file, we can just specify the launchpad user name there, the same way you would have done it on the command line, but permanently so you only have to set it once.

lp:~achiang/laika/configparser updated on 2010-10-13
13. By Alex Chiang on 2010-10-13

Whitespace fix to appease PEP8.

Preview Diff

Empty

Subscribers

People subscribed via source and target branches

to all changes: