Modules |
Files |
Inheritance Tree |
Inheritance Graph |
Name Index |
Config
File: Synopsis/Formatter/HTML/FileSource.py
1| # $Id: FileSource.py,v 1.2 2003/02/01 23:59:32 chalky Exp $
2| #
3| # This file is a part of Synopsis.
4| # Copyright (C) 2000-2003 Stephen Davies
5| # Copyright (C) 2000, 2001 Stefan Seefeld
6| #
7| # Synopsis is free software; you can redistribute it and/or modify it
8| # under the terms of the GNU General Public License as published by
9| # the Free Software Foundation; either version 2 of the License, or
10| # (at your option) any later version.
11| #
12| # This program is distributed in the hope that it will be useful,
13| # but WITHOUT ANY WARRANTY; without even the implied warranty of
14| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15| # General Public License for more details.
16| #
17| # You should have received a copy of the GNU General Public License
18| # along with this program; if not, write to the Free Software
19| # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20| # 02111-1307, USA.
21| #
22| # $Log: FileSource.py,v $
23| # Revision 1.2 2003/02/01 23:59:32 chalky
24| # Use full_filename() for file source so don't need file_path any more to
25| # find the original source files.
26| #
27| # Revision 1.1 2003/01/16 12:46:46 chalky
28| # Renamed FilePages to FileSource, FileTree to FileListing. Added FileIndexer
29| # (used to be part of FileTree) and FileDetails.
30| #
31| # Revision 1.22 2002/12/09 04:00:58 chalky
32| # Added multiple file support to parsers, changed AST datastructure to handle
33| # new information, added a demo to demo/C++. AST Declarations now have a
34| # reference to a SourceFile (which includes a filename) instead of a filename.
35| #
36| # Revision 1.21 2002/11/13 02:29:24 chalky
37| # Support exclude_glob option to exclude files from listings. Remove debug info.
38| #
39| # Revision 1.20 2002/11/13 01:01:49 chalky
40| # Improvements to links when using the Nested file layout
41| #
42| # Revision 1.19 2002/11/02 06:37:37 chalky
43| # Allow non-frames output, some refactoring of page layout, new modules.
44| #
45| # Revision 1.18 2002/11/01 03:39:20 chalky
46| # Cleaning up HTML after using 'htmltidy'
47| #
48| # Revision 1.17 2002/10/29 15:00:32 chalky
49| # Put toc in the right place
50| #
51| # Revision 1.16 2002/10/29 12:43:56 chalky
52| # Added flexible TOC support to link to things other than ScopePages
53| #
54| # Revision 1.15 2002/10/26 04:16:49 chalky
55| # Fix bug which didn't like empty paths (when path doesn't start at root
56| # directory)
57| #
58| # Revision 1.14 2002/07/19 14:26:32 chalky
59| # Revert prefix in FileLayout but keep relative referencing elsewhere.
60| #
61| # Revision 1.12 2002/01/13 09:44:51 chalky
62| # Allow formatted source in GUI
63| #
64|
65| # System modules
66| import time, os
67|
68| # Synopsis modules
69| from Synopsis.Core import AST, Util
70|
71| # HTML modules
72| import Page
73| import core
74| import ASTFormatter
75| from core import config
76| from Tags import *
77|
78| # Link module
79| link = None
80| try:
81| link = Util._import("Synopsis.Parser.C++.link")
82| except ImportError:
83| print "Warning: unable to import link module. Continuing..."
84|
85| class FileSource (Page.Page):
86| """A module for creating a page for each file with hyperlinked source"""
87| def __init__(self, manager):
88| Page.Page.__init__(self, manager)
89| # Try old name first for backwards compatibility
90| if hasattr(config.obj, 'FilePages'): myconfig = config.obj.FilePages
91| else: myconfig = config.obj.FileSource
92| self.__linkpath = myconfig.links_path
93| self.__toclist = myconfig.toc_files
94| self.__scope = myconfig.scope
95| # We will NOT be in the Manual directory TODO - use FileLayout for this
96| self.__toclist = map(lambda x: ''+x, self.__toclist)
97| if hasattr(myconfig, 'use_toc'):
98| self.__tocfrom = myconfig.use_toc
99| else:
100| self.__tocfrom = config.default_toc
101|
102| def filename(self):
103| """since FileSource generates a whole file hierarchy, this method returns the current filename,
104| which may change over the lifetime of this object"""
105| return self.__filename
106| def title(self):
107| """since FileSource generates a while file hierarchy, this method returns the current title,
108| which may change over the lifetime of this object"""
109| return self.__title
110|
111| def process(self, start):
112| """Creates a page for every file"""
113| # Get the TOC
114| toc = self.manager.getPage(self.__tocfrom).get_toc(start)
115| tocfile = config.files.nameOfSpecial('FileSourceInputTOC')
116| tocfile = os.path.join(config.basename, tocfile)
117| toc.store(tocfile)
118| self.__toclist.append(tocfile)
119| # create a page for each main file
120| for file in config.ast.files().values():
121| if file.is_main():
122| self.process_node(file)
123|
124| os.unlink(tocfile)
125|
126| def register_filenames(self, start):
127| """Registers a page for every source file"""
128| for file in config.ast.files().values():
129| if file.is_main():
130| filename = file.filename()
131| filename = os.path.join(config.base_dir, filename)
132| filename = config.files.nameOfFileSource(filename)
133| #print "Registering",filename
134| self.manager.register_filename(filename, self, file)
135|
136| def process_node(self, file):
137| """Creates a page for the given file"""
138|
139| # Start page
140| toc = config.toc
141| filename = file.filename()
142| filename = os.path.join(config.base_dir, filename)
143| self.__filename = config.files.nameOfFileSource(filename)
144| #name = list(node.path)
145| #while len(name) and name[0] == '..': del name[0]
146| #source = string.join(name, os.sep)
147| source = file.filename()
148| self.__title = source
149|
150| # Massage toc list to prefix '../../.....' to any relative entry.
151| prefix = rel(self.filename(), '')
152| toc_to_change = config.toc_out
153| toclist = list(self.__toclist)
154| for index in range(len(toclist)):
155| if '|' not in toclist[index]:
156| toclist[index] = toclist[index]+'|'+prefix
157|
158| self.start_file()
159| self.write(self.manager.formatHeader(self.filename()))
160| self.write('File: '+entity('b', self.__title))
161|
162| if not link:
163| # No link module..
164| self.write('link module for highlighting source unavailable')
165| try:
166| self.write(open(file.full_filename(),'r').read())
167| except IOError, e:
168| self.write("An error occurred:"+ str(e))
169| else:
170| self.write('<br><div class="file-all">\n')
171| # Call link module
172| f_out = os.path.join(config.basename, self.__filename) + '-temp'
173| f_in = file.full_filename()
174| f_link = self.__linkpath%source
175| #print "file: %s link: %s out: %s"%(f_in, f_link, f_out)
176| try:
177| link.link(toclist, f_in, f_out, f_link, self.__scope) #, config.types)
178| except link.error, msg:
179| print "An error occurred:",msg
180| try:
181| self.write(open(f_out,'r').read())
182| os.unlink(f_out)
183| except IOError, e:
184| self.write("An error occurred:"+ str(e))
185| self.write("</div>")
186|
187| self.end_file()
188|
189| htmlPageClass = FileSource