File: addressbook-slides-server.tac

package info (click to toggle)
ldaptor 0.0.43%2Bdebian1-3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 2,168 kB
  • ctags: 3,592
  • sloc: python: 18,670; xml: 787; makefile: 147; sh: 88
file content (39 lines) | stat: -rw-r--r-- 1,396 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# -*- python -*-
# run me with "twistd -noy addressbook-slides-server.tac"
from twisted.application import service, internet
from twisted.web import server, resource, static
from twisted.internet import protocol, reactor
from cStringIO import StringIO
import re

class StartMeld(resource.Resource):
    isLeaf = True
    safeRe = re.compile('^\d\d_[a-z]+')

    def render(self, request):
        request.setHeader('content-type', 'text/plain')
        if len(request.postpath) != 2:
            return 'Usage: /diff/FROM/TO\n'

        from_, to = request.postpath

        if not self.safeRe.match(from_):
            return 'Path element "from" is invalid.\n'
        if not self.safeRe.match(to):
            return 'Path element "to" is invalid.\n'

        proto = protocol.ProcessProtocol()
        reactor.spawnProcess(proto,
                             'meld',
                             ['meld',
                              'examples/addressbook/%s' % from_,
                              'examples/addressbook/%s' % to],
                             env=None)
        return 'Launched comparison of %s and %s.\n' % (from_, to)

application = service.Application("addressbook-slides")
resource = static.File('addressbook-slides')
resource.putChild('diff', StartMeld())
site = server.Site(resource)
webServer = internet.TCPServer(8087, site)
webServer.setServiceParent(application)