~lifeless/python-oops-tools/bug-881400

« back to all changes in this revision

Viewing changes to src/oopstools/scripts/amqp2disk.py

  • Committer: Tarmac
  • Author(s): Robert Collins
  • Date: 2011-10-18 07:06:00 UTC
  • mfrom: (2.1.1 amqp)
  • Revision ID: launchpad@pqm.canonical.com-20111018070600-vy8dsww7szbygctk
Bump to oops-amqp 0.0.0.2, cleanup some cruft.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
__metaclass__ = type
20
20
 
 
21
from functools import partial
21
22
import sys
22
23
import optparse
23
 
import StringIO
24
24
from textwrap import dedent
25
25
 
26
26
import amqplib.client_0_8 as amqp
28
28
import oops_amqp
29
29
import oops_datedir_repo
30
30
 
31
 
from oopstools.oops.helpers import parsedate, load_prefixes
32
31
from oopstools.oops.models import (
33
32
    Oops,
34
33
    parsed_oops_to_model_oops,
35
 
    Prefix,
36
 
    Report,
37
34
    )
38
 
from oopstools.oops.oopsstore import OopsStore
39
 
from oopstools.oops import dbsummaries
40
 
from oopstools.oops.summaries import (
41
 
    WebAppErrorSummary,
42
 
    CheckwatchesErrorSummary,
43
 
    CodeHostingWithRemoteSectionSummary,
44
 
    GenericErrorSummary,
45
 
)
46
35
 
47
36
 
48
37
def main(argv=None):
91
80
    needed('password')
92
81
    needed('vhost')
93
82
    needed('queue')
94
 
    connection = amqp.Connection(host=options.host, userid=options.username,
 
83
    factory = partial(
 
84
        amqp.Connection, host=options.host, userid=options.username,
95
85
        password=options.password, virtual_host=options.vhost)
96
 
    channel = connection.channel()
97
86
    if options.bind_to:
98
 
        channel.queue_declare(options.queue, durable=True, auto_delete=False)
99
 
        channel.queue_bind(options.queue, options.bind_to)
 
87
        connection = factory()
 
88
        try:
 
89
            channel = connection.channel()
 
90
            try:
 
91
                channel.queue_declare(
 
92
                    options.queue, durable=True, auto_delete=False)
 
93
                channel.queue_bind(options.queue, options.bind_to)
 
94
            finally:
 
95
                channel.close()
 
96
        finally:
 
97
            connection.close()
100
98
    config = make_amqp_config(options.output)
101
 
    receiver = oops_amqp.Receiver(config, channel, options.queue)
 
99
    receiver = oops_amqp.Receiver(config, factory, options.queue)
102
100
    try:
103
101
        receiver.run_forever()
104
102
    except KeyboardInterrupt: