You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@subversion.apache.org by Marc Sherman <ms...@projectile.ca> on 2005/07/29 15:00:40 UTC

svnperms.py: inherit settings from another section?

Would anyone be interested in a modification to svnperms.py to allow 
sections to inherit settings from previous sections?

We've got a number of repositories, all sharing a single svnperms.conf, 
with the repository name used as the section name -- this seems to be 
the common way to deploy this script.  Our svnperms.conf has a lot of 
duplication in it -- all the repositories share most rules in common, 
with just a few specializations for specific repositories.  Specifying a 
default section that all the repo sections inherit from seems like a 
good way to simplify maintenance of this conf file.

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?

Thanks,
- Marc

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org

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

Posted by Marc Sherman <ms...@projectile.ca>.
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