/[navidoc]/navidoc/navidoc/modules/navbar.py
ViewVC logotype

Diff of /navidoc/navidoc/modules/navbar.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by benja, Wed Mar 19 13:43:16 2003 UTC revision 1.2 by humppake, Wed Mar 19 15:34:02 2003 UTC
# Line 1  Line 1 
1    #
2    # Copyright (c) 2003 by Benja Fallenstein
3    #
4    # This file is part of Navidoc.
5    #
6    # Navidoc is free software; you can redistribute it and/or modify it under
7    # the terms of the GNU Lesser General Public License as published by
8    # the Free Software Foundation; either version 2 of the License, or
9    # (at your option) any later version.
10    #
11    # Navidoc is distributed in the hope that it will be useful, but WITHOUT
12    # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13    # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General
14    # Public License for more details.
15    #
16    # You should have received a copy of the GNU Lesser General
17    # Public License along with Navidoc; if not, write to the Free
18    # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
19    # MA  02111-1307  USA
20    #
21    
22    #
23    # Written by Benja Fallenstein
24    #
25    
26    __docformat__ = 'reStructuredText'
27    
28  import re, os  import re, os
29    
30    import config
31    
32    from navidoc.utils.path import _slashify
33    
34    dbg = config.dbg.shorthand('navbar')
35    
36  class Tree:  class Tree:
37      re_title = re.compile("<title>(.*)</title>")      re_title = re.compile("<title>(.*)</title>")
38    
# Line 21  class Tree: Line 53  class Tree:
53                    
54          match = self.re_title.search(contents)          match = self.re_title.search(contents)
55          if not match:          if not match:
56              print ("File %s skipped: It does not contain "              dbg(("File %s skipped: It does not contain "
57                     "a <title>.") % filename                     "a <title>.") % filename)
58              return              return
59    
60          name = match.group(1)          name = match.group(1)
# Line 40  class Tree: Line 72  class Tree:
72    
73      def prettyprint(self, indent=""):      def prettyprint(self, indent=""):
74          for el in self.files:          for el in self.files:
75              print "%s%s [%s]" % (indent, el[1],              dbg("%s%s [%s]" % (indent, el[1],
76                                   os.path.basename(el[0]))                                 os.path.basename(el[0])))
77              if len(el) > 2:              if len(el) > 2:
78                  el[2].prettyprint(indent+"  ")                  el[2].prettyprint(indent+"  ")
79    
# Line 54  class Tree: Line 86  class Tree:
86  def simpleNavbar(tree, indent=""):  def simpleNavbar(tree, indent=""):
87      s = ""      s = ""
88      for el in tree.files:      for el in tree.files:
89          s += '%s<a href="%s">%s</a><br>\n' % (indent, el[0], el[1])          s += '%s<a href="%s">%s</a><br>\n' % \
90                 (indent, el[0][len(_slashify(config.working_directory)):len(el[0])], el[1])
91          if len(el) > 2:          if len(el) > 2:
92              s += simpleNavbar(el[2], indent+"&nbsp;&nbsp;")              s += simpleNavbar(el[2], indent+"&nbsp;&nbsp;")
93      return s      return s
94    
95  def insertNavbars(tree, bar=None):  def insertNavbars(tree, bar=None, single_file=None):
96      if bar is None:      if bar is None:
97          bar = '<hr class="footer"/>'          bar = '<hr class="footer"/>'
98          bar += '<div class="left-bar">\n'          bar += '<div class="left-bar">\n'
# Line 69  def insertNavbars(tree, bar=None): Line 102  def insertNavbars(tree, bar=None):
102          bar += simpleNavbar(tree)          bar += simpleNavbar(tree)
103          bar += '</p></div>\n'          bar += '</p></div>\n'
104    
105      for el in tree.files:      if single_file:
106          if len(el) == 2:          s = open(filename).read()
107              s = open(el[0]).read()          i = s.find('<hr class="footer"/>')
108              i = s.find('<hr class="footer"/>')          s = s[:i] + bar + s[i:]
109              s = s[:i] + bar + s[i:]          open(filename, 'w').write(s)
110              open(el[0], 'w').write(s)          dbg("Inserted navbar into %s" % filename)
111              print "Inseted navbar into %s" % el[0]  
112          else:      else:
113              insertNavbars(el[2], bar)          for el in tree.files:
114                if len(el) == 2:
115                    s = open(el[0]).read()
116                    i = s.find('<hr class="footer"/>')
117                    s = s[:i] + bar + s[i:]
118                    open(el[0], 'w').write(s)
119                    dbg( "Inserted navbar into %s" % el[0])
120                else:
121                    insertNavbars(el[2], bar)
122    
123  if __name__ == '__main__':  if __name__ == '__main__':
124      import sys      import sys
125      t = Tree(sys.argv[1])      t = Tree(sys.argv[1])
126      insertNavbars(t)      insertNavbars(t)
127        
128    def postprocess(path):
129        t = Tree(path)
130        insertNavbars(t)

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26