~justin-fathomdb/nova/justinsb-openstack-api-volumes

« back to all changes in this revision

Viewing changes to vendor/Twisted-10.0.0/twisted/scripts/htmlizer.py

  • Committer: Jesse Andrews
  • Date: 2010-05-28 06:05:26 UTC
  • Revision ID: git-v1:bf6e6e718cdc7488e2da87b21e258ccc065fe499
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 2001-2004 Twisted Matrix Laboratories.
 
2
# See LICENSE for details.
 
3
 
 
4
#
 
5
 
 
6
"""HTML pretty-printing for Python source code."""
 
7
 
 
8
__version__ = '$Revision: 1.8 $'[11:-2]
 
9
 
 
10
from twisted.python import htmlizer, usage
 
11
from twisted import copyright
 
12
 
 
13
import os, sys
 
14
 
 
15
header = '''<html><head>
 
16
<title>%(title)s</title>
 
17
<meta name=\"Generator\" content="%(generator)s" />
 
18
%(alternate)s
 
19
%(stylesheet)s
 
20
</head>
 
21
<body>
 
22
'''
 
23
footer = """</body>"""
 
24
 
 
25
styleLink = '<link rel="stylesheet" href="%s" type="text/css" />'
 
26
alternateLink = '<link rel="alternate" href="%(source)s" type="text/x-python" />'
 
27
 
 
28
class Options(usage.Options):
 
29
    synopsis = """%s [options] source.py
 
30
    """ % (
 
31
        os.path.basename(sys.argv[0]),)
 
32
 
 
33
    optParameters = [
 
34
        ('stylesheet', 's', None, "URL of stylesheet to link to."),
 
35
        ]
 
36
    zsh_extras = ["1:source python file:_files -g '*.py'"]
 
37
 
 
38
    def parseArgs(self, filename):
 
39
        self['filename'] = filename
 
40
 
 
41
def run():
 
42
    options = Options()
 
43
    try:
 
44
        options.parseOptions()
 
45
    except usage.UsageError, e:
 
46
        print str(e)
 
47
        sys.exit(1)
 
48
    filename = options['filename']
 
49
    if options.get('stylesheet') is not None:
 
50
        stylesheet = styleLink % (options['stylesheet'],)
 
51
    else:
 
52
        stylesheet = ''
 
53
 
 
54
    output = open(filename + '.html', 'w')
 
55
    try:
 
56
        output.write(header % {
 
57
            'title': filename,
 
58
            'generator': 'htmlizer/%s' % (copyright.longversion,),
 
59
            'alternate': alternateLink % {'source': filename},
 
60
            'stylesheet': stylesheet
 
61
            })
 
62
        htmlizer.filter(open(filename), output,
 
63
                        htmlizer.SmallerHTMLWriter)
 
64
        output.write(footer)
 
65
    finally:
 
66
        output.close()