OLD | NEW |
---|---|
(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)) | |
M-A Ruel
2013/01/10 01:06:11
In general, I prefer it to be aligned to = to be c
scherkus (not reviewing)
2013/01/10 01:12:23
comme ça?
M-A Ruel
2013/01/10 01:13:53
Oui, c'est plus lisible.
| |
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()) | |
OLD | NEW |