2 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
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
19 URL
= 'https://omahaproxy.appspot.com/json'
24 data
= json
.load(urllib
.urlopen(URL
))
25 except Exception as e
:
26 print 'Error: could not load %s\n\n%s' % (URL
, str(e
))
29 # Iterate to find out valid values for OS, channel, and field options.
34 for os_versions
in data
:
35 oses
.add(os_versions
['os'])
37 for version
in os_versions
['versions']:
39 if field
== 'channel':
40 channels
.add(version
['channel'])
45 channels
= sorted(channels
)
46 fields
= sorted(fields
)
48 # Command line parsing fun begins!
49 usage
= ('%prog [options]\n'
50 'Print out information about a particular Chrome channel.')
51 parser
= optparse
.OptionParser(usage
=usage
)
53 parser
.add_option('-o', '--os',
56 help='The operating system of interest: %s '
57 '[default: %%default]' % ', '.join(oses
))
58 parser
.add_option('-c', '--channel',
61 help='The channel of interest: %s '
62 '[default: %%default]' % ', '.join(channels
))
63 parser
.add_option('-f', '--field',
66 help='The field of interest: %s '
67 '[default: %%default] ' % ', '.join(fields
))
68 (opts
, args
) = parser
.parse_args()
70 # Print out requested data if available.
71 for os_versions
in data
:
72 if os_versions
['os'] != opts
.os
:
75 for version
in os_versions
['versions']:
76 if version
['channel'] != opts
.channel
:
79 if opts
.field
not in version
:
82 print version
[opts
.field
]
85 print 'Error: unable to find %s for Chrome %s %s.' % (
86 opts
.field
, opts
.os
, opts
.channel
)
89 if __name__
== '__main__':