<commit_before>#!/usr/bin/python
#
# Copyright 2015 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Swat copyright, bump version."""


import argparse
import collections
import os
from os import path
import re

from nototools import autofix_for_release
from nototools import cldr_data
from nototools import font_data
from nototools import noto_fonts
from nototools import ttc_utils

from fontTools import ttLib
from fontTools import misc

_COPYRIGHT_ID = 0
_VERSION_ID = 5
_TRADEMARK_ID = 7
_MANUFACTURER_ID = 8
_DESIGNER_ID = 9
_DESCRIPTION_ID = 10
_VENDOR_URL_ID = 11
_DESIGNER_URL_ID = 12
_LICENSE_ID = 13
_LICENSE_URL_ID = 14

_NAME_ID_LABELS = {
    _COPYRIGHT_ID: 'copyright',
    _VERSION_ID: 'version',
    _TRADEMARK_ID: 'trademark',
    _MANUFACTURER_ID: 'manufacturer',
    _DESIGNER_ID: 'designer',
    _DESCRIPTION_ID: 'description',
    _VENDOR_URL_ID: 'vendor url',
    _DESIGNER_URL_ID: 'designer url',
    _LICENSE_ID: 'license',
    _LICENSE_URL_ID: 'license url',
}

_SIL_LICENSE = (
    'This Font Software is licensed under the SIL Open Font License, '
    'Version 1.1. This Font Software is distributed on an "AS IS" '
    'BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express '
    'or implied. See the SIL Open Font License for the specific language, '
    'permissions and limitations governing your use of this Font Software.')

_SIL_LICENSE_URL = "http://scripts.sil.org/OFL"

_NOTO_URL = "http://www.google.com/get/noto/"

_SCRIPT_KEYS = {
    'Aran': 'Urdu',
    'HST': 'Historic',
    'LGC': ''
}

_FAMILY_KEYS = {
  'Arimo': 'a',
  'Cousine':'b',
  'Tinos': 'c',
  'Noto': 'd',
}

_HINTED_TABLES_TO_DROP = autofix_for_release.TABLES_TO_DROP
_UNHINTED_TABLES_TO_DROP = (autofix_for_release.TABLES_TO_DROP +
                            ['fpgm', 'prep', 'cvt'])

_changes = {}

_autofix = collections.defaultdict(list)

_ttc_fonts = {}

def _swat_fonts(dst_root, dry_run):
  def family_key(family):
      return _FAMILY_KEYS.get(family, 'x' + family)
  def script_key(script):
      return (_SCRIPT_KEYS.get(script, None) or
              cldr_data.get_english_script_name(script))
  def compare_key(font):
    return (family_key(font.family),
            font.style,
            script_key(font.script),
            'a' if font.is_hinted else '',
            font.variant if font.variant else '',
            'UI' if font.is_UI else '',
            '' if font.weight == 'Regular' else font.weight,
            font.slope or '',
            font.fmt)
  fonts = noto_fonts.get_noto_fonts()
  for font in sorted(fonts, key=compare_key):
    _swat_font(font, dst_root, dry_run)

  if _ttc_fonts:
    _construct_ttc_fonts(fonts, dst_root, dry_run)


def _noto_relative_path(filepath):
  """Return relative path from some noto root, or None"""
  x = filepath.find('noto-fonts')
  if x == -1:
    x = filepath.find('noto-cjk')
    if x == -1:
      x = filepath.find('noto-emoji')
  if x == -1:
    return None
  return filepath[x:]


def get_bumped_version(ttfont, is_hinted):
  """Return bumped values for the header and name tables."""

  names = font_data.get_name_records(ttfont)
  version = names[_VERSION_ID]
  m = re.match(r'Version (\d{1,5})\.(\d{1,5})(.*)', version)
  if not m:
    print '! Could not match version string (%s)' % version
    return False, None, None

  major_version = m.group(1)
  minor_version = m.group(2)
  version_remainder = m.group(3)
  accuracy = len(minor_version)
  print_revision = font_data.printable_font_revision(ttfont, accuracy)
  # sanity check
  expected_revision = major_version + '.' + minor_version
  if expected_revision != print_revision:
    raise ValueError('! Expected revision \'%s\' but got revision \'%s\'' % (
        expected_revision, print_revision))

  # bump the minor version keeping significant digits:
  new_minor_version = str(int(minor_version) + 1).zfill(accuracy)
  new_revision = major_version + '.' + new_minor_version<commit_msg>fix for review<commit_after>#!/usr/bin/python
#
# Copyright 2015 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Swat copyright, bump version."""


import argparse
import collections
import os
from os import path
import re

from nototools import autofix_for_release
from nototools import cldr_data
from nototools import font_data
from nototools import noto_fonts
from nototools import ttc_utils

from fontTools import ttLib
from fontTools import misc

_COPYRIGHT_ID = 0
_VERSION_ID = 5
_TRADEMARK_ID = 7
_MANUFACTURER_ID = 8
_DESIGNER_ID = 9
_DESCRIPTION_ID = 10
_VENDOR_URL_ID = 11
_DESIGNER_URL_ID = 12
_LICENSE_ID = 13
_LICENSE_URL_ID = 14

_NAME_ID_LABELS = {
    _COPYRIGHT_ID: 'copyright',
    _VERSION_ID: 'version',
    _TRADEMARK_ID: 'trademark',
    _MANUFACTURER_ID: 'manufacturer',
    _DESIGNER_ID: 'designer',
    _DESCRIPTION_ID: 'description',
    _VENDOR_URL_ID: 'vendor url',
    _DESIGNER_URL_ID: 'designer url',
    _LICENSE_ID: 'license',
    _LICENSE_URL_ID: 'license url',
}

_SIL_LICENSE = (
    'This Font Software is licensed under the SIL Open Font License, '
    'Version 1.1. This Font Software is distributed on an "AS IS" '
    'BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express '
    'or implied. See the SIL Open Font License for the specific language, '
    'permissions and limitations governing your use of this Font Software.')

_SIL_LICENSE_URL = "http://scripts.sil.org/OFL"

_NOTO_URL = "http://www.google.com/get/noto/"

_SCRIPT_KEYS = {
    'Aran': 'Urdu',
    'HST': 'Historic',
    'LGC': ''
}

_FAMILY_KEYS = {
  'Arimo': 'a',
  'Cousine':'b',
  'Tinos': 'c',
  'Noto': 'd',
}

_HINTED_TABLES_TO_DROP = autofix_for_release.TABLES_TO_DROP
_UNHINTED_TABLES_TO_DROP = (autofix_for_release.TABLES_TO_DROP +
                            ['fpgm', 'prep', 'cvt'])

_changes = {}

_autofix = collections.defaultdict(list)

_ttc_fonts = {}

def _swat_fonts(dst_root, dry_run):
  def family_key(family):
      return _FAMILY_KEYS.get(family, 'x' + family)
  def script_key(script):
      return (_SCRIPT_KEYS.get(script, None) or
              cldr_data.get_english_script_name(script))
  def compare_key(font):
    return (family_key(font.family),
            font.style,
            script_key(font.script),
            'a' if font.is_hinted else '',
            font.variant if font.variant else '',
            'UI' if font.is_UI else '',
            '' if font.weight == 'Regular' else font.weight,
            font.slope or '',
            font.fmt)
  fonts = noto_fonts.get_noto_fonts()
  for font in sorted(fonts, key=compare_key):
    _swat_font(font, dst_root, dry_run)

  if _ttc_fonts:
    _construct_ttc_fonts(fonts, dst_root, dry_run)


def _noto_relative_path(filepath):
  """Return relative path from some noto root, or None"""
  x = filepath.find('noto-fonts')
  if x == -1:
    x = filepath.find('noto-cjk')
    if x == -1:
      x = filepath.find('noto-emoji')
  if x == -1:
    return None
  return filepath[x:]


def get_bumped_version(ttfont, is_hinted):
  """Return bumped values for the header and name tables."""

  names = font_data.get_name_records(ttfont)
  version = names[_VERSION_ID]
  m = re.match(r'Version (\d{1,5})\.(\d{1,5})(.*)', version)
  if not m:
    print '! Could not match version string (%s)' % version
    return None, None

  major_version = m.group(1)
  minor_version = m.group(2)
  version_remainder = m.group(3)
  accuracy = len(minor_version)
  print_revision = font_data.printable_font_revision(ttfont, accuracy)
  # sanity check
  expected_revision = major_version + '.' + minor_version
  if expected_revision != print_revision:
    raise ValueError('! Expected revision \'%s\' but got revision \'%s\'' % (
        expected_revision, print_revision))

  # bump the minor version keeping significant digits:
  new_minor_version = str(int(minor_version) + 1).zfill(accuracy)
  new_revision = major_version + '.' + new_minor_version
{'fraction_non_alphanumeric': 0.10744633273703041, 'fraction_numerical': 0.008050089445438283, 'mean_word_length': 3.683246073298429, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '5184795', 'n_tokens_mistral': 3173, 'n_tokens_neox': 3062, 'n_words': 846}