<commit_before>#!/usr/bin/python
# Copyright (c) 2011 The Native Client Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""Download all Native Client toolchains for this platform.

This module downloads multiple tgz's and expands them.
"""

import optparse
import os.path

import download_utils
import toolchainbinaries
import sync_tgz
import sys


def ShowUpdatedDEPS(base_url, version, nacl_newlib_only):
  """Print a suggested DEPS toolchain hash update for all platforms.

  Arguments:
    base_url: base download url for the toolchains.
    version: revision of the toolchain to use.
    nacl_newlib_only: flag indicating to only consider non-pnacl newlib flavors.
  """
  flavors = set()
  for platform in toolchainbinaries.PLATFORM_MAPPING:
    pm = toolchainbinaries.PLATFORM_MAPPING[platform]
    for arch in pm:
      for flavor in pm[arch]:
        if nacl_newlib_only and toolchainbinaries.IsNaClNewlibFlavor(flavor):
          continue
        flavors.add(flavor)
  for flavor in flavors:
    url = toolchainbinaries.EncodeToolchainUrl(base_url, version, flavor)
    print '  "nacl_toolchain_%s_hash":' % flavor
    print '      "%s"' % sync_tgz.HashUrl(url)
    sys.stdout.flush()


def SyncFlavor(flavor, url, dst, hash):
  """Sync a flavor of the nacl toolchain

  Arguments:
    flavor: short directory name of the toolchain flavor.
    url: url to download the toolchain flavor from.
    dst: destination directory for the toolchain.
    hash: expected hash of the toolchain.
  """
  parent_dir = os.path.dirname(os.path.dirname(__file__))
  # TODO(bradnelson_): get rid of this when toolchain tarballs flattened.
  if 'arm' in flavor or 'pnacl' in flavor:
    # TODO(cbiffle): we really shouldn't do this until the unpack succeeds!
    # See: http://code.google.com/p/nativeclient/issues/detail?id=834
    download_utils.RemoveDir(dst)
    sync_tgz.SyncTgz(url, dst, verbose=False, hash=hash)
  elif 'newlib' in flavor:
    dst_tmp = os.path.join(parent_dir, 'toolchain', '.tmp')
    sync_tgz.SyncTgz(url, dst_tmp, verbose=False, hash=hash)
    subdir = os.path.join(dst_tmp, 'sdk', 'nacl-sdk')
    download_utils.MoveDirCleanly(subdir, dst)
    download_utils.RemoveDir(dst_tmp)
  else:
    dst_tmp = os.path.join(parent_dir, 'toolchain', '.tmp')
    sync_tgz.SyncTgz(url, dst_tmp, maindir='toolchain', verbose=False,<commit_msg>Fixing logic and formatting in message printed when hashes need to be updated.<commit_after>#!/usr/bin/python
# Copyright (c) 2011 The Native Client Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""Download all Native Client toolchains for this platform.

This module downloads multiple tgz's and expands them.
"""

import optparse
import os.path

import download_utils
import toolchainbinaries
import sync_tgz
import sys


def ShowUpdatedDEPS(base_url, version, nacl_newlib_only):
  """Print a suggested DEPS toolchain hash update for all platforms.

  Arguments:
    base_url: base download url for the toolchains.
    version: revision of the toolchain to use.
    nacl_newlib_only: flag indicating to only consider non-pnacl newlib flavors.
  """
  flavors = set()
  for platform in toolchainbinaries.PLATFORM_MAPPING:
    pm = toolchainbinaries.PLATFORM_MAPPING[platform]
    for arch in pm:
      for flavor in pm[arch]:
        if (nacl_newlib_only and
            not toolchainbinaries.IsNaClNewlibFlavor(flavor)):
          continue
        flavors.add(flavor)
  for flavor in flavors:
    url = toolchainbinaries.EncodeToolchainUrl(base_url, version, flavor)
    print '  "nacl_toolchain_%s_hash":' % flavor
    print '      "%s",' % sync_tgz.HashUrl(url)
    sys.stdout.flush()


def SyncFlavor(flavor, url, dst, hash):
  """Sync a flavor of the nacl toolchain

  Arguments:
    flavor: short directory name of the toolchain flavor.
    url: url to download the toolchain flavor from.
    dst: destination directory for the toolchain.
    hash: expected hash of the toolchain.
  """
  parent_dir = os.path.dirname(os.path.dirname(__file__))
  # TODO(bradnelson_): get rid of this when toolchain tarballs flattened.
  if 'arm' in flavor or 'pnacl' in flavor:
    # TODO(cbiffle): we really shouldn't do this until the unpack succeeds!
    # See: http://code.google.com/p/nativeclient/issues/detail?id=834
    download_utils.RemoveDir(dst)
    sync_tgz.SyncTgz(url, dst, verbose=False, hash=hash)
  elif 'newlib' in flavor:
    dst_tmp = os.path.join(parent_dir, 'toolchain', '.tmp')
    sync_tgz.SyncTgz(url, dst_tmp, verbose=False, hash=hash)
    subdir = os.path.join(dst_tmp, 'sdk', 'nacl-sdk')
    download_utils.MoveDirCleanly(subdir, dst)
    download_utils.RemoveDir(dst_tmp)
  else:
    dst_tmp = os.path.join(parent_dir, 'toolchain', '.tmp')
    sync_tgz.SyncTgz(url, dst_tmp, maindir='toolchain', verbose=False,
{'fraction_non_alphanumeric': 0.09329563812600969, 'fraction_numerical': 0.002827140549273021, 'mean_word_length': 3.9778894472361808, 'pattern_counts': {'":': 2, '<': 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': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2984834', 'n_tokens_mistral': 1626, 'n_tokens_neox': 1561, 'n_words': 488}