blob: 13dc5d387c4efd2a6f9e51ef16ea39e8b3a541fc [file] [log] [blame]
[email protected]e117e9a2013-01-10 01:17:181#!/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
8Scrapes Chrome channel information and prints out the requested nugget of
9information.
10"""
11
Raul Tambre26d7db42019-09-25 11:06:3512from __future__ import print_function
13
[email protected]e117e9a2013-01-10 01:17:1814import json
15import optparse
16import os
17import string
18import sys
19import urllib
20
21URL = 'https://omahaproxy.appspot.com/json'
22
23
24def main():
25 try:
26 data = json.load(urllib.urlopen(URL))
27 except Exception as e:
Raul Tambre26d7db42019-09-25 11:06:3528 print('Error: could not load %s\n\n%s' % (URL, str(e)))
[email protected]e117e9a2013-01-10 01:17:1829 return 1
30
31 # Iterate to find out valid values for OS, channel, and field options.
32 oses = set()
33 channels = set()
34 fields = set()
35
36 for os_versions in data:
37 oses.add(os_versions['os'])
38
39 for version in os_versions['versions']:
40 for field in version:
41 if field == 'channel':
42 channels.add(version['channel'])
43 else:
44 fields.add(field)
45
46 oses = sorted(oses)
47 channels = sorted(channels)
48 fields = sorted(fields)
49
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)
54
55 parser.add_option('-o', '--os',
56 choices=oses,
57 default='win',
58 help='The operating system of interest: %s '
59 '[default: %%default]' % ', '.join(oses))
60 parser.add_option('-c', '--channel',
61 choices=channels,
62 default='stable',
63 help='The channel of interest: %s '
64 '[default: %%default]' % ', '.join(channels))
65 parser.add_option('-f', '--field',
66 choices=fields,
67 default='version',
68 help='The field of interest: %s '
69 '[default: %%default] ' % ', '.join(fields))
70 (opts, args) = parser.parse_args()
71
72 # Print out requested data if available.
73 for os_versions in data:
74 if os_versions['os'] != opts.os:
75 continue
76
77 for version in os_versions['versions']:
78 if version['channel'] != opts.channel:
79 continue
80
81 if opts.field not in version:
82 continue
83
Raul Tambre26d7db42019-09-25 11:06:3584 print(version[opts.field])
[email protected]e117e9a2013-01-10 01:17:1885 return 0
86
Raul Tambre26d7db42019-09-25 11:06:3587 print('Error: unable to find %s for Chrome %s %s.' % (opts.field, opts.os,
88 opts.channel))
[email protected]e117e9a2013-01-10 01:17:1889 return 1
90
91if __name__ == '__main__':
92 sys.exit(main())