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

[PATCH] Re: svnperms.py: inherit settings from another section?

From: Marc Sherman <msherman_at_projectile.ca>
Date: 2005-07-29 20:45:40 CEST

Marc Sherman wrote:
> Would anyone be interested in a modification to svnperms.py to allow
> sections to inherit settings from previous sections?
> [snip]
> My python is quite rusty, but it looks like a simple enough change to
> the file -- if I were to post a patch, would anyone out there be
> interested in reviewing it for me?

Here's the patch, against svn trunk. I'd appreciate it if someone who
knows the original script (or even just python better than I do) could
review it for me. In particular, I'm a bit confused about the parallel
lists and dicts in the config parser -- couldn't everything be done with
just the dicts?

The log message:
* tools/hook-scripts/svnperms.py
   (Config._read): add support for section inheritance in the conf file,
   with syntax [SECTION][PARENTSECTION] (the parent section is optional)
* tools/hook-scripts/svnperms.conf.example: add an example of
   inheritance

Index: tools/hook-scripts/svnperms.py
===================================================================
--- tools/hook-scripts/svnperms.py (revision 15484)
+++ tools/hook-scripts/svnperms.py (working copy)
@@ -14,7 +14,7 @@

  class Error(Exception): pass

-SECTION = re.compile(r'\[([^]]+)\]')
+SECTION = re.compile(r'\[([^]]+)\](?:\[([^]]+)\])?')
  OPTION = re.compile(r'(\S+)\s*=\s*(.*)$')

  class Config:
@@ -43,8 +43,19 @@
                  m = SECTION.match(line)
                  if m:
                      sectname = m.group(1)
- cursectdict =
self._sections_dict.setdefault(sectname, {})
- cursectlist = []
+ parentsectname = m.group(2)
+ if parentsectname is None:
+ # No parent section defined, so start a new section
+ cursectdict = self._sections_dict.setdefault \
+ (sectname, {})
+ cursectlist = []
+ else:
+ # Copy the parent section into the new section
+ parentsectdict = self._sections_dict.get \
+ (parentsectname, {})
+ cursectdict = self._sections_dict.setdefault \
+ (sectname, parentsectdict.copy())
+ cursectlist = self.walk(parentsectname)
                      self._sections_list.append((sectname, cursectlist))
                      optname = None
                  elif cursectdict is None:
Index: tools/hook-scripts/svnperms.conf.example
===================================================================
--- tools/hook-scripts/svnperms.conf.example (revision 15484)
+++ tools/hook-scripts/svnperms.conf.example (working copy)
@@ -84,3 +84,13 @@
  updates/[^/]+/[^/]+/releases/.* = autouser(add)
  updates/[^/]+/[^/]+/pristine/ = autouser(add,remove)

+#
+# Sections can inherit settings from previously defined sections, by
+# declaring the parent section in square brackets after the section
+# declaration. In this example, the [example5] section inherits all
+# the settings from [example2], and adds a new setting for a releases
+# directory which behaves like the tags directory:
+
+[example5][example2]
+releases/[^/]+/ = *(add)
+

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org
Received on Fri Jul 29 20:47:15 2005

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