Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(587)

Side by Side Diff: tools/omahaproxy.py

Issue 11789004: Add omahaproxy.py for accessing Chrome channel information from the command line. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: align Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
5
6 """Chrome Version Tool
7
8 Scrapes Chrome channel information and prints out the requested nugget of
9 information.
10 """
11
12 import json
13 import optparse
14 import os
15 import string
16 import sys
17 import urllib
18
19 URL = 'https://omahaproxy.appspot.com/json'
20
21
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
28
29 # Iterate to find out valid values for OS, channel, and field options.
30 oses = set()
31 channels = set()
32 fields = set()
33
34 for os_versions in data:
35 oses.add(os_versions['os'])
36
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)
43
44 oses = sorted(oses)
45 channels = sorted(channels)
46 fields = sorted(fields)
47
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)
52
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()
69
70 # Print out requested data if available.
71 for os_versions in data:
72 if os_versions['os'] != opts.os:
73 continue
74
75 for version in os_versions['versions']:
76 if version['channel'] != opts.channel:
77 continue
78
79 if opts.field not in version:
80 continue
81
82 print version[opts.field]
83 return 0
84
85 print 'Error: unable to find %s for Chrome %s %s.' % (
86 opts.field, opts.os, opts.channel)
87 return 1
88
89 if __name__ == '__main__':
90 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698