aboutsummaryrefslogtreecommitdiff
path: root/get_common_image_version.py
blob: da36b98fcf8ba6ea1b5a51ae49d4d952fd6136e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/python2
#
# Copyright 2013 Google Inc. All Rights Reserved.
"""Script to find list of common images (first beta releases) in Chromeos.

Display information about stable ChromeOS/Chrome versions to be used
by the team developers. The purpose is to increase team productivity
by using stable (known and tested) ChromeOS/Chrome versions instead of
using randomly selected versions. Currently we define as a "stable"
version the first Beta release in a particular release cycle.
"""

from __future__ import print_function

__author__ = 'llozano@google.com (Luis Lozano)'

import argparse
import pickle
import re
import sys
import urllib

VERSIONS_HISTORY_URL = 'http://cros-omahaproxy.appspot.com/history'


def DisplayBetas(betas):
  print('List of betas from %s' % VERSIONS_HISTORY_URL)
  for beta in betas:
    print('  Release', beta['chrome_major_version'], beta)
  return


def FindAllBetas(all_versions):
  """Get ChromeOS first betas from History URL."""

  all_betas = []
  prev_beta = {}
  for line in all_versions:
    match_obj = re.match(
        r'(?P<date>.*),(?P<chromeos_version>.*),'
        r'(?P<chrome_major_version>\d*).(?P<chrome_minor_version>.*),'
        r'(?P<chrome_appid>.*),beta-channel,,Samsung Chromebook Series 5 550',
        line)
    if match_obj:
      if prev_beta:
        if (prev_beta['chrome_major_version'] !=
            match_obj.group('chrome_major_version')):
          all_betas.append(prev_beta)
      prev_beta = match_obj.groupdict()
  if prev_beta:
    all_betas.append(prev_beta)
  return all_betas


def SerializeBetas(all_betas, serialize_file):
  with open(serialize_file, 'wb') as f:
    pickle.dump(all_betas, f)
    print('Serialized list of betas into', serialize_file)
  return


def Main(argv):
  """Get ChromeOS first betas list from history URL."""

  parser = argparse.ArgumentParser()
  parser.add_argument('--serialize',
                      dest='serialize',
                      default=None,
                      help='Save list of common images into the specified '
                      'file.')
  options = parser.parse_args(argv)

  try:
    opener = urllib.URLopener()
    all_versions = opener.open(VERSIONS_HISTORY_URL)
  except IOError as ioe:
    print('Cannot open', VERSIONS_HISTORY_URL)
    print(ioe)
    return 1

  all_betas = FindAllBetas(all_versions)
  DisplayBetas(all_betas)
  if options.serialize:
    SerializeBetas(all_betas, options.serialize)
  all_versions.close()

  return 0


if __name__ == '__main__':
  retval = Main(sys.argv[1:])
  sys.exit(retval)