[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: [PATCH] make mailer.py able to use mappings on several to_addr fields

From: Daniel Shahaf <d.s_at_daniel.shahaf.co.il>
Date: Sun, 30 Mar 2008 21:01:47 +0300

Philippe,

Philippe Combes wrote on Sun, 30 Mar 2008 at 16:05 +0200:
> Hi all,
>
> I am not sure I am posting to the right mailing list, but I did not find
> anything specific to mailer.py nor to contrib hook-scripts. Maybe would you
> be kind enough to forward to interested people.
>
> One very useful case of mappings would be to have, say, several authors in
> to_addr value so that the commit e-mail would be sent to all the e-mail
> addresses of these authors. Something like
>
> [project_foo]
> for_repos = .*/repos
> from_addr = %(author)s
> to_addr = john sarah
>
> [maps]
> from_addr = [authors]
> to_addr = [authors]
>
> [authors]
> john = jconnor_at_example.com
> sarah = sconnor_at_example.com
>
>
> With such a configuration, the current version of mailer.py would send "To:
> john, sarah" to the SMTP server, because the string "john sarah" has no
> mapping in [authors].
> With the patch below, it is still possible to map values with white spaces
> in other options than to_addr. Only when we get the value of to_addr, we
> first expand all words with defined mappings, and then collate them back
> into one string. We had to add an argument to Config.get, expand, which
> defaults to False, and this method is called with expand=True when we want
> to get the value of to_addr.
>
> There is probably a better way to do that, more generic, and cleaner.
> Indeed, it is the first time I read and write code in Python, so please be
> indulgent. But I dare submit this patch to give an idea of what sort of
> improvement I meant.
>
> Best regards,
>
> Philippe Combes
>
>
> --- mailer.py (révision 1)
> +++ mailer.py (copie de travail)
> @@ -2,6 +2,10 @@
> #
> # mailer.py: send email describing a commit
> #
> +## This is a patched version that makes it possible to specify several
> mapped
> +## values in to_addr option. The value is a whitespace separated list of
> single
> +## values that are each transformed according to the [maps] section.
> +#
> # $HeadURL:
> http://svn.collab.net/repos/svn/branches/1.4.x/tools/hook-scripts/mailer/mailer.py

Could you please submit a new version of the patch against the trunk
version of mailer.py? Also, please provide a log message (see
http://subversion.tigris.org/hacking.html#patches).

> $
> # $LastChangedDate$
> # $LastChangedBy: dlr $
> @@ -185,7 +189,7 @@
> def start(self, group, params):
> # whitespace-separated list of addresses; split into a clean list:
> self.to_addrs = \
> - filter(None, string.split(self.cfg.get('to_addr', group, params)))
> + filter(None, string.split(self.cfg.get('to_addr', group, params,
> True)))
> self.from_addr = self.cfg.get('from_addr', group, params) \
> or self.repos.author or 'no_author'
> self.reply_to = self.cfg.get('reply_to', group, params)
> @@ -1078,7 +1082,7 @@
> ob = getattr(ob, part)
> return ob
>
> - def get(self, option, group, params):
> + def get(self, option, group, params, expand=False ):
> "Get a config value with appropriate substitutions and value mapping."
>
> # find the right value
> @@ -1096,13 +1100,18 @@
> # apply any mapper
> mapper = getattr(self.maps, option, None)
> if mapper is not None:
> - value = mapper(value)
> + if expand:
> + value = string.join(map(mapper,string.split(value)))
> + else:
> + value = mapper(value)
>
> # Apply any parameters that may now be available for
> # substitution that were not before the mapping.
> if value is not None and params is not None:
> value = value % params
>
> + # Now if expand is required and nothing has changed
> +

Incomplete sentence?

Daniel

> return value
>
> def get_diff_cmd(self, group, args):
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe_at_subversion.tigris.org
For additional commands, e-mail: dev-help_at_subversion.tigris.org
Received on 2008-03-30 20:02:29 CEST

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.