diff options
author | Mike Crute <mcrute@gmail.com> | 2015-07-29 18:21:23 -0700 |
---|---|---|
committer | Mike Crute <mcrute@gmail.com> | 2015-07-29 18:21:23 -0700 |
commit | 4055293e7f0220f67ed4d8efc8de0d702c9b424d (patch) | |
tree | 1f70562de6e64b809d12bc0102281c6a94680574 /repolist.py | |
download | svn_repolist-master.tar.bz2 svn_repolist-master.tar.xz svn_repolist-master.zip |
Diffstat (limited to 'repolist.py')
-rw-r--r-- | repolist.py | 66 |
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 | """ | ||
3 | Subversion Repository Listing Tool | ||
4 | by Mike Crute on July 13, 2008 | ||
5 | for SoftGroup Interactive, Inc. | ||
6 | Released under the terms of the BSD license. | ||
7 | |||
8 | Generate a list of protected and unprotected subversion repositories | ||
9 | within a certain directory and pass those to a mako template. The | ||
10 | original intent was to provide a web-based public listing of svn | ||
11 | repos on a machine but this could be used for anything. | ||
12 | """ | ||
13 | |||
14 | import os | ||
15 | from stat import S_ISDIR as is_directory, ST_MODE as MODE | ||
16 | from ConfigParser import SafeConfigParser | ||
17 | from mako.template import Template | ||
18 | |||
19 | def 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 | |||
54 | if __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 | }) | ||