1#!/usr/bin/env python2 2# 3# Copyright 2013 Google Inc. All Rights Reserved. 4"""Script to find list of common images (first beta releases) in Chromeos. 5 6Display information about stable ChromeOS/Chrome versions to be used 7by the team developers. The purpose is to increase team productivity 8by using stable (known and tested) ChromeOS/Chrome versions instead of 9using randomly selected versions. Currently we define as a "stable" 10version the first Beta release in a particular release cycle. 11""" 12 13from __future__ import print_function 14 15__author__ = 'llozano@google.com (Luis Lozano)' 16 17import argparse 18import pickle 19import re 20import sys 21import urllib 22 23VERSIONS_HISTORY_URL = 'http://cros-omahaproxy.appspot.com/history' 24 25 26def DisplayBetas(betas): 27 print('List of betas from %s' % VERSIONS_HISTORY_URL) 28 for beta in betas: 29 print(' Release', beta['chrome_major_version'], beta) 30 return 31 32 33def FindAllBetas(all_versions): 34 """Get ChromeOS first betas from History URL.""" 35 36 all_betas = [] 37 prev_beta = {} 38 for line in all_versions: 39 match_obj = re.match( 40 r'(?P<date>.*),(?P<chromeos_version>.*),' 41 r'(?P<chrome_major_version>\d*).(?P<chrome_minor_version>.*),' 42 r'(?P<chrome_appid>.*),beta-channel,,Samsung Chromebook Series 5 550', 43 line) 44 if match_obj: 45 if prev_beta: 46 if (prev_beta['chrome_major_version'] != 47 match_obj.group('chrome_major_version')): 48 all_betas.append(prev_beta) 49 prev_beta = match_obj.groupdict() 50 if prev_beta: 51 all_betas.append(prev_beta) 52 return all_betas 53 54 55def SerializeBetas(all_betas, serialize_file): 56 with open(serialize_file, 'wb') as f: 57 pickle.dump(all_betas, f) 58 print('Serialized list of betas into', serialize_file) 59 return 60 61 62def Main(argv): 63 """Get ChromeOS first betas list from history URL.""" 64 65 parser = argparse.ArgumentParser() 66 parser.add_argument( 67 '--serialize', 68 dest='serialize', 69 default=None, 70 help='Save list of common images into the specified ' 71 'file.') 72 options = parser.parse_args(argv) 73 74 try: 75 opener = urllib.URLopener() 76 all_versions = opener.open(VERSIONS_HISTORY_URL) 77 except IOError as ioe: 78 print('Cannot open', VERSIONS_HISTORY_URL) 79 print(ioe) 80 return 1 81 82 all_betas = FindAllBetas(all_versions) 83 DisplayBetas(all_betas) 84 if options.serialize: 85 SerializeBetas(all_betas, options.serialize) 86 all_versions.close() 87 88 return 0 89 90 91if __name__ == '__main__': 92 retval = Main(sys.argv[1:]) 93 sys.exit(retval) 94