~ubuntu-branches/ubuntu/lucid/landscape-client/lucid-updates

« back to all changes in this revision

Viewing changes to landscape/broker/store.py

  • Committer: Package Import Robot
  • Author(s): Andreas Hasenack
  • Date: 2012-04-10 14:28:48 UTC
  • mfrom: (1.1.27)
  • mto: This revision was merged to the branch mainline in revision 35.
  • Revision ID: package-import@ubuntu.com-20120410142848-7xsy4g2xii7y7ntc
ImportĀ upstreamĀ versionĀ 12.04.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
    history of our exchanges with the server.  What we call "server
35
35
    sequence", is the next message number expected by the *client* itself,
36
36
    and is entirely unrelated to the stored messages.
 
37
 
 
38
    @param persist: a L{Persist} used to save state parameters like the
 
39
        accepted message types, sequence, server uuid etc.
 
40
    @param directory: base of the file system hierarchy
37
41
    """
38
42
 
39
43
    api = SERVER_API
40
44
 
41
45
    def __init__(self, persist, directory, directory_size=1000,
42
 
                 monitor_interval=60*60, get_time=time.time):
43
 
        """
44
 
        @param persist: a L{Persist} used to save state parameters like
45
 
            the accepted message types, sequence, server uuid etc.
46
 
        @param directory: base of the file system hierarchy
47
 
        """
 
46
                 monitor_interval=60 * 60, get_time=time.time):
48
47
        self._get_time = get_time
49
48
        self._directory = directory
50
49
        self._directory_size = directory_size
81
80
    def get_sequence(self):
82
81
        """Get the current sequence.
83
82
 
84
 
        @return: The sequence number of the message that the server expects us to
85
 
           send on the next exchange.
 
83
        @return: The sequence number of the message that the server expects us
 
84
            to send on the next exchange.
86
85
        """
87
86
        return self._persist.get("sequence", 0)
88
87
 
97
96
    def get_server_sequence(self):
98
97
        """Get the current server sequence.
99
98
 
100
 
        @return: the sequence number of the message that we will ask the server to
101
 
            send to us on the next exchange.
 
99
        @return: the sequence number of the message that we will ask the server
 
100
            to send to us on the next exchange.
102
101
        """
103
102
        return self._persist.get("server_sequence", 0)
104
103
 
160
159
 
161
160
    def delete_old_messages(self):
162
161
        """Delete messages which are unlikely to be needed in the future."""
163
 
        for fn in itertools.islice(self._walk_messages(exclude=HELD+BROKEN),
 
162
        for fn in itertools.islice(self._walk_messages(exclude=HELD + BROKEN),
164
163
                                   self.get_pending_offset()):
165
164
            os.unlink(fn)
166
165
            containing_dir = os.path.split(fn)[0]
255
254
    def _walk_pending_messages(self):
256
255
        """Walk the files which are definitely pending."""
257
256
        pending_offset = self.get_pending_offset()
258
 
        for i, filename in enumerate(self._walk_messages(exclude=HELD+BROKEN)):
 
257
        for i, filename in enumerate(self._walk_messages(exclude=HELD +
 
258
                                                                 BROKEN)):
259
259
            if i >= pending_offset:
260
260
                yield filename
261
261
 
307
307
                    if accepted:
308
308
                        new_filename = self._get_next_message_filename()
309
309
                        os.rename(old_filename, new_filename)
310
 
                        self._set_flags(new_filename, set(flags)-set(HELD))
 
310
                        self._set_flags(new_filename, set(flags) - set(HELD))
311
311
                else:
312
312
                    if not accepted and offset >= pending_offset:
313
 
                        self._set_flags(old_filename, set(flags)|set(HELD))
 
313
                        self._set_flags(old_filename, set(flags) | set(HELD))
314
314
                    offset += 1
315
315
 
316
316
    def _get_flags(self, path):
323
323
        dirname, basename = os.path.split(path)
324
324
        new_path = os.path.join(dirname, basename.split("_")[0])
325
325
        if flags:
326
 
            new_path += "_"+"".join(sorted(set(flags)))
 
326
            new_path += "_" + "".join(sorted(set(flags)))
327
327
        os.rename(path, new_path)
328
328
        return new_path
329
329
 
330
330
    def _add_flags(self, path, flags):
331
 
        self._set_flags(path, self._get_flags(path)+flags)
 
331
        self._set_flags(path, self._get_flags(path) + flags)
332
332
 
333
333
 
334
334
def get_default_message_store(*args, **kwargs):
335
 
    """Get a L{MessageStore} object with all Landscape message schemas added."""
 
335
    """
 
336
    Get a L{MessageStore} object with all Landscape message schemas added.
 
337
    """
336
338
    from landscape. message_schemas import message_schemas
337
339
    store = MessageStore(*args, **kwargs)
338
340
    for schema in message_schemas.values():