Exemple #1
0
def find_screenshots(repo_root, translation_expectations):
  grd_files = translation_helper.get_translatable_grds(
      repo_root, list_grds_in_repository(repo_root), translation_expectations)

  screenshots = []
  for grd_file in grd_files:
    grd_path = grd_file.path
    # Convert grd_path.grd to grd_path_grd/ directory.
    name, ext = os.path.splitext(os.path.basename(grd_path))
    relative_screenshots_dir = os.path.relpath(
        os.path.dirname(grd_path), repo_root)
    screenshots_dir = os.path.realpath(
        os.path.join(repo_root,
                     os.path.join(relative_screenshots_dir,
                                  name + ext.replace('.', '_'))))
    # Grab all the .png files under the screenshot directory. On a clean
    # checkout this should be an empty list, as the repo should only contain
    # .sha1 files of previously uploaded screenshots.
    if not os.path.exists(screenshots_dir):
      continue
    for f in os.listdir(screenshots_dir):
      if f.endswith('.sha1'):
        continue
      if not f.endswith('.png'):
        print 'File with unexpected extension: %s in %s' % (f, screenshots_dir)
        continue
      screenshots.append(os.path.join(screenshots_dir, f))
  return screenshots
Exemple #2
0
def Run():
  grds = list_files_in_repository(repo_root, '*.grd')
  grdps = list_files_in_repository(repo_root, '*.grdp')

  print('Found %d grds, %d grdps in the repo.' % (len(grds), len(grdps)))
  # Make sure we can parse all .grd files in the source tree. Grd files are
  # parsed via the file path.
  for grd in grds:
    # This file is intentionally missing an include, skip it.
    if grd == os.path.join('tools', 'translation', 'testdata', 'internal.grd'):
      continue
    path = os.path.join(repo_root, grd)
    grd_helper.GetGrdMessages(path, os.path.dirname(path))

  # Make sure we can parse all .grdp files in the source tree.
  # Grdp files are parsed using file contents instead of path.
  for grdp in grdps:
    path = os.path.join(repo_root, grdp)
    # Parse grdp files using file contents.
    contents = read_file_as_text(path)
    grd_helper.GetGrdpMessagesFromString(contents)

  print('Successfully parsed all .grd and .grdp files in the repo.')

  # Additional check for translateable grds. Translateable grds are a subset
  # of all grds so this checks some files twice, but it exercises the
  # get_translatable_grds() path and also doesn't need to skip internal.grd.
  TRANSLATION_EXPECTATIONS_PATH = os.path.join(repo_root, 'tools',
                                               'gritsettings',
                                               'translation_expectations.pyl')
  translateable_grds = translation_helper.get_translatable_grds(
      repo_root, grds, TRANSLATION_EXPECTATIONS_PATH)
  print('Found %d translateable .grd files in translation expectations.' %
        len(translateable_grds))
  for grd in translateable_grds:
    path = os.path.join(repo_root, grd.path)
    grd_helper.GetGrdMessages(path, os.path.dirname(path))
  print('Successfully parsed all translateable_grds .grd files in translation '
        'expectations.')
  print('DONE')
Exemple #3
0
def find_screenshots(repo_root, translation_expectations):
    """Returns a list of translation related .png files in the repository."""
    translatable_grds = translation_helper.get_translatable_grds(
        repo_root, git_helper.list_grds_in_repository(repo_root),
        translation_expectations)

    # Add the paths of grds and any files they include. This includes grdp files
    # and files included via <structure> elements.
    src_paths = []
    for grd in translatable_grds:
        src_paths.append(grd.path)
        src_paths.extend(grd.grdp_paths)
        src_paths.extend(grd.structure_paths)

    screenshots = []
    for grd_path in src_paths:
        # Convert grd_path.grd to grd_path_grd/ directory.
        name, ext = os.path.splitext(os.path.basename(grd_path))
        relative_screenshots_dir = os.path.relpath(os.path.dirname(grd_path),
                                                   repo_root)
        screenshots_dir = os.path.realpath(
            os.path.join(
                repo_root,
                os.path.join(relative_screenshots_dir,
                             name + ext.replace('.', '_'))))
        # Grab all the .png files under the screenshot directory. On a clean
        # checkout this should be an empty list, as the repo should only contain
        # .sha1 files of previously uploaded screenshots.
        if not os.path.exists(screenshots_dir):
            continue
        for f in os.listdir(screenshots_dir):
            if f in ('OWNERS', 'README.md',
                     'DIR_METADATA') or f.endswith('.sha1'):
                continue
            if not f.endswith('.png'):
                print('File with unexpected extension: %s in %s' %
                      (f, screenshots_dir))
                continue
            screenshots.append(os.path.join(screenshots_dir, f))
    return screenshots