<commit_before># Copyright 2015 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.

# TODO(qyearsley): Add a step to vulcanize each template HTML file.
# TODO(qyearsley): Add a step to put static files in a versioned
# directory and modify app.yaml and request_handler as needed.

import os
import subprocess
import sys

from catapult_build import module_finder
from catapult_build import temp_deployment_dir


def AppcfgUpdate(paths, app_id, service_name=None):
  """Deploys a new version of an App Engine app from a temporary directory.

  Args:
    paths: List of paths to files and directories that should be linked
        (or copied) in the deployment directory.
    app_id: The application ID to use.
  """
  try:
    import appcfg  # pylint: disable=unused-variable
  except ImportError:
    # TODO(qyearsley): Put the App Engine SDK in the path with the
    # binary dependency manager.
    # See: https://github.com/catapult-project/catapult/issues/2135
    print 'This script requires the App Engine SDK to be in PYTHONPATH.'
    sys.exit(1)
  with temp_deployment_dir.TempDeploymentDir(
      paths, use_symlinks=False) as temp_dir:
    print 'Deploying from "%s".' % temp_dir
    _Run([
        module_finder.FindModule('appcfg'),
        '--application=%s' % app_id,
        '--version=%s' % _VersionName(),
        'update',
        os.path.join(temp_dir, service_name) if service_name else temp_dir,
    ])


def _VersionName():
  is_synced = not _Run(['git', 'diff', 'master']).strip()
  deployment_type = 'clean' if is_synced else 'dev'
  email = _Run(['git', 'config', '--get', 'user.email'])
  username = email[0:email.find('@')]
  commit_hash = _Run(['git', 'rev-parse', '--short=8', 'HEAD']).strip()
  return '%s-%s-%s' % (deployment_type, username, commit_hash)


def _Run(command):
  proc = subprocess.Popen(command, stdout=subprocess.PIPE)
  output, _ = proc.communicate()
  return output<commit_msg>This disables the external diff driver. I have p4merge setup as the default git diff tool, so out deploy script always fails to detect any local changes and is uploaded incorrectly as a "clean" version.<commit_after># Copyright 2015 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.

# TODO(qyearsley): Add a step to vulcanize each template HTML file.
# TODO(qyearsley): Add a step to put static files in a versioned
# directory and modify app.yaml and request_handler as needed.

import os
import subprocess
import sys

from catapult_build import module_finder
from catapult_build import temp_deployment_dir


def AppcfgUpdate(paths, app_id, service_name=None):
  """Deploys a new version of an App Engine app from a temporary directory.

  Args:
    paths: List of paths to files and directories that should be linked
        (or copied) in the deployment directory.
    app_id: The application ID to use.
  """
  try:
    import appcfg  # pylint: disable=unused-variable
  except ImportError:
    # TODO(qyearsley): Put the App Engine SDK in the path with the
    # binary dependency manager.
    # See: https://github.com/catapult-project/catapult/issues/2135
    print 'This script requires the App Engine SDK to be in PYTHONPATH.'
    sys.exit(1)
  with temp_deployment_dir.TempDeploymentDir(
      paths, use_symlinks=False) as temp_dir:
    print 'Deploying from "%s".' % temp_dir
    _Run([
        module_finder.FindModule('appcfg'),
        '--application=%s' % app_id,
        '--version=%s' % _VersionName(),
        'update',
        os.path.join(temp_dir, service_name) if service_name else temp_dir,
    ])


def _VersionName():
  is_synced = not _Run(['git', 'diff', 'master', '--no-ext-diff']).strip()
  deployment_type = 'clean' if is_synced else 'dev'
  email = _Run(['git', 'config', '--get', 'user.email'])
  username = email[0:email.find('@')]
  commit_hash = _Run(['git', 'rev-parse', '--short=8', 'HEAD']).strip()
  return '%s-%s-%s' % (deployment_type, username, commit_hash)


def _Run(command):
  proc = subprocess.Popen(command, stdout=subprocess.PIPE)
  output, _ = proc.communicate()
  return output
{'fraction_non_alphanumeric': 0.10838831291234684, 'fraction_numerical': 0.005419415645617342, 'mean_word_length': 3.834851936218679, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5981807', 'n_tokens_mistral': 1340, 'n_tokens_neox': 1305, 'n_words': 458}