1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
6 class HostFileSystemIterator(object):
7 '''Provides methods for iterating through host file systems, in both
8 ascending (oldest to newest version) and descending order.
11 def __init__(self
, file_system_provider
, branch_utility
):
12 self
._file
_system
_provider
= file_system_provider
13 self
._branch
_utility
= branch_utility
15 def _ForEach(self
, channel_info
, callback
, get_next
):
16 '''Iterates through a sequence of file systems defined by |get_next| until
17 |callback| returns False, or until the end of the sequence of file systems
18 is reached. Returns the BranchUtility.ChannelInfo of the last file system
19 for which |callback| returned True.
22 while channel_info
is not None:
23 if channel_info
.branch
== 'master':
24 file_system
= self
._file
_system
_provider
.GetMaster()
26 file_system
= self
._file
_system
_provider
.GetBranch(channel_info
.branch
)
27 if not callback(file_system
, channel_info
):
29 last_true
= channel_info
30 channel_info
= get_next(channel_info
)
33 def Ascending(self
, channel_info
, callback
):
34 return self
._ForEach
(channel_info
, callback
, self
._branch
_utility
.Newer
)
36 def Descending(self
, channel_info
, callback
):
37 return self
._ForEach
(channel_info
, callback
, self
._branch
_utility
.Older
)