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 | |
download | svn_repolist-master.tar.bz2 svn_repolist-master.tar.xz svn_repolist-master.zip |
-rw-r--r-- | repolist.py | 66 | ||||
-rw-r--r-- | repolist.tpl | 36 |
2 files changed, 102 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 | }) | ||
diff --git a/repolist.tpl b/repolist.tpl new file mode 100644 index 0000000..7c7ba00 --- /dev/null +++ b/repolist.tpl | |||
@@ -0,0 +1,36 @@ | |||
1 | <html> | ||
2 | <head> | ||
3 | <title>SoftGroup Interactive Subversion Access</title> | ||
4 | <style type="text/css"> | ||
5 | body { | ||
6 | font: 12px Verdana; | ||
7 | } | ||
8 | </style> | ||
9 | </head> | ||
10 | |||
11 | <body> | ||
12 | <h1>SoftGroup Interactive Developer Services</h1> | ||
13 | |||
14 | <p> | ||
15 | Subversion access is provided to SoftGroup Interactive developers and the | ||
16 | open source community. Please use it wisely. If you need access to a repository | ||
17 | email the administrator. This service is monitored by using it you consent to | ||
18 | that monitoring. | ||
19 | </p> | ||
20 | |||
21 | <h2>Public</h2> | ||
22 | <ul> | ||
23 | % for repo in unlocked_repos: | ||
24 | <li><a href="${repo[1]}">${repo[0]}</a></li> | ||
25 | % endfor | ||
26 | </ul> | ||
27 | |||
28 | <h2>Password Protected</h2> | ||
29 | <ul> | ||
30 | % for repo in locked_repos: | ||
31 | <li><a href="${repo[1]}">${repo[0]}</a></li> | ||
32 | % endfor | ||
33 | </ul> | ||
34 | </body> | ||
35 | </html> | ||
36 | |||