Chromium Code Reviews| Index: chrome/common/extensions/docs/server2/branch_utility.py |
| diff --git a/chrome/common/extensions/docs/server2/branch_utility.py b/chrome/common/extensions/docs/server2/branch_utility.py |
| index 0dd43d102637f061a065074980889ebebb71a404..d65d94a55d7621d8558c9f8354ce21b9df691bde 100644 |
| --- a/chrome/common/extensions/docs/server2/branch_utility.py |
| +++ b/chrome/common/extensions/docs/server2/branch_utility.py |
| @@ -18,16 +18,34 @@ class BranchUtility(object): |
| channel=None) |
| @staticmethod |
| + def GetAllChannelNames(): |
| + return ('stable', 'beta', 'dev', 'trunk') |
| + |
| + def GetAllBranchNumbers(self): |
| + return [(branch, self.GetChannelInfoForChannelName(branch).branch) |
|
not at google - send to devlin
2013/05/15 08:15:00
This GetChannelInfoForChannelName doesn't actually
epeterson
2013/06/02 00:25:50
Done.
|
| + for branch in BranchUtility.GetAllChannelNames()] |
|
not at google - send to devlin
2013/05/15 08:15:00
channel in
epeterson
2013/06/02 00:25:50
Done.
|
| + |
| + def GetAllVersionNumbers(self): |
| + return [self.GetChannelInfoForChannelName(branch).version |
| + for branch in self.GetAllChannelNames()] |
|
not at google - send to devlin
2013/05/15 08:15:00
channel in
epeterson
2013/06/02 00:25:50
Done.
|
| + |
| + def GetChannelInfoForAllChannels(self): |
|
not at google - send to devlin
2013/05/15 08:15:00
can be just GetAllChannelInfo, shorter.
epeterson
2013/06/02 00:25:50
Done.
|
| + return [self.GetChannelInfoForChannelName(branch) |
| + for branch in self.GetAllChannelNames()] |
|
not at google - send to devlin
2013/05/15 08:15:00
channel in
epeterson
2013/06/02 00:25:50
Done.
|
| + |
| + @staticmethod |
| + def NewestChannel(channels): |
| + for channel in reversed(BranchUtility.GetAllChannelNames()): |
| + if channel in channels: |
| + return channel |
| + |
| + @staticmethod |
| def Create(object_store_creator): |
| return BranchUtility(url_constants.OMAHA_PROXY_URL, |
| AppEngineUrlFetcher(), |
| object_store_creator) |
| @staticmethod |
| - def GetAllChannelNames(): |
| - return ['stable', 'beta', 'dev', 'trunk'] |
| - |
| - @staticmethod |
| def SplitChannelNameFromPath(path): |
| """Splits the channel name out of |path|, returning the tuple |
| (channel_name, real_path). If the channel cannot be determined then returns |
| @@ -37,19 +55,30 @@ class BranchUtility(object): |
| first, second = path.split('/', 1) |
| else: |
| first, second = (path, '') |
| - if first in ['trunk', 'dev', 'beta', 'stable']: |
| + if first in BranchUtility.GetAllChannelNames(): |
| return (first, second) |
| return (None, path) |
| - def GetBranchForChannel(self, channel_name): |
| - """Returns the branch number for a channel name. |
| + def GetChannelInfo(self, channel): |
| + class ChannelInfo(object): |
| + def __init__(self, name, branch, version): |
| + self.name = name |
| + self.branch = branch |
| + self.version = version |
| + |
| + return ChannelInfo(channel, |
| + self._ExtractFromVersionJson(channel, 'branch'), |
| + self._ExtractFromVersionJson(channel, 'version')) |
| + |
| + def _ExtractFromVersionJson(self, channel_name, data_type): |
| + """Returns the branch or version number for a channel name. |
| """ |
| if channel_name == 'trunk': |
| return 'trunk' |
| - branch_number = self._object_store.Get(channel_name).Get() |
| - if branch_number is not None: |
| - return branch_number |
| + data = self._object_store.Get('%s.%s' % (channel_name, data_type)).Get() |
| + if data is not None: |
| + return data |
| try: |
| version_json = json.loads(self._fetcher.Fetch(self._fetch_url).content) |
| @@ -60,23 +89,27 @@ class BranchUtility(object): |
| 'Falling back to "trunk".' % e) |
| return 'trunk' |
| - branch_numbers = {} |
| + numbers = {} |
| for entry in version_json: |
| if entry['os'] not in ['win', 'linux', 'mac', 'cros']: |
| continue |
| for version in entry['versions']: |
| if version['channel'] != channel_name: |
| continue |
| - branch = version['version'].split('.')[2] |
| - if branch not in branch_numbers: |
| - branch_numbers[branch] = 0 |
| + if data_type == 'branch': |
| + number = version['version'].split('.')[2] |
| + elif data_type == 'version': |
| + number = version['version'].split('.')[0] |
| + if number not in numbers: |
| + numbers[number] = 0 |
| else: |
| - branch_numbers[branch] += 1 |
| + numbers[number] += 1 |
| - sorted_branches = sorted(branch_numbers.iteritems(), |
| - None, |
| - operator.itemgetter(1), |
| - True) |
| - self._object_store.Set(channel_name, sorted_branches[0][0]) |
| + sorted_numbers = sorted(numbers.iteritems(), |
| + None, |
| + operator.itemgetter(1), |
| + True) |
| + self._object_store.Set('%s.%s' % (channel_name, data_type), |
| + sorted_numbers[0][0]) |
| - return sorted_branches[0][0] |
| + return sorted_numbers[0][0] |