[merge] Re: bzr-email: add optional hostname on subject (Getting a binary value from config files)

Frédéric Brin frederic.brin at assonetworx.com
Wed Dec 17 00:15:30 GMT 2008


> > +	subject_include_hostname = self.config.get_user_option('subject_include_hostname')
> > +	if subject_include_hostname is None or subject_include_hostname.lower() == 'false':
> 
> Isn't there a better way to get a boolean config value than coding this
> here?

I tried my best to find out to find an answer to this question.
>>>
I would like to achieve to have a section in location.conf like this
so that it only applies to a specific directory

[/etc]
subject_include_hostname = true
<<<
So far the only option I found to get this to work is to use the
get_user_option function, that make the algorithm walk through the
different config files to find out the best setting.

To get a binary result we have the as_bool function. The way it is coded
currently this function could only be linked to a dictionnary as it
takes a key as parameter and look for that key in the object (self).

Follow the few possibilities I see now:

+ either extend the get_user_option with as_boolean option defaulting to
False (So that it does not break current code). Set to True returns a
boolean value or raise a ValueError

+ the logic inside of the current as_bool() can be factored out though
as a function that takes a string and returns a bool (Jelmer's idea ;)
and put somewhere.

+ I let my crappy test the way it is

> > +	    return ("Rev %d: %s in %s" %
> > +		    (self.revno,
> > +		     self.revision.get_summary(),
> > +		     self.url()))
> > +        else:
> > +	    from socket import gethostname
> > +	    return ("Rev %d: %s in %s on %s" %
> > +		    (self.revno,
> > +		     self.revision.get_summary(),
> > +		     self.url(),
> > +		     gethostname()))
> >  
> >      def diff_filename(self):
> >          return "patch-%s.diff" % (self.revno,)
> > 
> 
> 
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: Ceci est une partie de message
	=?ISO-8859-1?Q?num=E9riquement?= =?ISO-8859-1?Q?_sign=E9e?=
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20081217/3fb84795/attachment.pgp 


More information about the bazaar mailing list