Edgewall Software

MacroBazaar: SvnFiles.py

File SvnFiles.py, 1.1 KB (added by anonymous, 7 years ago)

SvnFiles? macro

Line 
1"""
2
3Lists all files for a given svn directory matching a given filetype
4
5This macro takes 2 parameters, the path and the filetype
6
7"""
8
9import posixpath
10import svn
11import re
12from trac.core import open_svn_repos
13
14from StringIO import StringIO
15
16def 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