| 1 | """ |
|---|
| 2 | |
|---|
| 3 | Lists all files for a given svn directory matching a given filetype |
|---|
| 4 | |
|---|
| 5 | This macro takes 2 parameters, the path and the filetype |
|---|
| 6 | |
|---|
| 7 | """ |
|---|
| 8 | |
|---|
| 9 | import posixpath |
|---|
| 10 | import svn |
|---|
| 11 | import re |
|---|
| 12 | from trac.core import open_svn_repos |
|---|
| 13 | |
|---|
| 14 | from StringIO import StringIO |
|---|
| 15 | |
|---|
| 16 | def execute(hdf, args, env): |
|---|
| 17 | |
|---|
| 18 | path = filetype = '' |
|---|
| 19 | if args: |
|---|
| 20 | argv = [arg.strip() for arg in args.split(',')] |
|---|
| 21 | if len(argv) > 0: |
|---|
| 22 | path = argv[0] |
|---|
| 23 | if len(argv) > 1: |
|---|
| 24 | filetype = argv[1] |
|---|
| 25 | |
|---|
| 26 | repos_dir = env.get_config('trac', 'repository_dir') |
|---|
| 27 | pool, rep, fs_ptr = open_svn_repos(repos_dir) |
|---|
| 28 | |
|---|
| 29 | rev = svn.fs.youngest_rev(fs_ptr, pool) |
|---|
| 30 | root = svn.fs.revision_root(fs_ptr, rev, pool) |
|---|
| 31 | node_type = svn.fs.check_path(root, path, pool) |
|---|
| 32 | |
|---|
| 33 | buf = StringIO() |
|---|
| 34 | if node_type == svn.core.svn_node_dir: |
|---|
| 35 | entries = svn.fs.dir_entries(root, path, pool) |
|---|
| 36 | |
|---|
| 37 | for item in entries.keys(): |
|---|
| 38 | m = re.search(filetype,item) |
|---|
| 39 | if m: |
|---|
| 40 | fullpath = posixpath.join(path,item) |
|---|
| 41 | buf.write('<a href="%s">%s</a> ' % (env.href.file(fullpath), |
|---|
| 42 | item)) |
|---|
| 43 | |
|---|
| 44 | return buf.getvalue() |
|---|
| 45 | |
|---|