~kiko/checkbox/pluggable-questions

« back to all changes in this revision

Viewing changes to plugins/message_exchange.py

  • Committer: Christian Reis
  • Date: 2007-09-21 13:14:33 UTC
  • mfrom: (17.1.3 trunk)
  • Revision ID: christian.reis@canonical.com-20070921131433-v12u5s7w9fqsso25
Where is pyflakes when I need it

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
import logging
3
3
import pprint
4
4
import StringIO
 
5
import bz2
 
6
 
 
7
from socket import gethostname
5
8
 
6
9
from hwtest.plugin import Plugin
7
10
from hwtest.transport import HTTPTransport
10
13
 
11
14
class MessageExchange(Plugin):
12
15
    transport_factory = HTTPTransport
13
 
    transport_url = 'https://launchpad.net/hwdb/+submit'
 
16
    transport_url = 'http://192.168.99.181:8086/hwdb/+submit'
14
17
 
15
18
    def __init__(self):
16
19
        self._transport = self.transport_factory(self.transport_url)
46
49
 
47
50
        form.append(('field.actions.upload', u'Upload'))
48
51
 
 
52
        # Set the filename based on the hostname
 
53
        filename = '%s.xml.bz2' % str(gethostname())
 
54
        
 
55
        # bzip2 compress the payload and attach it to the form
49
56
        payload = report.toxml()
50
 
        f = StringIO.StringIO(payload)
51
 
        f.name = 'hwdb.data'
52
 
        f.size = len(payload)
 
57
        cpayload = bz2.compress(payload)
 
58
        f = StringIO.StringIO(cpayload)
 
59
        f.name = filename
 
60
        f.size = len(cpayload)
53
61
        form.append(('field.submission_data', f))
54
62
 
55
63
        logging.info("System ID: %s", report.info['system'])
76
84
            if "Error" in header:
77
85
                # HACK: this should return a useful error message
78
86
                self._manager.set_error("Submission failure")
79
 
                log.error(header)
 
87
                logging.error(header)
80
88
                return
81
89
 
82
90
        response = ret.read()
83
91
        logging.info("Sent %d bytes and received %d bytes in %s.",
84
 
                     len(payload), len(response),
 
92
                     len(form), len(response),
85
93
                     format_delta(time.time() - start_time))
86
94
 
87
95
        if not self._check_response(response):