components/vector_icons/aggregate_vector_icons.py
def AggregateVectorIcons(working_directory, file_list, output_cc, output_h):
  """Compiles all .icon files in a directory into two C++ files.

  Args:
      working_directory: The path to the directory that holds the .icon files
          and C++ templates.
      file_list: A file containing the list of vector icon files to process.
      output_cc: The path that should be used to write the .cc file.
      output_h: The path that should be used to write the .h file.
  """

  # For each file in |file_list|, place it in |path_map| if its extension is
  # .icon. This will map the icon's name to its path, e.g.,
  # path_map['cat'] = 'foo/bar/cat.icon'.
  icon_list = []
  with open(file_list, "r") as f:
    file_list_contents = f.read()
  icon_list = shlex.split(file_list_contents)

  path_map = {}

  for icon_path in icon_list:
    (icon_name, extension) = os.path.splitext(os.path.basename(icon_path))

    if extension != ".icon":
      Error("Only filenames " + icon_name + ".icon are allowed.")

    if icon_name not in path_map:
      path_map[icon_name] = icon_path
    else:
      Error("A vector icon with name '" + icon_name + "' already exists.")

  # Generate the file vector_icons.h which declares a variable for each
  # icon in |path_map|. The variable name is derived from the icon name by
  # converting to camel case, prepending 'k', and appending 'Icon'. For
  # example, the icon 'foo_bar' will have the variable name kFooBarIcon.
  with open(os.path.join(working_directory, "vector_icons.h.template"),
            "r") as input_header_template:
    header_template_contents = input_header_template.readlines()

  output_header = open(output_h, "w")
  for line in header_template_contents:
    if not TEMPLATE_PLACEHOLDER in line:
      output_header.write(line)
      continue

    for icon in path_map:
      (icon_name, extension) = os.path.splitext(
                               os.path.basename(path_map[icon]))
      output_header.write("VECTOR_ICON_TEMPLATE_H({})\n".format(
          GetIconName(icon_name)))
  output_header.close()

  # Copy the vector icon drawing commands from the .icon files, splitting them
  # into their individual icon representations, and use them to generate
  # vector_icons.cc, which defines the variables declared in vector_icons.h.
  input_cc_template = open(
      os.path.join(working_directory, "vector_icons.cc.template"))
  cc_template_contents = input_cc_template.readlines()
  input_cc_template.close()

  output_cc = open(output_cc, "w")
  for line in cc_template_contents:
    if not TEMPLATE_PLACEHOLDER in line:
      output_cc.write(line)
      continue
    for icon in path_map:
      (icon_name, extension) = os.path.splitext(
                               os.path.basename(path_map[icon]))

      icon_representations = ExtractIconReps(path_map[icon])
      icon_representation_strings = []
      for i, size in enumerate(sorted(icon_representations, reverse=True)):
        vector_commands = icon_representations[size]
        icon_path_name = GetPathName(icon_name, size if i != 0 else None)
        # Store the vector-drawing commands for foo_bar.icon in the temporary
        # variable kFooBarPath.
        output_cc.write("VECTOR_ICON_REP_TEMPLATE({}, {})\n".format(
            icon_path_name, vector_commands))
        icon_representation_strings.append(
            "{{{0}, base::size({0})}}".format(icon_path_name))

      # Another temporary variable kFooBarRepList is used to create all the
      # VectorIconReps inline, with a pointer to it in the final VectorIcon.
      output_cc.write("VECTOR_ICON_TEMPLATE_CC({}, {}, {})\n".format(
          GetRepListName(icon_name), GetIconName(icon_name),
          ", ".join(icon_representation_strings)))

  output_cc.close()
Compiles all .icon files in a directory into two C++ files.

  Args:
      working_directory: The path to the directory that holds the .icon files
          and C++ templates.
      file_list: A file containing the list of vector icon files to process.
      output_cc: The path that should be used to write the .cc file.
      output_h: The path that should be used to write the .h file.
  
Compiles all .icon files in a directory into two C++ files.
Compiles all . icon files in a directory into two C ++ files .
def AggregateVectorIcons(working_directory, file_list, output_cc, output_h):
  icon_list = []
  with open(file_list, "r") as f:
    file_list_contents = f.read()
  icon_list = shlex.split(file_list_contents)
  path_map = {}
  for icon_path in icon_list:
    (icon_name, extension) = os.path.splitext(os.path.basename(icon_path))
    if extension != ".icon":
      Error("Only filenames " + icon_name + ".icon are allowed.")
    if icon_name not in path_map:
      path_map[icon_name] = icon_path
    else:
      Error("A vector icon with name '" + icon_name + "' already exists.")
  with open(os.path.join(working_directory, "vector_icons.h.template"),
            "r") as input_header_template:
    header_template_contents = input_header_template.readlines()
  output_header = open(output_h, "w")
  for line in header_template_contents:
    if not TEMPLATE_PLACEHOLDER in line:
      output_header.write(line)
      continue
    for icon in path_map:
      (icon_name, extension) = os.path.splitext(
                               os.path.basename(path_map[icon]))
      output_header.write("VECTOR_ICON_TEMPLATE_H({})\n".format(
          GetIconName(icon_name)))
  output_header.close()
  input_cc_template = open(
      os.path.join(working_directory, "vector_icons.cc.template"))
  cc_template_contents = input_cc_template.readlines()
  input_cc_template.close()
  output_cc = open(output_cc, "w")
  for line in cc_template_contents:
    if not TEMPLATE_PLACEHOLDER in line:
      output_cc.write(line)
      continue
    for icon in path_map:
      (icon_name, extension) = os.path.splitext(
                               os.path.basename(path_map[icon]))
      icon_representations = ExtractIconReps(path_map[icon])
      icon_representation_strings = []
      for i, size in enumerate(sorted(icon_representations, reverse=True)):
        vector_commands = icon_representations[size]
        icon_path_name = GetPathName(icon_name, size if i != 0 else None)
        output_cc.write("VECTOR_ICON_REP_TEMPLATE({}, {})\n".format(
            icon_path_name, vector_commands))
        icon_representation_strings.append(
            "{{{0}, base::size({0})}}".format(icon_path_name))
      output_cc.write("VECTOR_ICON_TEMPLATE_CC({}, {}, {})\n".format(
          GetRepListName(icon_name), GetIconName(icon_name),
          ", ".join(icon_representation_strings)))
  output_cc.close()
def AggregateVectorIcons ( working_directory , file_list , output_cc , output_h ) : icon_list = [ ] with open ( file_list , "r" ) as f : file_list_contents = f . read ( ) icon_list = shlex . split ( file_list_contents ) path_map = { } for icon_path in icon_list : ( icon_name , extension ) = os . path . splitext ( os . path . basename ( icon_path ) ) if extension != ".icon" : Error ( "Only filenames " + icon_name + ".icon are allowed." ) if icon_name not in path_map : path_map [ icon_name ] = icon_path else : Error ( "A vector icon with name '" + icon_name + "' already exists." ) with open ( os . path . join ( working_directory , "vector_icons.h.template" ) , "r" ) as input_header_template : header_template_contents = input_header_template . readlines ( ) output_header = open ( output_h , "w" ) for line in header_template_contents : if not TEMPLATE_PLACEHOLDER in line : output_header . write ( line ) continue for icon in path_map : ( icon_name , extension ) = os . path . splitext ( os . path . basename ( path_map [ icon ] ) ) output_header . write ( "VECTOR_ICON_TEMPLATE_H({})\n" . format ( GetIconName ( icon_name ) ) ) output_header . close ( ) input_cc_template = open ( os . path . join ( working_directory , "vector_icons.cc.template" ) ) cc_template_contents = input_cc_template . readlines ( ) input_cc_template . close ( ) output_cc = open ( output_cc , "w" ) for line in cc_template_contents : if not TEMPLATE_PLACEHOLDER in line : output_cc . write ( line ) continue for icon in path_map : ( icon_name , extension ) = os . path . splitext ( os . path . basename ( path_map [ icon ] ) ) icon_representations = ExtractIconReps ( path_map [ icon ] ) icon_representation_strings = [ ] for i , size in enumerate ( sorted ( icon_representations , reverse = True ) ) : vector_commands = icon_representations [ size ] icon_path_name = GetPathName ( icon_name , size if i != 0 else None ) output_cc . write ( "VECTOR_ICON_REP_TEMPLATE({}, {})\n" . format ( icon_path_name , vector_commands ) ) icon_representation_strings . append ( "{{{0}, base::size({0})}}" . format ( icon_path_name ) ) output_cc . write ( "VECTOR_ICON_TEMPLATE_CC({}, {}, {})\n" . format ( GetRepListName ( icon_name ) , GetIconName ( icon_name ) , ", " . join ( icon_representation_strings ) ) ) output_cc . close ( )
Compiles all .icon files in a directory into two C++ files.
Compiles all . icon files in a directory into two C ++ files .
"""Compiles all .icon files in a directory into two C++ files.

  Args:
      working_directory: The path to the directory that holds the .icon files
          and C++ templates.
      file_list: A file containing the list of vector icon files to process.
      output_cc: The path that should be used to write the .cc file.
      output_h: The path that should be used to write the .h file.
  """ # For each file in |file_list|, place it in |path_map| if its extension is # .icon. This will map the icon's name to its path, e.g., # path_map['cat'] = 'foo/bar/cat.icon'. # Generate the file vector_icons.h which declares a variable for each # icon in |path_map|. The variable name is derived from the icon name by # converting to camel case, prepending 'k', and appending 'Icon'. For # example, the icon 'foo_bar' will have the variable name kFooBarIcon. # Copy the vector icon drawing commands from the .icon files, splitting them # into their individual icon representations, and use them to generate # vector_icons.cc, which defines the variables declared in vector_icons.h. # Store the vector-drawing commands for foo_bar.icon in the temporary # variable kFooBarPath. # Another temporary variable kFooBarRepList is used to create all the # VectorIconReps inline, with a pointer to it in the final VectorIcon.
working_directory
The path to the directory that holds the .icon files
and C++ templates.
The path to the directory that holds the . icon files and C ++ templates .
file_list
A file containing the list of vector icon files to process.
A file containing the list of vector icon files to process .
output_cc
The path that should be used to write the .cc file.
The path that should be used to write the . cc file .
output_h
The path that should be used to write the .h file.
The path that should be used to write the . h file .