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

svn commit: r15160 - trunk/tools/hook-scripts/mailer

From: Brandt, Servatius <Servatius.Brandt_at_fujitsu-siemens.com>
Date: 2005-06-28 15:02:58 CEST

C. Michael Pilato wrote:

> > > (Config.get): Apply mappings on a per-word basis.
> >
> > Sure, this is fine for email addresses, but is this the right thing
to
> > do for *all* possible parameter types?
> > And what about compatibility?
>
> Oops. Yeah, that's badness on both points. I'll have to be reverting
> that part of the change. Like... now.

I understand your points. Could we then get a new type of mapping
specification for applying mappings wordwise? Mapping multiple email
addresses as in the following example is not practicable when only a few
more than two persons are involved:

        [group1]
        to_addr = harry

        [group2]
        to_addr = harry sally

        [maps]
        to_addr = [mail-addresses]

        [mail-addresses]
        harry = harry@example.com
        sally = sally@example.com
        harry sally = harry@example.com sally@example.com
        sally harry = sally@example.com harry@example.com

Something like

        to_addr = [mail-addresses] wordwise

(syntax?) would help. Disadvantage: The same mappings could be used in
two different ways:

        to_addr = [mail-addresses] wordwise
        reply_to = [mail-addresses]

Alternative:

        to_addr = <mail-addresses>

for wordwise mappings. A <mail-addresses> section and
a [mail-addresses] section could coexist, but both would be different
sections. It's possible to do it this way, but it looks strange. And
inventing a new syntax for every extension doesn't seem a good idea.

Another alternative: Let the mapping itself specify how it is applied.
This could be controlled by an option:

        [maps]
        to_addr = [mail-addresses]

        [mail-addresses]
        map_wordwise = yes
        harry = harry@example.com
        sally = sally@example.com

The option could also be set in the [defaults] section. Theoretically,
this is not compatible. But I do not think that anybody has named the
left hand side of a mapping "map_wordwise". But maybe, it's better to
chose a name starting with an underline which also allows for future
extensions without introducing a new name:

        [mail-addresses]
        _mapping_control = wordwise,remap
        harry = harry@example.com
        sally = sally@example.com
        all = harry sally

This example uses a remap extension that allows to map a name to a group
of several persons in a first step, then mapping their names to their
email addresses in a second step. If _mapping_control is not specified
or empty, it's compatible.

I personally like the last alternative most. It's also easy to
implement. Here is a patch:

Index: mailer.py
===================================================================
--- mailer.py (revision 23)
+++ mailer.py (working copy)
@@ -1024,13 +1024,28 @@
         sectname = mapvalue[1:-1]
         if not hasattr(self, sectname):
           raise UnknownMappingSection(sectname)
- # construct a lambda to look up the given value as an option
name,
+ # construct a function to look up the given value as an option
name,
         # and return the option's value. if the option is not present,
- # then just return the value unchanged.
- setattr(self.maps, optname,
- lambda value,
- sect=getattr(self, sectname): getattr(sect,
value,
- value))
+ # then just return the value unchanged. map wordwise and/or
remap
+ # the result if specified by the special _mapping_control option
+ control = self.get('_mapping_control', sectname, None).split("
")
+ getvalue = lambda val, sect=getattr(self, sectname): \
+ val != '_map_control' and getattr(sect, val, val) or val
+ # don't map special option
+
+ def mapper(value, ctrl=control, getval=getvalue, rlim=10):
+ if rlim == 0:
+ raise RemappingLimitExceeded
+ if 'wordwise' in ctrl:
+ mapped = " ".join(map(getval, value.split()))
+ else:
+ mapped = getval(value)
+ if 'remap' in control and mapped != value:
+ return mapper(mapped, rlim=rlim-1) # recursive up to 10
levels
+ else:
+ return mapped
+
+ setattr(self.maps, optname, mapper)
         # mark for removal when all optnames are done
         if sectname not in mapsections:
           mapsections.append(sectname)
@@ -1129,6 +1144,8 @@
   pass
 class UnknownMappingSpec(Exception):
   pass
+class RemappingLimitExceeded(Exception):
+ pass
 class UnknownSubcommand(Exception):
   pass
 

Index: mailer.conf.example
===================================================================
--- mailer.conf.example (revision 20)
+++ mailer.conf.example (working copy)
@@ -243,6 +243,12 @@
 #
 # This will use the given section to map values. The option names in
 # the section are the input values, and the option values are the
result.
+# The special option name _mapping_control is not mapped itself. It can
+# be used to specify how the mapping should be performed. If it
contains
+# "wordwise", the mappings specified in the sections are applied
wordwise.
+# Otherwise, they are applied as a whole. If it contains "remap", the
result
+# of the mapping is again used as input until the value doesn't change
anymore.
+# This process is limited to 10 times to avoid an endless recursion.
 #
 
 #

------------------------------------------------------------------------
Servatius Brandt Phone: +49 89 636-41504
Fujitsu Siemens Computers Fax: +49 89 636-48716
EP SW AD C++ Email: Servatius.Brandt@fujitsu-siemens.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Tue Jun 28 17:12:38 2005

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