third_party/google_input_tools/builder.py
def export(target_file, source_filename, providers, requirements, processed):
  """Writes the contents of a file.

  Description:
    Appends the contents of the source file to the target file. In order to
    preserve proper dependencies, each file has its required namespaces
    processed before exporting the source file itself. The set of exported files
    is tracked to guard against multiple exports of the same file. Comments as
    well as 'provide' and 'require' statements are removed during to export to
    reduce file size.

  Args:
    target_file: Handle to target file for export.
    source_filename: Name of the file to export.
    providers: Map of namespace to filename.
    requirements: Map of filename to required namespaces.
    processed: Set of processed files.
  Returns:
  """

  # Filename may have already been processed if it was a requirement of a
  # previous exported file.
  if source_filename in processed:
    return

  # Export requirements before file.
  if source_filename in requirements:
    for namespace in requirements[source_filename]:
      if namespace in providers:
        dependency = providers[namespace]
        if dependency:
          export(target_file, dependency, providers, requirements, processed)

  processed.add(source_filename)

  # Export file
  for name in providers:
    if providers[name] == source_filename:
      target_file.write('// %s%s' % (name, os.linesep))
  source_file = open(source_filename, 'r')
  try:
    comment_block = False
    for line in source_file:
      # Skip require statements.
      if not re.match(require_regex, line):
        formatted = line.rstrip()
        if comment_block:
          # Scan for trailing */ in multi-line comment.
          index = formatted.find('*/')
          if index >= 0:
            formatted = formatted[index + 2:]
            comment_block = False
          else:
            formatted = ''
        # Remove full-line // style comments.
        if formatted.lstrip().startswith('//'):
          formatted = ''
        # Remove /* */ style comments.
        start_comment = formatted.find('/*')
        end_comment = formatted.find('*/')
        while start_comment >= 0:
          if end_comment > start_comment:
            formatted = (formatted[:start_comment]
                         + formatted[end_comment + 2:])
            start_comment = formatted.find('/*')
            end_comment = formatted.find('*/')
          else:
            formatted = formatted[:start_comment]
            comment_block = True
            start_comment = -1
        if formatted.strip():
          target_file.write('%s%s' % (formatted, os.linesep))
  finally:
    source_file.close()
  target_file.write('\n')
Writes the contents of a file.

  Description:
    Appends the contents of the source file to the target file. In order to
    preserve proper dependencies, each file has its required namespaces
    processed before exporting the source file itself. The set of exported files
    is tracked to guard against multiple exports of the same file. Comments as
    well as 'provide' and 'require' statements are removed during to export to
    reduce file size.

  Args:
    target_file: Handle to target file for export.
    source_filename: Name of the file to export.
    providers: Map of namespace to filename.
    requirements: Map of filename to required namespaces.
    processed: Set of processed files.
  Returns:
  
Writes the contents of a file.
Description:
Appends the contents of the source file to the target file. In order to
preserve proper dependencies, each file has its required namespaces
processed before exporting the source file itself. The set of exported files
is tracked to guard against multiple exports of the same file. Comments as
well as 'provide' and 'require' statements are removed during to export to
reduce file size.
Writes the contents of a file . Description : Appends the contents of the source file to the target file . In order to preserve proper dependencies each file has its required namespaces processed before exporting the source file itself . The set of exported files is tracked to guard against multiple exports of the same file . Comments as well as ' provide ' and ' require ' statements are removed during to export to reduce file size .
def export(target_file, source_filename, providers, requirements, processed):
  if source_filename in processed:
    return
  if source_filename in requirements:
    for namespace in requirements[source_filename]:
      if namespace in providers:
        dependency = providers[namespace]
        if dependency:
          export(target_file, dependency, providers, requirements, processed)
  processed.add(source_filename)
  for name in providers:
    if providers[name] == source_filename:
      target_file.write('// %s%s' % (name, os.linesep))
  source_file = open(source_filename, 'r')
  try:
    comment_block = False
    for line in source_file:
      if not re.match(require_regex, line):
        formatted = line.rstrip()
        if comment_block:
          index = formatted.find('*/')
          if index >= 0:
            formatted = formatted[index + 2:]
            comment_block = False
          else:
            formatted = ''
        if formatted.lstrip().startswith('//'):
          formatted = ''
        start_comment = formatted.find('/*')
        end_comment = formatted.find('*/')
        while start_comment >= 0:
          if end_comment > start_comment:
            formatted = (formatted[:start_comment]
                         + formatted[end_comment + 2:])
            start_comment = formatted.find('/*')
            end_comment = formatted.find('*/')
          else:
            formatted = formatted[:start_comment]
            comment_block = True
            start_comment = -1
        if formatted.strip():
          target_file.write('%s%s' % (formatted, os.linesep))
  finally:
    source_file.close()
  target_file.write('\n')
def export ( target_file , source_filename , providers , requirements , processed ) : if source_filename in processed : return if source_filename in requirements : for namespace in requirements [ source_filename ] : if namespace in providers : dependency = providers [ namespace ] if dependency : export ( target_file , dependency , providers , requirements , processed ) processed . add ( source_filename ) for name in providers : if providers [ name ] == source_filename : target_file . write ( '// %s%s' % ( name , os . linesep ) ) source_file = open ( source_filename , 'r' ) try : comment_block = False for line in source_file : if not re . match ( require_regex , line ) : formatted = line . rstrip ( ) if comment_block : index = formatted . find ( '*/' ) if index >= 0 : formatted = formatted [ index + 2 : ] comment_block = False else : formatted = '' if formatted . lstrip ( ) . startswith ( '//' ) : formatted = '' start_comment = formatted . find ( '/*' ) end_comment = formatted . find ( '*/' ) while start_comment >= 0 : if end_comment > start_comment : formatted = ( formatted [ : start_comment ] + formatted [ end_comment + 2 : ] ) start_comment = formatted . find ( '/*' ) end_comment = formatted . find ( '*/' ) else : formatted = formatted [ : start_comment ] comment_block = True start_comment = - 1 if formatted . strip ( ) : target_file . write ( '%s%s' % ( formatted , os . linesep ) ) finally : source_file . close ( ) target_file . write ( '\n' )
Writes the contents of a file.
Writes the contents of a file .
"""Writes the contents of a file.

  Description:
    Appends the contents of the source file to the target file. In order to
    preserve proper dependencies, each file has its required namespaces
    processed before exporting the source file itself. The set of exported files
    is tracked to guard against multiple exports of the same file. Comments as
    well as 'provide' and 'require' statements are removed during to export to
    reduce file size.

  Args:
    target_file: Handle to target file for export.
    source_filename: Name of the file to export.
    providers: Map of namespace to filename.
    requirements: Map of filename to required namespaces.
    processed: Set of processed files.
  Returns:
  """ # Filename may have already been processed if it was a requirement of a # previous exported file. # Export requirements before file. # Export file # Skip require statements. # Scan for trailing */ in multi-line comment. # Remove full-line // style comments. # Remove /* */ style comments.
None
target_file
Handle to target file for export.
Handle to target file for export .
source_filename
Name of the file to export.
Name of the file to export .
providers
Map of namespace to filename.
Map of namespace to filename .
requirements
Map of filename to required namespaces.
Map of filename to required namespaces .
processed
Set of processed files.
Set of processed files .