Пример #1
0
 def list_files(patchpath):
     """ List the files referenced by a patch, without duplicates
     
     Args:
         patchpath (string) path to patch file
         
     Returns:
         list of filenames
         
     Notes:
         A "filename" is the portion of the file's path after the kernel root,
         e.g. "drivers/iio/...".
     """
     #--
     
     strings = ut.read_strings(patchpath)
     files = {}
     for string in strings:
         if (string.startswith('diff --git ')):
             filename = ut.get_string_filename(string)
             files[filename] = True
     
     filenames = sorted(files)   # 2to3
     
     return filenames
Пример #2
0
    def list_files(patchpath):
        """ List the files referenced by a patch, without duplicates
        
        Args:
            patchpath (string) path to patch file
            
        Returns:
            list of filenames
            
        Notes:
            A "filename" is the portion of the file's path after the kernel root,
            e.g. "drivers/iio/...".
        """
        #--

        strings = ut.read_strings(patchpath)
        files = {}
        for string in strings:
            if (string.startswith('diff --git ')):
                filename = ut.get_string_filename(string)
                files[filename] = True

        filenames = sorted(files)  # 2to3

        return filenames
Пример #3
0
 def _get_diffs(self, archive, filenames):
     ''' Generate list of diff sections that refer to files in filenames
     '''
     
     strings = ut.read_strings(archive)
     
     diff = []
     for index in range(len(strings)):
         string = strings[index]
         if (string.lstrip().startswith('diff --git ')):
             if (len(diff) > 0):
                 yield diff
             filename = ut.get_string_filename(string)
             if (filename in filenames):
                 diff = ["%04d: %s" % (index + 1, string)]
         elif (len(diff) > 0):
             diff += ["%04d: %s" % (index + 1, string)]
     if (len(diff) > 0):
         yield diff
Пример #4
0
    def _get_diffs(self, archive, filenames):
        ''' Generate list of diff sections that refer to files in filenames
        '''

        strings = ut.read_strings(archive)

        diff = []
        for index in range(len(strings)):
            string = strings[index]
            if (string.lstrip().startswith('diff --git ')):
                if (len(diff) > 0):
                    yield diff
                filename = ut.get_string_filename(string)
                if (filename in filenames):
                    diff = ["%04d: %s" % (index + 1, string)]
            elif (len(diff) > 0):
                diff += ["%04d: %s" % (index + 1, string)]
        if (len(diff) > 0):
            yield diff
Пример #5
0
 def sections(self, filenames):
     """ Find archive file sections that modify files also modified by our patches
     
     Args:
         filenames (list): file names referenced in our patches
         
     Returns:
         A list of sections. Each section is a list of strings, in which
         the first string identifies the start line number of a diff section,
         and the remaining strings are the content of the diff section.
         
     Raises:
         None
     """
     #--
     sections = []
     for (begin, segment) in self._segments():
         if (ut.get_string_filename(segment[0]) in filenames):
             sections += [['archive line %d:' % begin] + segment]
     
     return sections
Пример #6
0
    def _get_data(self):
        ''' Scan patchset to get two mappings:
                filedata maps filenames to patches
                patchdata maps patches to filenames
        ''' 

        filedata  = {}
        patchdata = {}
        for patchname in self.get_patch_names():
            filelist = []
            strings = ut.read_strings(ut.join_path(self.patchdir, patchname))
            for index in range(len(strings)):
                if (strings[index].startswith('diff --git ')):
                    filename = ut.get_string_filename(strings[index])
                    if (filename in filedata):
                        filedata[filename] += [(patchname, index)]
                    else:
                        filedata[filename] = [(patchname, index)]
                    filelist += [(filename, index)]
            patchdata[patchname] = filelist
                        
        self.filedata  = filedata                
        self.patchdata = patchdata
Пример #7
0
    def _get_data(self):
        ''' Scan patchset to get two mappings:
                filedata maps filenames to patches
                patchdata maps patches to filenames
        '''

        filedata = {}
        patchdata = {}
        for patchname in self.get_patch_names():
            filelist = []
            strings = ut.read_strings(ut.join_path(self.patchdir, patchname))
            for index in range(len(strings)):
                if (strings[index].startswith('diff --git ')):
                    filename = ut.get_string_filename(strings[index])
                    if (filename in filedata):
                        filedata[filename] += [(patchname, index)]
                    else:
                        filedata[filename] = [(patchname, index)]
                    filelist += [(filename, index)]
            patchdata[patchname] = filelist

        self.filedata = filedata
        self.patchdata = patchdata
Пример #8
0
 def watch(self, archpath):
     """ View files related to archive diff sections
     
     Args:
         archpath (string): path to patch archive file
         
     Returns:
         None. Output is a series of launches of the Viewer to view the files.
         
     Raises:
         PT_ParameterError
         PT_NotFoundError
     """
     #--
     
     if (not ut.is_string_type(archpath)):
         raise PT_ParameterError(self.name, 'archpath') 
     
     if (not ut.is_file(archpath)):
         raise PT_NotFoundError(self.name, archpath)
            
     tempfile = ut.join_path(self._tempdir, 'archdata.txt')
     filedata = self._patchset.get_file_data()
     filenames = [key for key in filedata]
     a = Archive(archpath)
     s = a.sections(filenames)
     print("Found %d matching sections" % len(s))
     v = Viewer()
     for section in s:
         ut.write_strings(section, tempfile)
         filename = ut.get_string_filename(section[1])
         filepath = ut.join_path(self._sourcedir, filename)
         patchfiles = []
         for (fn, _) in filedata[filename]:
             patchfiles += [ut.join_path(self._patchdir, fn)]
         r = v.view([tempfile, filepath] + patchfiles)
         print(r)