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

« back to all changes in this revision

Viewing changes to vendor/Twisted-10.0.0/doc/historic/2003/pycon/tw-deploy/tw-deploy

  • 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
#!/usr/bin/python
 
2
# Requires CVS Slides
 
3
 
 
4
from slides import Lecture, Slide, TitleSlide, Image, Bullet, PRE, URL, SubBullet, NumSlide, toHTML
 
5
 
 
6
PERL_PROCESSOR = """\
 
7
from twisted.web import static, twcgi
 
8
 
 
9
class PerlScript(twcgi.FilteredScript):
 
10
    filter = '/usr/bin/perl' # Points to the perl parser
 
11
"""
 
12
 
 
13
RPY_EXAMPLE = """\
 
14
from twisted.web import resource
 
15
 
 
16
class MyGreatResource(resource.Resource):
 
17
    def render(self, request):
 
18
        return "<html>foo</html>"
 
19
 
 
20
resource = MyGreatResource()
 
21
"""
 
22
 
 
23
lecture = Lecture(
 
24
    "A Twisted Web Tutorial",
 
25
 
 
26
    TitleSlide("Twisted Web -- A tutorial",
 
27
          Image("twistedlogo.png"),
 
28
    ),
 
29
 
 
30
    Slide("Twisted Web -- Where does it fit?",
 
31
          Image("twisted-overview.png"),
 
32
    ),
 
33
    
 
34
    Slide("Setup and Configuration Utilities",
 
35
          Bullet("mktap"),
 
36
          Bullet("twistd"),
 
37
          Bullet("websetroot"),
 
38
    ),
 
39
 
 
40
    Slide("mktap",
 
41
          Bullet("TAP Model"),
 
42
          Bullet("General usage"),
 
43
          Bullet("Flexibility and Power"),
 
44
    ),
 
45
 
 
46
    Slide("mktap web : Common Useful Options",
 
47
          Bullet("--path"),
 
48
          Bullet("--port"),
 
49
          Bullet("--user"),
 
50
          Bullet("--logfile"),
 
51
          Bullet("--processor"),
 
52
    ),
 
53
 
 
54
    Slide("Sample mktap command lines",
 
55
          Bullet(PRE("mktap web")),
 
56
          Bullet(PRE("mktap web --path=/var/www --logfile=/var/log/twistedweb.log")),
 
57
          Bullet(PRE("mktap web --port=80 --path=/var/www --user --mime-type=text/plain")),
 
58
          Bullet(PRE("mktap web --path=/home/nafai/public_html --processor=.pl=PerlProcessor.PerlProcessor --index=index.pl")),
 
59
    ),
 
60
 
 
61
    Slide("twistd : An overview",
 
62
          Bullet("Start a Twisted Application"),
 
63
          Bullet("Loads and instance of twisted.internet.app.Application from a file"),
 
64
          Bullet("Daemonizes, binds to appropriate ports, and starts the Twisted mainloop"),
 
65
    ),
 
66
 
 
67
    Slide("Sample twistd command lines",
 
68
          Bullet(PRE("twistd -f web.tap -l /var/log/twisted.log")),
 
69
          Bullet(PRE("twistd -f web.tap --pidfile /var/run/web.pid")),
 
70
    ),
 
71
 
 
72
    Slide("Shutting down twistd",
 
73
          Bullet("On Unix (in general): "),
 
74
          SubBullet(
 
75
                    Bullet(PRE("kill -9 `cat twistd.pid`"))),
 
76
          Bullet("On Windows: "),
 
77
          SubBullet(
 
78
                    Bullet("Cannot daemonize on Windows, so just run twistd in a command prompt"),
 
79
                    Bullet("Switch to the command prompt, and press Control-C"),
 
80
          ),
 
81
    ),
 
82
 
 
83
    Slide("Shutdown TAPs",
 
84
          Bullet("Since TAPs store persistent data for an application,\
 
85
          a 'shutdown' TAP is created on twistd shutdown"),
 
86
          Bullet("You'll often want to start your Twisted application\
 
87
          on subsequent runs with the shutdown TAP"),
 
88
    ),
 
89
 
 
90
    Slide("twistd and security",
 
91
          Bullet("When twistd is run as root, it will shed root privileges\
 
92
                  for the uid and gid of either the user that created the TAP or those\
 
93
                  specified on the mktap commandline."),
 
94
    ),
 
95
    
 
96
    # Try this out!
 
97
    Slide("websetroot",
 
98
          Bullet("Used to change what the root of the server points to"),
 
99
          Bullet("Set it to a Resource contained either in a Python source file or a Pickle file"),
 
100
    ),       
 
101
 
 
102
    Slide("Sample websetroot command lines",
 
103
          Bullet(PRE("websetroot -p 80 -f web.tap --script rootResource.py")),
 
104
          Bullet(PRE("websetroot -p 8080 -f web.tap --pickle rootPickle")),
 
105
    ),
 
106
    
 
107
    # Resource example
 
108
    # Use the perl example from the docs
 
109
    Slide("What's a Resource?",
 
110
          Bullet("Everything in twisted in represented as twisted.web.resource.Resource object"),
 
111
          Bullet("In general, two calls are made on a resource:"),
 
112
          SubBullet(
 
113
                    Bullet(PRE("getChild()")),
 
114
                    Bullet(PRE("render()")),
 
115
          ),
 
116
    ),
 
117
 
 
118
    Slide("Resource call examples:",
 
119
          Bullet("/foo/bar/baz gets converted to:"
 
120
          ),
 
121
          SubBullet(
 
122
                    Bullet(PRE("site.getChild('foo', request).getChild('bar', request).getChild('baz', request).render(request)")),
 
123
          ),
 
124
          Bullet("/foo/bar/baz/ gets converted to:"
 
125
          ),
 
126
          SubBullet(
 
127
                    Bullet(PRE("site.getChild('foo', request).getChild('bar', request).getChild('baz', request).getChild('', request).render(request)")),
 
128
          ),
 
129
    ),
 
130
 
 
131
    Slide("What do Resources handle?",
 
132
           Bullet("Out of the box, Twisted supports files of all types"),
 
133
           Bullet("HTML, text, etc."),
 
134
           Bullet("Default MIME type can be specified"),
 
135
    ),
 
136
 
 
137
    Slide("What about web development?",
 
138
           Bullet("Twisted Web has what are called processors, which are instances\
 
139
           of classes inherited from resource.Resource"),
 
140
           Bullet("By default, Twisted supports the following file types:"),
 
141
           SubBullet(
 
142
                     Bullet(".php"),
 
143
                     Bullet(".php3"),
 
144
                     Bullet(".cgi"),
 
145
                     Bullet(".epy"),
 
146
                     Bullet(".rpy"),
 
147
                     Bullet(".trp"),
 
148
           ),
 
149
          Bullet("You can also write your own"),
 
150
    ),
 
151
 
 
152
    Slide("Custom Processor: More than One Evil Way to Do It",
 
153
           Bullet("A custom processor to handle Perl CGIs:"),
 
154
           PRE(PERL_PROCESSOR),
 
155
           Bullet("An example of how to use:"),
 
156
           SubBullet(Bullet(PRE("mktap web --path=/home/nafai/public_html --processor=.pl=PerlScript.PerlScript")),
 
157
           ),
 
158
    ),
 
159
 
 
160
    Slide("What about making my own resources?",
 
161
           Bullet("Define a class that inherits from resource.Resource"),
 
162
           Bullet("Define the render() method on that class"),
 
163
           Bullet("For long requests, render() can return NOT_DONE_YET"),
 
164
           Bullet("Then Create a .rpy file that sets resource = to an instance of the class"),
 
165
    ),
 
166
 
 
167
    Slide(".rpy example",
 
168
           PRE(RPY_EXAMPLE),
 
169
    ),
 
170
           
 
171
   Slide("More Stuff",
 
172
          Bullet("In other words, the slides I didn't get to write..."),
 
173
          SubBullet(
 
174
             Bullet("Distributed Servers"),
 
175
             Bullet("Virtual Hosts"),
 
176
             Bullet("Rewrite Rules"),
 
177
             Bullet("Debian configuration"),
 
178
             Bullet("twistedmatrix.com configuration"),
 
179
          ),
 
180
    ),
 
181
)
 
182
 
 
183
if __name__ == '__main__':
 
184
    lecture.renderHTML(".", "tw_deploy-%02d.html", css="main.css")