<commit_before>#!/usr/bin/python

# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""This module uprevs Chrome for cbuildbot.

After calling, it prints outs CHROME_VERSION_ATOM=(version atom string).  A
caller could then use this atom with emerge to build the newly uprevved version
of Chrome e.g.

./cros_mark_chrome_as_stable tot
Returns chrome-base/chromeos-chrome-8.0.552.0_alpha_r1

emerge-x86-generic =chrome-base/chromeos-chrome-8.0.552.0_alpha_r1
"""

import optparse
import os
import re
import sys
import urllib

sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
import cros_mark_as_stable

sys.path.append(os.path.join(os.path.dirname(__file__), '../lib'))
from cros_build_lib import RunCommand, Info, Warning

BASE_CHROME_SVN_URL = 'http://src.chromium.org/svn'

# Command for which chrome ebuild to uprev.
TIP_OF_TRUNK, LATEST_RELEASE, STICKY = 'tot', 'latest_release', 'stable_release'
CHROME_REV = [TIP_OF_TRUNK, LATEST_RELEASE, STICKY]

# Helper regex's for finding ebuilds.
_CHROME_VERSION_REGEX = '\d+\.\d+\.\d+\.\d+'
_NON_STICKY_REGEX = '%s[(_rc.*)|(_alpha.*)]+' % _CHROME_VERSION_REGEX

# Dir where all the action happens.
_CHROME_OVERLAY_DIR = ('%(srcroot)s/third_party/chromiumos-overlay'
                       '/chromeos-base/chromeos-chrome')

_GIT_COMMIT_MESSAGE = ('Marking %(chrome_rev)s for chrome ebuild with version '
                       '%(chrome_version)s as stable.')


def _GetSvnUrl():
  """Returns the path to the svn url for the given chrome branch."""
  return os.path.join(BASE_CHROME_SVN_URL, 'trunk')


def  _GetTipOfTrunkSvnRevision():
  """Returns the current svn revision for the chrome tree."""
  svn_url = _GetSvnUrl()
  svn_info = RunCommand(['svn', 'info', svn_url], redirect_stdout=True)

  revision_re = re.compile('^Revision:\s+(\d+).*')
  for line in svn_info.splitlines():
    match = revision_re.search(line)
    if match:
      return match.group(1)

  raise Exception('Could not find revision information from %s' % svn_url)


def _GetTipOfTrunkVersion():
  """Returns the current Chrome version."""
  svn_url = _GetSvnUrl()
  chrome_version_file = urllib.urlopen(os.path.join(svn_url, 'src', 'chrome',
                                                    'VERSION'))
  chrome_version_info = chrome_version_file.read()
  chrome_version_file.close()

  # Sanity check.<commit_msg>Print out SVN revision number for TOT chrome pfq builds.<commit_after>#!/usr/bin/python

# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""This module uprevs Chrome for cbuildbot.

After calling, it prints outs CHROME_VERSION_ATOM=(version atom string).  A
caller could then use this atom with emerge to build the newly uprevved version
of Chrome e.g.

./cros_mark_chrome_as_stable tot
Returns chrome-base/chromeos-chrome-8.0.552.0_alpha_r1

emerge-x86-generic =chrome-base/chromeos-chrome-8.0.552.0_alpha_r1
"""

import optparse
import os
import re
import sys
import urllib

sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
import cros_mark_as_stable

sys.path.append(os.path.join(os.path.dirname(__file__), '../lib'))
from cros_build_lib import RunCommand, Info, Warning

BASE_CHROME_SVN_URL = 'http://src.chromium.org/svn'

# Command for which chrome ebuild to uprev.
TIP_OF_TRUNK, LATEST_RELEASE, STICKY = 'tot', 'latest_release', 'stable_release'
CHROME_REV = [TIP_OF_TRUNK, LATEST_RELEASE, STICKY]

# Helper regex's for finding ebuilds.
_CHROME_VERSION_REGEX = '\d+\.\d+\.\d+\.\d+'
_NON_STICKY_REGEX = '%s[(_rc.*)|(_alpha.*)]+' % _CHROME_VERSION_REGEX

# Dir where all the action happens.
_CHROME_OVERLAY_DIR = ('%(srcroot)s/third_party/chromiumos-overlay'
                       '/chromeos-base/chromeos-chrome')

_GIT_COMMIT_MESSAGE = ('Marking %(chrome_rev)s for chrome ebuild with version '
                       '%(chrome_version)s as stable.')


def _GetSvnUrl():
  """Returns the path to the svn url for the given chrome branch."""
  return os.path.join(BASE_CHROME_SVN_URL, 'trunk')


def  _GetTipOfTrunkSvnRevision():
  """Returns the current svn revision for the chrome tree."""
  svn_url = _GetSvnUrl()
  svn_info = RunCommand(['svn', 'info', svn_url], redirect_stdout=True)

  revision_re = re.compile('^Revision:\s+(\d+).*')
  for line in svn_info.splitlines():
    match = revision_re.search(line)
    if match:
      svn_revision = match.group(1)
      Info('Using SVN Revision %s' % svn_revision)
      return svn_revision

  raise Exception('Could not find revision information from %s' % svn_url)


def _GetTipOfTrunkVersion():
  """Returns the current Chrome version."""
  svn_url = _GetSvnUrl()
  chrome_version_file = urllib.urlopen(os.path.join(svn_url, 'src', 'chrome',
                                                    'VERSION'))
  chrome_version_info = chrome_version_file.read()
  chrome_version_file.close()

  # Sanity check.
{'fraction_non_alphanumeric': 0.11987381703470032, 'fraction_numerical': 0.008280757097791799, 'mean_word_length': 3.973529411764706, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4419314', 'n_tokens_mistral': 1818, 'n_tokens_neox': 1744, 'n_words': 441}