Modules |
Files |
Inheritance Tree |
Inheritance Graph |
Name Index |
Config
File: Synopsis/Formatter/HTML/FileListing.py
1| # $Id: FileListing.py,v 1.1 2003/01/16 12:46:46 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: FileListing.py,v $
23| # Revision 1.1 2003/01/16 12:46:46 chalky
24| # Renamed FilePages to FileSource, FileTree to FileListing. Added FileIndexer
25| # (used to be part of FileTree) and FileDetails.
26| #
27| # Revision 1.18 2003/01/02 07:00:58 chalky
28| # Only use Core.FileTree, refactored FileTree to be quicker and better.
29| #
30| # Revision 1.17 2002/12/12 17:25:33 chalky
31| # Implemented Include support for C++ parser. A few other minor fixes.
32| #
33| # Revision 1.16 2002/11/02 06:37:37 chalky
34| # Allow non-frames output, some refactoring of page layout, new modules.
35| #
36| # Revision 1.15 2002/11/01 07:21:15 chalky
37| # More HTML formatting fixes eg: ampersands and stuff
38| #
39| # Revision 1.14 2002/10/29 12:43:56 chalky
40| # Added flexible TOC support to link to things other than ScopePages
41| #
42|
43| # System modules
44| import os
45|
46| # Synopsis modules
47| from Synopsis.Core import AST, Util
48| from Synopsis.Core.FileTree import FileTree
49|
50| # HTML modules
51| import Page
52| import core
53| from core import config
54| from Tags import *
55|
56| class FileListing (Page.Page):
57| """A page that creates an index of files, and an index for each file.
58| First the index of files is created, intended for the top-left frame.
59| Second a page is created for each file, listing the major declarations for
60| that file, eg: classes, global functions, namespaces, etc."""
61| def __init__(self, manager):
62| Page.Page.__init__(self, manager)
63| self.__filename = config.files.nameOfSpecial('FileListing')
64| self.__title = 'Files'
65|
66| def filename(self):
67| """Returns the filename"""
68| return self.__filename
69| def title(self):
70| """Returns the title"""
71| return self.__title
72|
73| def register(self):
74| """Registers this page for the top-left frame"""
75| config.set_main_page(self.filename())
76| # Reset filename in case we got main page status
77| self.__filename = config.files.nameOfSpecial('FileListing')
78| self.manager.addRootPage(self.filename(), self.title(), "contents", 2)
79| config.set_contents_page(self.filename())
80|
81| def register_filenames(self, start):
82| """Registers a page for each file indexed"""
83| self.manager.register_filename(self.__filename, self, None)
84|
85| def process(self, start):
86| """Creates the listing using the recursive processFileTreeNode method"""
87| # Init tree
88| self.tree = config.treeFormatterClass(self)
89| # Start the file
90| self.start_file()
91| self.write(self.manager.formatHeader(self.filename(), 2))
92| self.tree.startTree()
93| # recursively visit all nodes
94| self.processFileTreeNode(config.fileTree.root())
95| self.tree.endTree()
96| self.end_file()
97|
98| def _node_sorter(self, a, b):
99| """Compares file nodes a and b depending on whether they are leaves
100| or not"""
101| a_leaf = isinstance(a, FileTree.File)
102| b_leaf = isinstance(a, FileTree.File)
103| if a_leaf != b_leaf:
104| return cmp(b_leaf, a_leaf)
105| return cmp(string.upper(a.path), string.upper(b.path))
106|
107| def processFileTreeNode(self, node):
108| """Creates a portion of the tree for the given file node. This method
109| assumes that the file is already in progress, and just appends to
110| it. This method is recursive, calling itself for each child of node
111| (file or directory)."""
112| if isinstance(node, FileTree.File):
113| # Leaf node
114| ref = rel(self.filename(), config.files.nameOfFileIndex(node.path))
115| text = href(ref, node.filename, target='index')
116| self.tree.writeLeaf(text)
117| return
118| # Non-leaf node
119| children = node.children
120| children.sort(self._node_sorter)
121| if len(node.path):
122| self.tree.writeNodeStart(node.filename+os.sep)
123| if len(children):
124| for child in children:
125| self.processFileTreeNode(child)
126| if len(node.path):
127| self.tree.writeNodeEnd()
128|
129| htmlPageClass = FileListing