summaryrefslogtreecommitdiffstats
path: root/tools/omahaproxy.py
diff options
context:
space:
mode:
authorscherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-10 01:17:18 +0000
committerscherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-10 01:17:18 +0000
commite117e9a2d75fb268fb6a89abaa0d6f1bfa11f01e (patch)
tree32898edce4243a85f733f13f530f6e9f294816eb /tools/omahaproxy.py
parent827120bb2dcb2038a6db08ec089704804fcc4900 (diff)
downloadchromium_src-e117e9a2d75fb268fb6a89abaa0d6f1bfa11f01e.zip
chromium_src-e117e9a2d75fb268fb6a89abaa0d6f1bfa11f01e.tar.gz
chromium_src-e117e9a2d75fb268fb6a89abaa0d6f1bfa11f01e.tar.bz2
Add omahaproxy.py for accessing Chrome channel information from the command line.
Review URL: https://codereview.chromium.org/11789004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175962 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/omahaproxy.py')
-rwxr-xr-xtools/omahaproxy.py90
1 files changed, 90 insertions, 0 deletions
diff --git a/tools/omahaproxy.py b/tools/omahaproxy.py
new file mode 100755
index 0000000..75bf43d
--- /dev/null
+++ b/tools/omahaproxy.py
@@ -0,0 +1,90 @@
+#!/usr/bin/env python
+# Copyright (c) 2013 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Chrome Version Tool
+
+Scrapes Chrome channel information and prints out the requested nugget of
+information.
+"""
+
+import json
+import optparse
+import os
+import string
+import sys
+import urllib
+
+URL = 'https://omahaproxy.appspot.com/json'
+
+
+def main():
+ try:
+ data = json.load(urllib.urlopen(URL))
+ except Exception as e:
+ print 'Error: could not load %s\n\n%s' % (URL, str(e))
+ return 1
+
+ # Iterate to find out valid values for OS, channel, and field options.
+ oses = set()
+ channels = set()
+ fields = set()
+
+ for os_versions in data:
+ oses.add(os_versions['os'])
+
+ for version in os_versions['versions']:
+ for field in version:
+ if field == 'channel':
+ channels.add(version['channel'])
+ else:
+ fields.add(field)
+
+ oses = sorted(oses)
+ channels = sorted(channels)
+ fields = sorted(fields)
+
+ # Command line parsing fun begins!
+ usage = ('%prog [options]\n'
+ 'Print out information about a particular Chrome channel.')
+ parser = optparse.OptionParser(usage=usage)
+
+ parser.add_option('-o', '--os',
+ choices=oses,
+ default='win',
+ help='The operating system of interest: %s '
+ '[default: %%default]' % ', '.join(oses))
+ parser.add_option('-c', '--channel',
+ choices=channels,
+ default='stable',
+ help='The channel of interest: %s '
+ '[default: %%default]' % ', '.join(channels))
+ parser.add_option('-f', '--field',
+ choices=fields,
+ default='version',
+ help='The field of interest: %s '
+ '[default: %%default] ' % ', '.join(fields))
+ (opts, args) = parser.parse_args()
+
+ # Print out requested data if available.
+ for os_versions in data:
+ if os_versions['os'] != opts.os:
+ continue
+
+ for version in os_versions['versions']:
+ if version['channel'] != opts.channel:
+ continue
+
+ if opts.field not in version:
+ continue
+
+ print version[opts.field]
+ return 0
+
+ print 'Error: unable to find %s for Chrome %s %s.' % (
+ opts.field, opts.os, opts.channel)
+ return 1
+
+if __name__ == '__main__':
+ sys.exit(main())