~launchpad-pqm/launchpad/devel

8687.15.8 by Karl Fogel
Add the copyright header block to more files.
1
# Copyright 2009 Canonical Ltd.  This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
1628 by Canonical.com Patch Queue Manager
Configuration, Librian and Librarian test harness work
3
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
4
# Twisted Application Configuration file.
2237 by Canonical.com Patch Queue Manager
[trivial] Libraraian upstream tweaks, which demonstrate the the feature is broken (?)
5
# Use with "twistd2.4 -y <file.tac>", e.g. "twistd -noy server.tac"
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
6
6998.3.2 by Guilherme Salgado
fix the bug.
7
from twisted.application import service, strports
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
8
from twisted.web import server
9
4450.7.1 by James Henstridge
move librarian over to use the webapp database adapter
10
from canonical.config import config, dbconfig
2240 by Canonical.com Patch Queue Manager
My librarian-cleanups branch, held up by baz confusion. r=BjornT
11
from canonical.launchpad.daemons import tachandler
4450.7.1 by James Henstridge
move librarian over to use the webapp database adapter
12
from canonical.launchpad.scripts import execute_zcml_for_scripts
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
13
14
from canonical.librarian.libraryprotocol import FileUploadFactory
15
from canonical.librarian import storage, db
16
from canonical.librarian import web as fatweb
17
18
# Connect to database
4450.7.1 by James Henstridge
move librarian over to use the webapp database adapter
19
dbconfig.setConfigSection('librarian')
20
execute_zcml_for_scripts()
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
21
5863.9.2 by Curtis Hovey
Updated code to use the libraran_server section.
22
path = config.librarian_server.root
23
if config.librarian_server.upstream_host:
24
    upstreamHost = config.librarian_server.upstream_host
25
    upstreamPort = config.librarian_server.upstream_port
5911.2.9 by Francis J. Lacoste
Start a restricted librarian in tests.
26
    print 'Using upstream librarian http://%s:%d' % (
27
        upstreamHost, upstreamPort)
2109 by Canonical.com Patch Queue Manager
[trivial] Add upstream librarian support for the staging environment
28
else:
29
    upstreamHost = upstreamPort = None
6998.3.2 by Guilherme Salgado
fix the bug.
30
31
application = service.Application('Librarian')
32
librarianService = service.IServiceCollection(application)
33
34
# Service that announces when the daemon is ready
35
tachandler.ReadyService().setServiceParent(librarianService)
36
6998.3.3 by Guilherme Salgado
A couple changes after Francis' review
37
def setUpListener(uploadPort, webPort, restricted):
38
    """Set up a librarian listener on the given ports.
39
40
    :param restricted: Should this be a restricted listener?  A restricted
41
        listener will serve only files with the 'restricted' file set and all
42
        files uploaded through the restricted listener will have that flag
43
        set.
44
    """
45
    librarian_storage = storage.LibrarianStorage(
46
        path, db.Library(restricted=restricted))
47
    upload_factory = FileUploadFactory(librarian_storage)
48
    strports.service(str(uploadPort), upload_factory).setServiceParent(
49
        librarianService)
50
    root = fatweb.LibraryFileResource(
51
        librarian_storage, upstreamHost, upstreamPort)
52
    root.putChild('search', fatweb.DigestSearchResource(librarian_storage))
53
    root.putChild('robots.txt', fatweb.robotsTxt)
54
    site = server.Site(root)
55
    site.displayTracebacks = False
56
    strports.service(str(webPort), site).setServiceParent(librarianService)
57
58
# Set up the public librarian.
6998.3.2 by Guilherme Salgado
fix the bug.
59
uploadPort = config.librarian.upload_port
60
webPort = config.librarian.download_port
6998.3.5 by Guilherme Salgado
Aaaargh
61
setUpListener(uploadPort, webPort, restricted=False)
6998.3.2 by Guilherme Salgado
fix the bug.
62
6998.3.3 by Guilherme Salgado
A couple changes after Francis' review
63
# Set up the restricted librarian.
64
webPort = config.librarian.restricted_download_port
6998.3.2 by Guilherme Salgado
fix the bug.
65
uploadPort = config.librarian.restricted_upload_port
6998.3.5 by Guilherme Salgado
Aaaargh
66
setUpListener(uploadPort, webPort, restricted=True)