File: Synopsis/Formatters/SXR.py 1
2
3
4
5
6
7
8"""The SXR Facade around the HTML Formatter """
9
10from Synopsis import config
11from Synopsis import IR
12from Synopsis.Processor import *
13import HTML
14from HTML.View import View, Template
15from HTML.Views import Directory, Source, RawFile
16import os, os.path
17from shutil import copyfile
18
19class SXRIndex(View):
20 """Top level Index View. This is the starting point for the SXR browser."""
21
22 sxr_cgi = Parameter('sxr.cgi', 'URL to use for sxr.cgi script')
23
24 def filename(self):
25
26 return self.directory_layout.index()
27
28 def title(self):
29
30 return 'Index'
31
32 def root(self):
33
34 return self.filename(), self.title()
35
36 def process(self):
37 """Recursively visit each directory below the base path given in the
38 config."""
39
40 self.start_file()
41
42 self.write("""
43<table class="form">
44 <tr>
45 <td>Click here to start browsing at the root of the directory tree:</td>
46 <td>
47 <a href="dir.html">/</a>
48 </td>
49 </tr>
50 <tr>
51 <td>Enter a file name to search:</td>
52 <td>
53 <form method="get" action="%(script)s/file">
54 <input type="text" name="string" value="" size="15"/>
55 <input type="submit" value="Find"/>
56 </form>
57 </td>
58 </tr>
59 <tr>
60 <td>Enter a variable, type, or function name to search:</td>
61 <td>
62 <form method="get" action="%(script)s/ident">
63 <input type="text" name="string" value="" size="15"/>
64 <input type="submit" value="Find"/>
65 </form>
66 </td>
67 </tr>
68</table>
69"""%{'script' : self.sxr_cgi})
70 self.end_file()
71
72class Formatter(Processor):
73 """This is a facade to the HTML.Formatter. It adds an 'url' parameter and
74 dispatches it to various 'views'."""
75
76 title = Parameter('Synopsis - Cross-Reference', 'title to put into html header')
77 url = Parameter('/sxr.cgi', 'the base url to use for the sxr cgi')
78 sxr_prefix = Parameter(None, 'path prefix (directory) to contain sxr info')
79 src_dir = Parameter('', 'starting point for directory listing')
80 exclude = Parameter([], 'TODO: define an exclusion mechanism (glob based ?)')
81 sxr_template = Parameter(os.path.join(config.datadir, 'sxr-template.html'), 'html template to be used by the sxr.cgi script')
82 stylesheet = Parameter(os.path.join(config.datadir, 'html.css'), 'stylesheet to be used')
83
84 def process(self, ir, **kwds):
85
86 self.set_parameters(kwds)
87 if not self.output: raise MissingArgument('output')
88 if not self.sxr_prefix: raise MissingArgument('sxr_prefix')
89
90 self.ir = self.merge_input(ir)
91
92 if not os.path.exists(self.output): os.makedirs(self.output)
93
94 content = [SXRIndex(sxr_cgi = self.url,
95 template = Template(template = self.sxr_template)),
96 Directory(src_dir = self.src_dir,
97 base_path = self.src_dir,
98 exclude = self.exclude,
99 template = Template(template = self.sxr_template)),
100 Source(external_url = '%s/ident?full=1&string='%self.url,
101 template = Template(template = self.sxr_template)),
102 RawFile(src_dir = self.src_dir,
103 base_path = self.src_dir,
104 exclude = self.exclude,
105 template = Template(template = self.sxr_template))]
106
107 html = HTML.Formatter(index = [],
108 detail = [],
109 content = content,
110 sxr_prefix = self.sxr_prefix,
111 stylesheet = self.stylesheet)
112 self.ir = html.process(self.ir, output = self.output)
113
114 if self.sxr_template:
115 copyfile(self.sxr_template,
116 os.path.join(self.output, 'sxr-template.html'))
117
118
119 ir = IR.IR(sxr=self.ir.sxr)
120 ir.save(os.path.join(self.output, 'sxr.syn'))
121
122 return self.ir
123
Generated on Thu Apr 16 16:27:12 2009 by
synopsis (version devel)