FileList.py :  » Web-Frameworks » Webware » Webware-1.0.2 » DocSupport » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Web Frameworks » Webware 
Webware » Webware 1.0.2 » DocSupport » FileList.py
#!/usr/bin/env python

"""FileList.py

A quick, hacky script to contruct a file list from a set of Python files.

"""


import os, sys
from glob import glob
from types import StringType


class FileList:
  """Builds a file list for a package of Python modules."""

  def __init__(self, name='Webware'):
    self._name = name
    self._files = []
    self._verbose = 0
    self._filesToIgnore = []

  def addFilesToIgnore(self, list):
    self._filesToIgnore.extend(list)

  def readFiles(self, filename):
    filenames = glob(filename)
    for name in filenames:
      self.readFile(name)

  def readFile(self, name):
    if name in self._filesToIgnore:
      if self._verbose:
        print 'Skipping %s...' % name
      return
    if self._verbose:
      print 'Reading %s...' % name
    self._files.append(name)

  def printList(self, file=sys.stdout):
    if type(file) is StringType:
      file = open(file, 'w')
      close = 1
    else:
      close = 0
    name = self._name
    title = 'File List of %s' % name
    file.write('%s\n%s\n\n' % (title, '='*len(title)))
    files = self._files
    files.sort(lambda a, b: cmp(a.lower(), b.lower()))
    for filename in files:
      file.write(filename + '\n')
    file.write('\n')
    if close:
      file.close()

  def printForWeb(self, file=sys.stdout):
    if type(file) is StringType:
      file = open(file, 'w')
      close = 1
    else:
      close = 0
    name = self._name
    title = 'File List of %s' % name
    other = ('<a href="ClassList.html">alphabetical class list<a>'
      ' and <a href="ClassHierarchy.html">class hierarchy</a>'
      ' of %s' % name)
    file.write('''<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<head>
<title>%s</title>
<style type="text/css">
<!--
body { background: #FFF;
 font-family: Verdana, Arial, Helvetica, sans-serif;
 font-size: 10pt;
 padding: 6pt; }
th { background-color: #CCF; text-align: left; }
td { background-color: #EEF; }
.center { text-align: center; }
.center table { margin-left: auto; margin-right: auto; text-align: left; }
-->
</style>
</head>
<body><div class="center">
<h1>%s</h1>
<p>See also the %s.</p>
<table cellpadding="2" cellspacing="2">
''' % (title, title, other))
    file.write('<tr><th>Source File</th>'
      '<th>Source</th><th>Doc</th><th>Summary</th></tr>\n')
    files = self._files
    files.sort(lambda a, b: cmp(a.lower(), b.lower()))
    for filename in files:
      file.write('<tr><td>%s</td></tr>\n' % self.links(filename))
    file.write('''</table>
</div></body>
</html>''')
    if close:
      file.close()

  def links(self, filename):
    """In support of printForWeb()"""
    name = self._name
    links = []
    # souce file
    if os.path.exists(filename):
      links.append('<a href="../../%s">%s</a>' % (filename, filename))
    else:
      links.append('&nbsp;')
    filename = os.path.basename(filename)
    module = os.path.splitext(filename)[0]
    # highlighted source file
    if os.path.exists('Docs/Source/Files/%s.html' % module):
      links.append('<a href="Files/%s.html">source</a>' % module)
    else:
      links.append('&nbsp;')
    # doc file
    if os.path.exists('Docs/Source/Docs/%s.%s.html' % (name, module)):
      links.append('<a href="Docs/%s.%s.html">doc</a>' % (name, module))
    else:
      links.append('&nbsp;')
    # summary file
    if os.path.exists('Docs/Source/Summaries/%s.html' % module):
      links.append('<a href="Summaries/%s.html">summary</a>' % module)
    else:
      links.append('&nbsp;')
    # finish up
    return '</td><td class="center">'.join(links)


def main(args):
  filelist = FileList()
  for filename in args:
    filelist.readFiles(filename)
  filelist.printList()


if __name__ == '__main__':
  main(sys.argv[1:])
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.