~kiko/checkbox/pluggable-questions

« back to all changes in this revision

Viewing changes to plugins/message_exchange.py

  • Committer: Christian Reis
  • Date: 2007-09-19 21:45:48 UTC
  • Revision ID: christian.reis@canonical.com-20070919214548-g105a8uww595nl0y
Rip out curl support, and use urllib2 and a contributed module that handle file posts to submit data. Format data for submission to Launchpad. Almost works -- the hard part, posting the data, is sorted.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
import logging
2
2
import pprint
 
3
import StringIO
3
4
 
4
5
from hwtest.plugin import Plugin
5
6
from hwtest.transport import HTTPTransport
19
20
        self._manager.reactor.call_on("exchange", self.exchange)
20
21
 
21
22
    def exchange(self):
 
23
        message_store = self._manager.message_store
 
24
 
 
25
        # 'field.date_created':    u'2007-08-01',
 
26
        # 'field.format':          u'VERSION_1',
 
27
        # 'field.private':         u'',
 
28
        # 'field.contactable':     u'',
 
29
        # 'field.livecd':          u'',
 
30
        # 'field.submission_id':   u'unique ID 1',
 
31
        # 'field.emailaddress':    u'test@canonical.com',
 
32
        # 'field.distribution':    u'ubuntu',
 
33
        # 'field.distrorelease':   u'5.04',
 
34
        # 'field.architecture':    u'i386',
 
35
        # 'field.system':          u'HP 6543',
 
36
        # 'field.submission_data': data,
 
37
        # 'field.actions.upload':  u'Upload'}
 
38
 
 
39
        fields = {
 
40
            'field.date_created':    u'2007-08-01',
 
41
            'field.format':          u'VERSION_1',
 
42
            'field.private':         u'',
 
43
            'field.contactable':     u'',
 
44
            'field.livecd':          u'',
 
45
            'field.submission_id':   message_store.get_secure_id(),
 
46
            'field.emailaddress':    u'test@canonical.com',
 
47
            'field.distribution':    u'ubuntu',
 
48
            'field.distrorelease':   u'5.04',
 
49
            'field.architecture':    u'i386',
 
50
            'field.system':          u'HP 6543',
 
51
            'field.actions.upload':  u'Upload'}
 
52
 
 
53
        form = []
 
54
        for k, v in fields.items():
 
55
            form.append((k, v.encode("utf-8")))
 
56
 
 
57
 
22
58
        payload = self.make_payload()
23
 
        message_store = self._manager.message_store
24
59
        spayload = bpickle.dumps(payload)
 
60
        f = StringIO.StringIO(spayload)
 
61
        f.name = 'hwdb.data'
 
62
        f.size = len(spayload)
 
63
        form.append(('field.submission_data', f))
 
64
 
25
65
        if logging.getLogger().getEffectiveLevel() <= logging.DEBUG:
26
66
            logging.debug("Sending payload:\n%s", pprint.pformat(payload))
27
 
        ret = self._transport.exchange(spayload, message_store.get_secure_id())
 
67
        ret = self._transport.exchange(form)
 
68
 
 
69
        # XXX: fix beyond this point
 
70
 
28
71
        if not ret:
29
72
            # HACK: this should return a useful error message
30
73
            self._manager.set_error("Invalid Secure ID or submission failure")