Example #1
0
 def _sort_on_date(self, patches):
     ''' Sort patches on date field. The format is like:
             Fri, 28 Dec 2012 21:00:31 +0200
     '''
     records = []
     for patch in patches:
         strings = ut.read_strings(ut.join_path(self.patchdir, patch))
         for string in strings:
             if ("Date:" in string): # e.g. 'Date: Wed, 16 Jan 2013 19:09:47 +0000'
                 fields = ut.string_to_words(string[6:].lstrip(' \t'))
                 _, s_day, s_mon, s_year, s_hms, _ = fields
                 s_hour, s_minute, s_second = s_hms.split(':')
                 day, year = int(s_day), int(s_year)
                 hour, minute, second = int(s_hour), int(s_minute), int(s_second)
                 month = self.month_numbers[s_mon]
                 # ignoring microseconds
                 dt = datetime(year, month, day, hour, minute, second) 
                 records += [(dt, patch)]
                 break
     
     records = sorted(records, key = lambda r: r[0])
     
     patches = [patch for (_, patch) in records]
     
     return patches
Example #2
0
    def _sort_on_date(self, patches):
        ''' Sort patches on date field. The format is like:
                Fri, 28 Dec 2012 21:00:31 +0200
        '''
        records = []
        for patch in patches:
            strings = ut.read_strings(ut.join_path(self.patchdir, patch))
            for string in strings:
                if ("Date:" in string
                    ):  # e.g. 'Date: Wed, 16 Jan 2013 19:09:47 +0000'
                    fields = ut.string_to_words(string[6:].lstrip(' \t'))
                    _, s_day, s_mon, s_year, s_hms, _ = fields
                    s_hour, s_minute, s_second = s_hms.split(':')
                    day, year = int(s_day), int(s_year)
                    hour, minute, second = int(s_hour), int(s_minute), int(
                        s_second)
                    month = self.month_numbers[s_mon]
                    # ignoring microseconds
                    dt = datetime(year, month, day, hour, minute, second)
                    records += [(dt, patch)]
                    break

        records = sorted(records, key=lambda r: r[0])

        patches = [patch for (_, patch) in records]

        return patches
Example #3
0
    def _is_landmark(self, filepath, string):
        """ Determine if a string is a "landmark" string , i.e. one that is likely to be unique
            in the file, and thus may be easy to isolate if it is present. Searching for strings
            such as '};' could give a large number of extraneous matches. 
        """

        if ((len(string) == 0) or string.isspace()):
            return False
        else:
            words = ut.string_to_words(string)

        words2 = []
        for word in words:
            if ('_' in word):
                sylls = word.split('_')
                words2 += sylls
            else:
                words2 += [word]
        words = words2

        words2 = []
        for word in words:
            if ('-' in word):
                sylls = word.split('-')
                words2 += sylls
            else:
                words2 += [word]
        words = words2

        if (len(words) > 4):
            return True

        index = filepath.rfind('/') + 1
        filename = filepath[index:]

        if (filename.endswith('.c') or filename.endswith('.h')):
            return self._is_c_h_landmark(string, words)

        elif (filename.endswith('.S') or filename.endswith('.inc')):
            return self._is_S_landmark(string, words)

        elif (filename.endswith('.dts') or filename.endswith('.dtsi')):
            return self._is_dts_landmark(string, words)

        elif (filename.startswith('Kconfig')):
            return self._is_Kconfig_landmark(string, words)

        elif (filename.startswith('Makefile')):
            return self._is_Makefile_landmark(string, words)

        return self._is_generic_landmark(string, words)
Example #4
0
  def _is_landmark(self, filepath, string):
      """ Determine if a string is a "landmark" string , i.e. one that is likely to be unique
          in the file, and thus may be easy to isolate if it is present. Searching for strings
          such as '};' could give a large number of extraneous matches. 
      """
  
      if ((len(string) == 0) or string.isspace()):
          return False
      else:
          words = ut.string_to_words(string)
      
      words2 = []
      for word in words:
          if ('_' in word):
              sylls = word.split('_')
              words2 += sylls
          else:
              words2 += [word]
      words = words2
      
      words2 = []
      for word in words:
          if ('-' in word):
              sylls = word.split('-')
              words2 += sylls
          else:
              words2 += [word]
      words = words2
      
      if (len(words) > 4):
          return True
      
      index = filepath.rfind('/') + 1
      filename = filepath[index:]
          
      if (filename.endswith('.c') or filename.endswith('.h')):
          return self._is_c_h_landmark(string, words)
     
      elif (filename.endswith('.S') or filename.endswith('.inc')):
          return self._is_S_landmark(string, words)
      
      elif (filename.endswith('.dts') or filename.endswith('.dtsi')):   
          return self._is_dts_landmark(string, words)
              
      elif (filename.startswith('Kconfig')):
          return self._is_Kconfig_landmark(string, words)
 
      elif (filename.startswith('Makefile')):
          return self._is_Makefile_landmark(string, words)
      
      return self._is_generic_landmark(string, words)