2 # Copyright 2013 The Chromium Authors
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
8 Scrapes Chrome channel information and prints out the requested nugget of
12 from __future__ import print_function
21 URL = 'https://omahaproxy.appspot.com/json'
26 data = json.load(urllib.urlopen(URL))
27 except Exception as e:
28 print('Error: could not load %s\n\n%s' % (URL, str(e)))
31 # Iterate to find out valid values for OS, channel, and field options.
36 for os_versions in data:
37 oses.add(os_versions['os'])
39 for version in os_versions['versions']:
41 if field == 'channel':
42 channels.add(version['channel'])
47 channels = sorted(channels)
48 fields = sorted(fields)
50 # Command line parsing fun begins!
51 usage = ('%prog [options]\n'
52 'Print out information about a particular Chrome channel.')
53 parser = optparse.OptionParser(usage=usage)
55 parser.add_option('-o', '--os',
58 help='The operating system of interest: %s '
59 '[default: %%default]' % ', '.join(oses))
60 parser.add_option('-c', '--channel',
63 help='The channel of interest: %s '
64 '[default: %%default]' % ', '.join(channels))
65 parser.add_option('-f', '--field',
68 help='The field of interest: %s '
69 '[default: %%default] ' % ', '.join(fields))
70 (opts, args) = parser.parse_args()
72 # Print out requested data if available.
73 for os_versions in data:
74 if os_versions['os'] != opts.os:
77 for version in os_versions['versions']:
78 if version['channel'] != opts.channel:
81 if opts.field not in version:
84 print(version[opts.field])
87 print('Error: unable to find %s for Chrome %s %s.' % (opts.field, opts.os,
91 if __name__ == '__main__':