~roadmr/ubuntu/precise/checkbox/0.13.1

« back to all changes in this revision

Viewing changes to checkbox/message.py

  • Committer: Bazaar Package Importer
  • Author(s): Marc Tardif, Gabor Keleman
  • Date: 2009-08-19 15:36:05 UTC
  • Revision ID: james.westby@ubuntu.com-20090819153605-weo6htup3yi6zn0t
Tags: 0.8~alpha4
* New upstream version:
  * Changed icon.
  * Added timeout property to lock_prompt plugin.
  * Added concept of attachments to tests.
  * Added support for backslahes in templates to wrap lines.
  * Added support blacklisting and whitelisting both tests and suites.
  * Introduced the concept of jobs for suites, tests and attachments.
  * Removed upstart event which is no longer needed.
  * Replaced architecture and category with requires in test definitions.
* Fixed pygst dependency (LP: #334442)
* Fixed configuration file updates during install (LP: #330596)
* Fixed and expanded translations (LP: #347038)
* Fixed ignored system proxy settings (LP: #345548)
* Fixed parsing blank lines in templates (LP: #393907)
* Fixed escaping of lists (LP: #394001)
* Fixed timeout in manual tests (LP: #377986)
* Fixed CLI interface dialog.
* Fixed support for FreeDesktop XDG base directory specification (LP: #363549)
* Added general and package specific apport hooks

[ Gabor Keleman ]
* Fixed untranslated strings in tests (LP: #374666)
* Fixed untranslated last screen (LP: #374646)

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
    def __init__(self, persist, directory, directory_size=1000):
37
37
        self._directory = directory
38
38
        self._directory_size = directory_size
39
 
        self._schemas = {}
40
39
        self._original_persist = persist
41
40
        self._persist = persist.root_at("message-store")
42
41
        message_dir = self._message_dir()
47
46
        """Save metadata to disk."""
48
47
        self._original_persist.save()
49
48
 
50
 
    def set_accepted_types(self, types):
51
 
        """Specify the types of messages that the server will expect from us.
52
 
 
53
 
        If messages are added to the store which are not currently
54
 
        accepted, they will be saved but ignored until their type is
55
 
        accepted.
56
 
        """
57
 
        assert type(types) in (tuple, list, set)
58
 
        self._persist.set("accepted-types", sorted(set(types)))
59
 
        self._reprocess_holding()
60
 
 
61
 
    def get_accepted_types(self):
62
 
        return self._persist.get("accepted-types", ())
63
 
 
64
 
    def accepts(self, type):
65
 
        accepted_types = self.get_accepted_types()
66
 
        return not accepted_types or type in accepted_types
67
 
 
68
49
    def get_sequence(self):
69
50
        """
70
51
        Get the sequence number of the message that the server expects us to
109
90
                logging.exception(e)
110
91
                self._add_flags(filename, BROKEN)
111
92
            else:
112
 
                if not self.accepts(message["type"]):
113
 
                    self._add_flags(filename, HELD)
114
 
                else:
115
 
                    messages.append(message)
 
93
                messages.append(message)
116
94
        return messages
117
95
 
118
96
    def set_pending_flags(self, flags):
141
119
        for filename in self._walk_messages():
142
120
            os.unlink(filename)
143
121
 
144
 
    def add_schema(self, schema):
145
 
        """Add a schema to be applied to messages of the given type.
146
 
 
147
 
        The schema must be an instance of L{landscape.schema.Message}.
148
 
        """
149
 
        self._schemas[schema.type] = schema
150
 
 
151
122
    def is_pending(self, message_id):
152
123
        """Return bool indicating if C{message_id} still hasn't been delivered.
153
124
 
170
141
        @return: message_id, which is an identifier for the added message.
171
142
        """
172
143
        assert "type" in message
173
 
        if message["type"] in self._schemas:
174
 
            message = self._schemas[message["type"]].coerce(message)
175
144
 
176
145
        message_data = bpickle.dumps(message)
177
146
 
182
151
        file.close()
183
152
        os.rename(filename + ".tmp", filename)
184
153
 
185
 
        if not self.accepts(message["type"]):
186
 
            filename = self._set_flags(filename, HELD)
187
 
 
188
154
        # For now we use the inode as the message id, as it will work
189
155
        # correctly even faced with holding/unholding.  It will break
190
156
        # if the store is copied over for some reason, but this shouldn't
250
216
        finally:
251
217
            file.close()
252
218
 
253
 
    def _reprocess_holding(self):
254
 
        """
255
 
        Unhold accepted messages left behind, and hold unaccepted
256
 
        pending messages.
257
 
        """
258
 
        offset = 0
259
 
        pending_offset = self.get_pending_offset()
260
 
        for old_filename in self._walk_messages():
261
 
            flags = self._get_flags(old_filename)
262
 
            try:
263
 
                message = bpickle.loads(self._get_content(old_filename))
264
 
            except ValueError, e:
265
 
                logging.exception(e)
266
 
                if HELD not in flags:
267
 
                    offset += 1
268
 
            else:
269
 
                accepted = self.accepts(message["type"])
270
 
                if HELD in flags:
271
 
                    if accepted:
272
 
                        new_filename = self._get_next_message_filename()
273
 
                        os.rename(old_filename, new_filename)
274
 
                        self._set_flags(new_filename, set(flags)-set(HELD))
275
 
                else:
276
 
                    if not accepted and offset >= pending_offset:
277
 
                        self._set_flags(old_filename, set(flags)|set(HELD))
278
 
                    offset += 1
279
 
 
280
219
    def _get_flags(self, path):
281
220
        basename = posixpath.basename(path)
282
221
        if "_" in basename: