parameters: (grd_files, src_dirs)
return_statement: return 0
docstring: Will collect the message ids out of the given GRD files and then scan
    the source directories to try and figure out what ids are not currently
    being used by any source.
  
    grd_files:
      A list of GRD files to collect the ids from.
    src_dirs:
      A list of directories to walk looking for source files.
docstring_summary: Will collect the message ids out of the given GRD files and then scan
    the source directories to try and figure out what ids are not currently
    being used by any source.
docstring_tokens: Will collect the message ids out of the given GRD files and then scan the source directories to try and figure out what ids are not currently being used by any source .
function: def CheckForUnusedGrdIDsInSources(grd_files, src_dirs):
    """Will collect the message ids out of the given GRD files and then scan
    the source directories to try and figure out what ids are not currently
    being used by any source.
  
    grd_files:
      A list of GRD files to collect the ids from.
    src_dirs:
      A list of directories to walk looking for source files.
    """
    # Collect all the ids into a large map
    all_ids = set()
    file_id_map = {}
    for y in grd_files:
      handler = GrdIDExtractor()
      xml.sax.parse(y, handler)
      files_ids = handler.allIDs()
      file_id_map[y] = files_ids
      all_ids |= files_ids
  
  
    # The regex that will be used to check sources
    id_regex = re.compile('IDS_[A-Z0-9_]+')
  
    # Make sure the regex matches every id found.
    got_err = False
    for x in all_ids:
      match = id_regex.search(x)
      if match is None:
        print 'ERROR: "%s" did not match our regex' % (x)
        got_err = True
      if not match.group(0) is x:
        print 'ERROR: "%s" did not fully match our regex' % (x)
        got_err = True
    if got_err:
      return 1
  
    # The regex for deciding what is a source file
    src_regex = re.compile('\.(([chm])|(mm)|(cc)|(cp)|(cpp)|(xib)|(py))$')
  
    ids_left = all_ids.copy()
  
    # Scanning time.
    for src_dir in src_dirs:
      for root, dirs, files in os.walk(src_dir):
        # Remove svn directories from recursion
        if '.svn' in dirs:
          dirs.remove('.svn')
        for file in files:
          if src_regex.search(file.lower()):
            full_path = os.path.join(root, file)
            src_file_contents = open(full_path).read()
            for match in sorted(set(id_regex.findall(src_file_contents))):
              if match in ids_left:
                ids_left.remove(match)
              if DEBUG:
                if not match in all_ids:
                  print '%s had "%s", which was not in the found IDs' % \
                    (full_path, match)
          elif DEBUG > 1:
            full_path = os.path.join(root, file)
            print 'Skipping %s.' % (full_path)
  
    # Anything left?
    if len(ids_left) > 0:
      print 'The following ids are in GRD files, but *appear* to be unused:'
      for file_path, file_ids in file_id_map.iteritems():
        missing = ids_left.intersection(file_ids)
        if len(missing) > 0:
          print '  %s:' % (file_path)
          print '\n'.join('    %s' % (x) for x in sorted(missing))
  
    return 0
function_tokens: def CheckForUnusedGrdIDsInSources ( grd_files , src_dirs ) : # Collect all the ids into a large map all_ids = set ( ) file_id_map = { } for y in grd_files : handler = GrdIDExtractor ( ) xml . sax . parse ( y , handler ) files_ids = handler . allIDs ( ) file_id_map [ y ] = files_ids all_ids |= files_ids # The regex that will be used to check sources id_regex = re . compile ( 'IDS_[A-Z0-9_]+' ) # Make sure the regex matches every id found. got_err = False for x in all_ids : match = id_regex . search ( x ) if match is None : print 'ERROR: "%s" did not match our regex' % ( x ) got_err = True if not match . group ( 0 ) is x : print 'ERROR: "%s" did not fully match our regex' % ( x ) got_err = True if got_err : return 1 # The regex for deciding what is a source file src_regex = re . compile ( '\.(([chm])|(mm)|(cc)|(cp)|(cpp)|(xib)|(py))$' ) ids_left = all_ids . copy ( ) # Scanning time. for src_dir in src_dirs : for root , dirs , files in os . walk ( src_dir ) : # Remove svn directories from recursion if '.svn' in dirs : dirs . remove ( '.svn' ) for file in files : if src_regex . search ( file . lower ( ) ) : full_path = os . path . join ( root , file ) src_file_contents = open ( full_path ) . read ( ) for match in sorted ( set ( id_regex . findall ( src_file_contents ) ) ) : if match in ids_left : ids_left . remove ( match ) if DEBUG : if not match in all_ids : print '%s had "%s", which was not in the found IDs' % ( full_path , match ) elif DEBUG > 1 : full_path = os . path . join ( root , file ) print 'Skipping %s.' % ( full_path ) # Anything left? if len ( ids_left ) > 0 : print 'The following ids are in GRD files, but *appear* to be unused:' for file_path , file_ids in file_id_map . iteritems ( ) : missing = ids_left . intersection ( file_ids ) if len ( missing ) > 0 : print '  %s:' % ( file_path ) print '\n' . join ( '    %s' % ( x ) for x in sorted ( missing ) ) return 0