summaryrefslogtreecommitdiff
path: root/repolist.py
diff options
context:
space:
mode:
Diffstat (limited to 'repolist.py')
-rw-r--r--repolist.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/repolist.py b/repolist.py
new file mode 100644
index 0000000..7ab0c39
--- /dev/null
+++ b/repolist.py
@@ -0,0 +1,66 @@
1#!/usr/bin/python
2"""
3Subversion Repository Listing Tool
4by Mike Crute on July 13, 2008
5for SoftGroup Interactive, Inc.
6Released under the terms of the BSD license.
7
8Generate a list of protected and unprotected subversion repositories
9within a certain directory and pass those to a mako template. The
10original intent was to provide a web-based public listing of svn
11repos on a machine but this could be used for anything.
12"""
13
14import os
15from stat import S_ISDIR as is_directory, ST_MODE as MODE
16from ConfigParser import SafeConfigParser
17from mako.template import Template
18
19def get_repos(cfg, protected=False, directory='.', urlprepend="/repos/"):
20 """Get Repository List
21
22 Get a list of subversion repositories on the server by examining
23 a directory. The subdirectories are are looked up in a svn
24 authentication file to determine if they are locked or unlocked
25 and are then yielded to the caller.
26 """
27
28 directory += "/" if not directory.endswith("/") else ""
29
30 # Determine if the default repo policy is to allow reading
31 try:
32 default_policy = 'r' in cfg.get('/', '*')
33 except:
34 default_policy = True
35
36 for item in os.listdir(directory):
37 # Skip item if it's not a directory
38 if not is_directory(os.stat("%s%s" % (directory, item))[MODE]):
39 continue
40
41 try:
42 if 'r' not in cfg.get('%s:/' % item, '*') and protected == True:
43 yield (item, urlprepend + item)
44
45 if 'r' in cfg.get('%s:/' % item, '*') and protected == False:
46 yield (item, urlprepend + item)
47 except:
48 if default_policy != protected:
49 yield (item, urlprepend + item)
50 else:
51 continue
52
53
54if __name__ == "__main__":
55 """SoftGroup Interactive CGI Driver
56 Basically just run the script and output headers for CGI. For internal use.
57 """
58 config = SafeConfigParser()
59 config.readfp(open('/etc/svn/authen.conf'))
60
61 tmpl = Template(filename='repolist.tpl')
62 print "Content-Type: text/html\r\n"
63 print tmpl.render(**{
64 'locked_repos': [x for x in get_repos(config, protected=True, directory="/var/svn")],
65 'unlocked_repos': [x for x in get_repos(config, protected=False, directory="/var/svn")]
66 })