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

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

From: Marc Sherman <msherman_at_projectile.ca>
Date: 2005-07-30 16:31:49 CEST

Having not gotten a reply to this on the users lists, I re-read the
HACKING instructions, and am reposting this to the dev list (hopefully
correctly this time).

This is a patch against svn trunk to add section inheritance to the
config parser in the snvperms.py hook script.

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:

[[[
Patch by: Marc Sherman <msherman@projectile.ca>

* 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: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Sat Jul 30 16:32:32 2005

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