Allow supervised users to delete profiles in about:settings.
[chromium-blink-merge.git] / tools / omahaproxy.py
blob75bf43ddef3d8adf4ae176fc7781fe0e61a1cf17
1 #!/usr/bin/env python
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.
6 """Chrome Version Tool
8 Scrapes Chrome channel information and prints out the requested nugget of
9 information.
10 """
12 import json
13 import optparse
14 import os
15 import string
16 import sys
17 import urllib
19 URL = 'https://omahaproxy.appspot.com/json'
22 def main():
23 try:
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))
27 return 1
29 # Iterate to find out valid values for OS, channel, and field options.
30 oses = set()
31 channels = set()
32 fields = set()
34 for os_versions in data:
35 oses.add(os_versions['os'])
37 for version in os_versions['versions']:
38 for field in version:
39 if field == 'channel':
40 channels.add(version['channel'])
41 else:
42 fields.add(field)
44 oses = sorted(oses)
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',
54 choices=oses,
55 default='win',
56 help='The operating system of interest: %s '
57 '[default: %%default]' % ', '.join(oses))
58 parser.add_option('-c', '--channel',
59 choices=channels,
60 default='stable',
61 help='The channel of interest: %s '
62 '[default: %%default]' % ', '.join(channels))
63 parser.add_option('-f', '--field',
64 choices=fields,
65 default='version',
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:
73 continue
75 for version in os_versions['versions']:
76 if version['channel'] != opts.channel:
77 continue
79 if opts.field not in version:
80 continue
82 print version[opts.field]
83 return 0
85 print 'Error: unable to find %s for Chrome %s %s.' % (
86 opts.field, opts.os, opts.channel)
87 return 1
89 if __name__ == '__main__':
90 sys.exit(main())