You are here: Home Tech Testing SVN pre-commit hook permissions

Testing SVN pre-commit hook permissions

by Reed O'Brien last modified Oct 27, 2010 11:46 AM
A quick way to test pre-commit hooks w ihtout making test checkins.

First create a directory where you can put the svnperms.py file from the tools directory of an svn build.

then add two files in the same directory:

  1. svnpaths.py
  2. svnperms.conf

The contents of svnperms.conf should be:

[myrepo]
.*(?!((.*\W/?tags/?)|(tags/?)|(.*\W/?releases/?)|(releases/?))) = *(else )
.*/tags/.*              = *(tagadd)
tags/.*                 = *(startadd)
.*/releases/.*          = *(release)
releases/.*             = *(startrelease)

and the contents od svnpaths.py should be:

#!/usr/bin/env python
#
import re
#
not_tags = re.compile('(?!(.*\W/?tags/?|tags/?))')
tags = re.compile('^.*/tags/.*')
starttags = re.compile('^tags/.*')
#
patterns = {'not_tags'  : not_tags,
            'tags'      : tags,
            'starttags' : starttags
            }
#
paths = ['snark/meeting-notes',
         'snark/meeting-notes/2008',
         'flurbernurf/trunk',
         'flurbernurf/releases/',
         'flurbernurf/tags/foo/bar',
         'flurbernurf/trunk/stags/boo',
         'flurbernurf/branches/not/here',
         'Project/SubProject/',
         'Project/SubProject/branches/',
         'Project/SubProject/branches/foo',
         'Project/SubProject/releases/foo',
         'Project/SubProject/trunk/bar',
         'Project/SubProject/trunk',
         'Project/SubProject/releases',
         'Project/SubProject/tags',
         'Project/SubProject/tagsoup',
         'Project/SubProject/tags/baz',
         'Project/SubProject/tags/',
         'Project/SubProject/stags/',
         'Project/SubProject/sontags',
         'Project/SubProject/son/tag',
         'some/reports'
         'people/reed/reports',
         'tags/this',
         'releases/spam',
         'prereleases/eggs',
         'slacker/prereleases',
         ]
#
#
import sys
import os
sys.path.append(os.path.abspath(os.path.join('__file__', os.pardir)))
#
def main():
    filename = os.path.abspath(os.path.join('svnperms.conf', os.curdir))
   repos = 'myrepo'
   section = 'myrpo'
   author = 'myname'
   from svnperms import Config, Permission
   from pprint import pprint as pp
   c = Config(filename)
   print pp(c.__dict__)
   perm = Permission()
   perm.parse_perms(c.walk(section))
   pp(perm.__dict__)
   permerrors = []
   for path in paths:
       pathperms = perm.get(author, path)
       pp([path, pathperms])
##
if __name__ == '__main__':
    main()

Then running python svnpaths.py will give you output that will tell you how your paths will parsed:

$ ./svnpaths.py
{'_sections_dict': {'myrepo': {'.*(?!((.*\\W/?tags /?)|(tags/?)|(.*\\W/?releases/?)|(releases/?)))': '*(else)',
                              '.*/releases/.*': '*(release)',
                              '.*/tags/.*': '*(tagadd)',
                              'releases/.*': '*(startrelease)',
                              'tags/.*': '*(startadd)'}},
'_sections_list': [('myrepo',
                    [['.*(?!((.*\\W/?tags/?)|(tags/?)|(.*\\W/?releases/?)|(releases/?)))',
                      '*(else)'],
                     ['.*/tags/.*', '*(tagadd)'],
                     ['tags/.*', '*(startadd)'],
                     ['.*/releases/.*', '*(release)'],
                     ['releases/.*',  '*(startrelease)']])]}
None
{'_group': {},
'_permlist': [(<_sre.SRE_Pattern object at 0x206cf0>, ['*'], ['else']),
              (<_sre.SRE_Pattern object at 0x173b10>,['*'], ['tagadd']),
              (<_sre.SRE_Pattern object at 0x168f20>, ['*'], ['startadd']),
               (<_sre.SRE_Pattern object at 0x176620>,  ['*'], ['release']),
               (<_sre.SRE_Pattern object at 0x173b80>,
                ['*'],
                ['startrelease'])]}
['snark/meeting-notes', ['else']]
['snark/meeting-notes/2008', ['else']]
['flurbernurf/trunk', ['else']]
['flurbernurf/releases/', ['release']]
['flurbernurf/tags/foo/bar', ['tagadd']]
['flurbernurf/trunk/stags/boo', ['else']]
['flurbernurf/branches/not/here', ['else']]
['Project/SubProject/', ['else']]
['Project/SubProject/branches/', ['else']]
['Project/SubProject/branches/foo', ['else']]
['Project/SubProject/releases/foo', ['release']]
['Project/SubProject/trunk/bar', ['else']]
['Project/SubProject/trunk', ['else']]
['Project/SubProject/releases', ['else']]
['Project/SubProject/tags', ['else']]
['Project/SubProject/tagsoup', ['else']]
['Project/SubProject/tags/baz', ['tagadd']]
['Project/SubProject/tags/', ['tagadd']]
['Project/SubProject/stags/', ['else']]
['Project/SubProject/sontags', ['else']]
['Project/SubProject/son/tag', ['else']]
['some/reportspeople/reed/reports', ['else']]
['tags/this', ['startadd']]
['releases/spam', ['startrelease']]
['prereleases/eggs', ['else']]
['slacker/prereleases', ['else']]
Share this: