Example #1
0
def report_compare(compare_result, detailed=True):
  compare, base_cmap_data, target_cmap_data = compare_result
  base_map = cmap_data.create_map_from_table(base_cmap_data.table)
  target_map = cmap_data.create_map_from_table(target_cmap_data.table)

  base_title = title_from_metadata(base_cmap_data.meta)
  target_title = title_from_metadata(target_cmap_data.meta)

  print 'base: %s' % base_title
  print 'target: %s' % target_title
  for script in sorted(compare):
    added, removed = compare[script]
    if added or removed:
      name = base_map[script].name
      print '%s # %s' % (script, name)
      if added:
        print '  added (%d): %s' % (
            len(added), lint_config.write_int_ranges(added))
        if detailed:
          for cp in sorted(added):
            print '    %6s %s' % (
                '%04x' % cp, unicode_data.name(cp, ''))
      if removed:
        print '  removed (%d): %s' % (
            len(removed), lint_config.write_int_ranges(removed))
        if detailed:
          for cp in sorted(removed):
            print '    %6s %s' % (
                '%04x' % cp, unicode_data.name(cp, ''))
Example #2
0
def compare_cmap_data(base_cmap_data, target_cmap_data, scripts, cps,
                      except_scripts, except_cps, no_additions, no_removals):
  result = {}
  base_map = cmap_data.create_map_from_table(base_cmap_data.table)
  target_map = cmap_data.create_map_from_table(target_cmap_data.table)

  for script in sorted(base_map):
    if except_scripts and script in except_scripts:
      continue
    if scripts and script not in scripts:
      continue
    if script in target_map:
      name = base_map[script].name
      base_cps = lint_config.parse_int_ranges(base_map[script].ranges)
      target_cps = lint_config.parse_int_ranges(target_map[script].ranges)
      if cps:
        base_cps &= cps
        target_cps &= cps
      if except_cps:
        base_cps -= except_cps
        target_cps -= except_cps
      if base_cps != target_cps:
        added = None if no_additions else target_cps - base_cps
        removed = None if no_removals else base_cps - target_cps
      else:
        added, removed = None, None
      result[script] = (added, removed)
  return result
Example #3
0
def compare_cmap_data(base_cmap_data, target_cmap_data, scripts, cps,
                      except_scripts, except_cps, no_additions, no_removals):
  result = {}
  base_map = cmap_data.create_map_from_table(base_cmap_data.table)
  target_map = cmap_data.create_map_from_table(target_cmap_data.table)

  for script in sorted(base_map):
    if except_scripts and script in except_scripts:
      continue
    if scripts and script not in scripts:
      continue
    if script in target_map:
      name = base_map[script].name
      base_cps = lint_config.parse_int_ranges(base_map[script].ranges)
      target_cps = lint_config.parse_int_ranges(target_map[script].ranges)
      added, removed = compare_cmaps(
          base_cps, target_cps, cps, except_cps, no_additions, no_removals)
      base_xcps, target_xcps = (set(), set())
      if int(getattr(base_map[script], 'xcount', -1)) != -1:
        base_xcps = lint_config.parse_int_ranges(base_map[script].xranges)
      if int(getattr(target_map[script], 'xcount', -1)) != -1:
        target_xcps = lint_config.parse_int_ranges(target_map[script].xranges)
      xadded, xremoved = compare_cmaps(
          base_xcps, target_xcps, cps, except_cps, no_additions, no_removals)
      result[script] = added, removed, xadded, xremoved
  return result
def report_compare(compare_result, detailed=True):
  compare, base_cmap_data, target_cmap_data = compare_result
  base_map = cmap_data.create_map_from_table(base_cmap_data.table)
  target_map = cmap_data.create_map_from_table(target_cmap_data.table)

  inverted_target = collections.defaultdict(set)
  for script, row in target_map.iteritems():
    cps = tool_utils.parse_int_ranges(row.ranges)
    for cp in cps:
      inverted_target[cp].add(script)


  base_title = title_from_metadata(base_cmap_data.meta)
  target_title = title_from_metadata(target_cmap_data.meta)

  print 'base: %s' % base_title
  print 'target: %s' % target_title
  for script in sorted(compare):
    added, removed = compare[script]
    if added or removed:
      name = base_map[script].name
      print '%s # %s' % (script, name)
      if added:
        print '  added (%d): %s' % (
            len(added), lint_config.write_int_ranges(added))
        if detailed:
          _print_detailed(added)
      if removed:
        print '  removed (%d): %s' % (
            len(removed), lint_config.write_int_ranges(removed))
        if detailed:
          _print_detailed(removed, inverted_target)
Example #5
0
def csv_from_cmap_data(data, scripts, exclude_scripts):
  script_to_rowdata = cmap_data.create_map_from_table(data.table)
  cols = []
  max_lines = 0
  num_cells = 0
  for script in sorted(
      script_to_rowdata, key=lambda s: _script_to_name(s).lower()):
    if scripts and script not in scripts:
      continue
    if script in exclude_scripts:
      continue

    col = [
        '"%s"' % _script_to_name(script)
    ]
    rd = script_to_rowdata[script]
    cps = tool_utils.parse_int_ranges(rd.ranges)
    num_cells += len(cps)
    col.extend('U+%04X' % cp for cp in sorted(
        tool_utils.parse_int_ranges(rd.ranges)))
    cols.append(col)
    max_lines = max(max_lines, len(col))

  num_cols = len(cols)
  num_cells += num_cols  # headers are not empty
  all_cells = num_cols * max_lines
  fmt = 'Columns: %d\nRows: %d\nNon-empty cells: %d\nCells: %d'
  print >> sys.stderr, fmt % (num_cols, max_lines, num_cells, all_cells)
  cmap_lines = []
  cmap_lines.append(','.join(col[0] for col in cols))
  for i in range(1, max_lines):
    cmap_lines.append(','.join(col[i] if i < len(col) else '' for col in cols))
  return '\n'.join(cmap_lines)
def compare_cmap_data(
    base_cmap_data, target_cmap_data, scripts, except_scripts, opts=None):
  result = {}
  base_map = cmap_data.create_map_from_table(base_cmap_data.table)
  target_map = cmap_data.create_map_from_table(target_cmap_data.table)

  for script in sorted(base_map):
    if except_scripts and script in except_scripts:
      continue
    if scripts and script not in scripts:
      continue
    if script in target_map:
      base_data = base_map[script]
      target_data = target_map[script]
      result[script] = compare_data(base_data, target_data, opts)
  return result
def compare_interscript_data(base_cmap_data, scripts, opts=None):
  result = {}
  base_map = cmap_data.create_map_from_table(base_cmap_data.table)
  for i in range(len(scripts) - 1):
    base_script = scripts[i]
    for j in range(i + 1, len(scripts)):
      target_script = scripts[j]
      result[base_script, target_script] = compare_interscript(
          base_map, base_script, target_script, opts)
  return result
def report_compare(compare_result, detailed=True):
  compare, base_cmap_data, target_cmap_data = compare_result
  base_map = cmap_data.create_map_from_table(base_cmap_data.table)
  target_map = cmap_data.create_map_from_table(target_cmap_data.table)

  inverted_target = collections.defaultdict(set)
  for script, row in target_map.iteritems():
    cps = tool_utils.parse_int_ranges(row.ranges)
    for cp in cps:
      inverted_target[cp].add(script)

  base_title = title_from_metadata(base_cmap_data.meta)
  target_title = title_from_metadata(target_cmap_data.meta)

  print 'base: %s' % base_title
  print 'target: %s' % target_title
  for script in sorted(compare):
    added, removed, xadded, xremoved = compare[script]
    label = '%s # %s' % (script, base_map[script].name)
    report_cmap_compare(
        label, added, removed, xadded, xremoved, inverted_target, detailed)
def report_interscript_compare(compare_result, detailed=True):
  compare, base_cmap_data = compare_result
  base_map = cmap_data.create_map_from_table(base_cmap_data.table)
  title = title_from_metadata(base_cmap_data.meta)
  print 'data: %s' % title
  for t in sorted(compare):
    added, removed, xadded, xremoved = compare[t]
    base_script, target_script = t
    label = 'base: %s (%s), target: %s (%s)' % (
        base_script, base_map[base_script].name, target_script,
        base_map[target_script].name)
    report_cmap_compare(
        label, added, removed, xadded, xremoved, None, detailed)
Example #10
0
def csv_from_cmap_data(data, scripts, exclude_scripts):
  script_to_rowdata = cmap_data.create_map_from_table(data.table)
  cols = []
  max_lines = 0
  num_cells = 0
  for script in sorted(
      script_to_rowdata, key=lambda s: _script_to_name(s).lower()):
    if scripts and script not in scripts:
      continue
    if exclude_scripts and script in exclude_scripts:
      continue

    rd = script_to_rowdata[script]
    star = int(getattr(rd, 'xcount', -1)) != -1
    col = [
        '"%s%s"' % (_script_to_name(script), '*' if star else '')
    ]
    cps = tool_utils.parse_int_ranges(rd.ranges)
    xranges = getattr(rd, 'xranges', None)
    if xranges != None:
      xcps = frozenset(tool_utils.parse_int_ranges(xranges))
      cps |= xcps
    else:
      xcps = frozenset()
    num_cells += len(cps)
    col.extend(
        '%04X%s' % (cp, '*' if cp in xcps else '')
        for cp in sorted(cps))
    cols.append(col)
    max_lines = max(max_lines, len(col))

  num_cols = len(cols)
  num_cells += num_cols  # headers are not empty
  all_cells = num_cols * max_lines
  fmt = 'Columns: %d\nRows: %d\nNon-empty cells: %d\nCells: %d'
  print >> sys.stderr, fmt % (num_cols, max_lines, num_cells, all_cells)
  cmap_lines = []
  cmap_lines.append(','.join(col[0] for col in cols))
  for i in range(1, max_lines):
    cmap_lines.append(','.join(col[i] if i < len(col) else '' for col in cols))
  return '\n'.join(cmap_lines)
Example #11
0
def csv_from_cmap_data(data, scripts, exclude_scripts):
    script_to_rowdata = cmap_data.create_map_from_table(data.table)
    cols = []
    max_lines = 0
    num_cells = 0
    for script in sorted(script_to_rowdata,
                         key=lambda s: _script_to_name(s).lower()):
        if scripts and script not in scripts:
            continue
        if exclude_scripts and script in exclude_scripts:
            continue

        rd = script_to_rowdata[script]
        star = int(getattr(rd, 'xcount', -1)) != -1
        col = ['"%s%s"' % (_script_to_name(script), '*' if star else '')]
        cps = tool_utils.parse_int_ranges(rd.ranges)
        xranges = getattr(rd, 'xranges', None)
        if xranges != None:
            xcps = frozenset(tool_utils.parse_int_ranges(xranges))
            cps |= xcps
        else:
            xcps = frozenset()
        num_cells += len(cps)
        col.extend('U+%04X%s' % (cp, '*' if cp in xcps else '')
                   for cp in sorted(cps))
        cols.append(col)
        max_lines = max(max_lines, len(col))

    num_cols = len(cols)
    num_cells += num_cols  # headers are not empty
    all_cells = num_cols * max_lines
    fmt = 'Columns: %d\nRows: %d\nNon-empty cells: %d\nCells: %d'
    print >> sys.stderr, fmt % (num_cols, max_lines, num_cells, all_cells)
    cmap_lines = []
    cmap_lines.append(','.join(col[0] for col in cols))
    for i in range(1, max_lines):
        cmap_lines.append(','.join(col[i] if i < len(col) else ''
                                   for col in cols))
    return '\n'.join(cmap_lines)