예제 #1
0
def check_config(srcroot, docroot, modules):
    """ Check the configuration
    """
    errors = 0
    
    # Do all the Python/REST source files exist?
    for module in modules:
        
        # Python modules have a Python source file and a .rst docs file
        if (isinstance(module, list)):
            path = os.path.join(srcroot, module[1])
            if (not ut.is_file(path)):
                print("check_config: %s not found" % path)
                errors += 1
            path = os.path.join(docroot, module[0])
            if (not ut.is_file(path)):
                print("check_config: %s not found" % path)
                errors += 1
        else:
            # REST modules have only an .rst file
            path = os.path.join(docroot, module)
            if (not ut.is_file(path)):
                print("check_config: %s not found" % path)
                errors += 1
            
    return errors
예제 #2
0
 def _check_paths(self, diff):
     ''' Check that:
         (1) file named in diff spec exists (GIT format only)
         (2) file named in '---' line exists or is /dev/null
         (3) file named in '+++' line exists or is /dev/null
         (4) file to be created exists in new tree
         (5) file to be deleted does not exist in old tree
     '''
     
     if (not ut.is_file(ut.join_path(self.sourcedir, diff.a_path))):
         self._error_msg('"a" file not found: %s' % diff.a_path, 2)
         return False
     
     if (diff.old_path != '/dev/null'):
         if (not ut.is_file(ut.join_path(self.sourcedir, diff.old_path))):
             self._error_msg('"old" file not found: %s' % diff.old_path, 2)
             return False
     else:
         if (ut.is_file(ut.join_path(self.sourcedir, diff.new_path))):
             self._error_msg('"new" file found in old tree: %s' % diff.new_path, 2)
             return False
             
     if (diff.new_path != '/dev/null'):
         if (not ut.is_file(ut.join_path(self.sourcedir, diff.new_path))):
             self._error_msg('"new" file not found: %s' % diff.new_path, 2)
             return False
     else:
         if (not ut.is_file(ut.join_path(self.sourcedir, diff.old_path))):
             self._error_msg('"old" file not found in old tree: %s' % diff.old_path, 2)
             return False
             
     return True
예제 #3
0
    def __init__(self, path):
        """ Constructor
          
        Args:
            path (string): path to patch archive file
            
        Raises:
            PT_ParameterError, PT_NotFoundError
        
        Notes:
             A "patch archive" file lists diff sections from patches that were applied to
             produce the associated kernel version. Since the patch archive files can be very large,
             we take care to avoid copying or storing data that is not of interest to the user.
        """
        #--

        self.name = 'Archive'
        
        if (not ut.is_string_type(path)):
            raise PT_ParameterError(self.name, path)
        
        if (not ut.is_file(path)):
            raise PT_NotFoundError(self.name, path)
        
        self._path = path
예제 #4
0
 def vp2f(self, patchname, params):
     """ List patch and files it uses
 
     Args:
         patchname (string): name of patch file
         params    (dict):   parameters
             patchdir  (string, required): path of patches folder
             
     Raises:
         PT_ParameterError for any missing files
     """
     #--
     
     if (not isinstance(params, dict)):
         raise PT_ParameterError(self.name, 'params')
       
     sourcedir = self._check_directory_param(params, 'sourcedir')
     patchdir  = self._check_directory_param(params, 'patchdir')
     patchpath = self._check_filename_param(patchdir, patchname, 'patchname')
     
     # Get list of source filenames referenced in patch
     # Note that a patch may refer to files that do not exist in the source tree.
     filelist = Patch.list_files(patchpath)
     filepaths = []
     for file_ in filelist:
         path = ut.join_path(sourcedir, file_)
         if (ut.is_file(path)):
             filepaths += [path]
         
     paths = [patchpath] + filepaths
     
     return self._view(paths)
예제 #5
0
    def vp2f(self, patchname, params):
        """ List patch and files it uses
    
        Args:
            patchname (string): name of patch file
            params    (dict):   parameters
                patchdir  (string, required): path of patches folder
                
        Raises:
            PT_ParameterError for any missing files
        """
        #--

        if (not isinstance(params, dict)):
            raise PT_ParameterError(self.name, 'params')

        sourcedir = self._check_directory_param(params, 'sourcedir')
        patchdir = self._check_directory_param(params, 'patchdir')
        patchpath = self._check_filename_param(patchdir, patchname,
                                               'patchname')

        # Get list of source filenames referenced in patch
        # Note that a patch may refer to files that do not exist in the source tree.
        filelist = Patch.list_files(patchpath)
        filepaths = []
        for file_ in filelist:
            path = ut.join_path(sourcedir, file_)
            if (ut.is_file(path)):
                filepaths += [path]

        paths = [patchpath] + filepaths

        return self._view(paths)
예제 #6
0
 def _check_filename_param(self, prefix, value, name):
     
     if (not ut.is_string_type(value)):
         raise PT_ParameterError(self.name, name)
     
     path = ut.join_path(prefix, value)
     if (not ut.is_file(path)):
         raise PT_NotFoundError(self.name, value)
     
     return path
예제 #7
0
    def _check_filename_param(self, prefix, value, name):

        if (not ut.is_string_type(value)):
            raise PT_ParameterError(self.name, name)

        path = ut.join_path(prefix, value)
        if (not ut.is_file(path)):
            raise PT_NotFoundError(self.name, value)

        return path
예제 #8
0
    def vp2a(self, patchname, archpath, params):
        """ Display patch and archive diff sections that use its files
        
        Args:
            patchname (string): name of patch file
            archpath  (string): path to archive file
            params    (dict):   parameters
                patchdir (string, required): path of patches folder
                tempdir  (string, required): path to store temporary data
                
        Raises:    
            PT_ParameterError for any missing files
        
        Notes:
            Launches the editor synchronously, since a temporary file is created to hold
            the archive sections.
        """
        #--

        if (not isinstance(params, dict)):
            raise PT_ParameterError(self.name, 'params')

        sourcedir = self._check_directory_param(params, 'sourcedir')
        patchdir = self._check_directory_param(params, 'patchdir')
        tempdir = self._check_directory_param(params, 'tempdir')

        patchpath = self._check_filename_param(patchdir, patchname,
                                               'patchname')
        if (not ut.is_file(archpath)):
            raise PT_NotFoundError(self.name, archpath)

        # Get list of files used by the patch
        filelist = Patch.list_files(patchpath)
        filepaths = [ut.join_path(sourcedir, file_) for file_ in filelist]

        # Get archive diff sections that use any of the files
        strings = []
        for diff in self._get_diffs(archpath, filepaths):
            strings += diff

        if (len(strings) == 0):
            return []

        # Store the diff sections in a temporary file
        archname = archpath[archpath.rfind('/') + 1:]
        tempname = archname + '.tmp'
        temppath = ut.join_path(tempdir, tempname)
        ut.write_strings(strings, temppath)

        self._view([patchpath, temppath], True)

        # Note that we requested _view to wait for subprocess exit above,
        # so that we do not try to delete the file while it is in use.

        os.remove(temppath)
예제 #9
0
    def vp2a(self, patchname, archpath, params):
        """ Display patch and archive diff sections that use its files
        
        Args:
            patchname (string): name of patch file
            archpath  (string): path to archive file
            params    (dict):   parameters
                patchdir (string, required): path of patches folder
                tempdir  (string, required): path to store temporary data
                
        Raises:    
            PT_ParameterError for any missing files
        
        Notes:
            Launches the editor synchronously, since a temporary file is created to hold
            the archive sections.
        """
        #--
        
        if (not isinstance(params, dict)):
            raise PT_ParameterError(self.name, 'params')
        
        sourcedir  = self._check_directory_param(params, 'sourcedir')
        patchdir = self._check_directory_param(params, 'patchdir')
        tempdir = self._check_directory_param(params, 'tempdir')
        
        patchpath = self._check_filename_param(patchdir, patchname, 'patchname')
        if (not ut.is_file(archpath)):
            raise PT_NotFoundError(self.name, archpath)
        
        # Get list of files used by the patch
        filelist = Patch.list_files(patchpath)
        filepaths = [ut.join_path(sourcedir, file_) for file_ in filelist]

        # Get archive diff sections that use any of the files
        strings = []
        for diff in self._get_diffs(archpath, filepaths):
            strings += diff
        
        if (len(strings) == 0):
            return []
        
        # Store the diff sections in a temporary file
        archname = archpath[archpath.rfind('/') + 1:]
        tempname = archname + '.tmp'
        temppath = ut.join_path(tempdir, tempname)
        ut.write_strings(strings, temppath)
        
        self._view([patchpath, temppath], True)
        
        # Note that we requested _view to wait for subprocess exit above,
        # so that we do not try to delete the file while it is in use.
        
        os.remove(temppath)
예제 #10
0
    def vcpf(self, checkpath, patchname, params):
        """ List checker output file, patch and files it uses
    
        Args:
            checkpath (string): path to Checker output file
            patchname (string): patch name
            params (dict) parameters:
                sourcedir (string, required): path of sources folder
                patchdir  (string, required): path of patches folder
            
        Raises:    
            PT_ParameterError
            PT_NotFoundError
        """
        #--

        if (not isinstance(params, dict)):
            raise PT_ParameterError(self.name, 'params')

        if (not ut.is_file(checkpath)):
            raise PT_NotFoundError(self.name, checkpath)

        sourcedir = self._check_directory_param(params, 'sourcedir')
        patchdir = self._check_directory_param(params, 'patchdir')
        patchpath = self._check_filename_param(patchdir, patchname,
                                               'patchname')

        # Get list of source filenames referenced in patch.
        # Note that a patch may refer to files that do not exist in the source tree.
        filelist = Patch.list_files(patchpath)
        filepaths = []
        for file_ in filelist:
            path = ut.join_path(sourcedir, file_)
            if (ut.is_file(path)):
                filepaths += [path]

        paths = [checkpath, patchpath] + filepaths

        return self._view(paths)
예제 #11
0
    def vcpf(self, checkpath, patchname, params):
        """ List checker output file, patch and files it uses
    
        Args:
            checkpath (string): path to Checker output file
            patchname (string): patch name
            params (dict) parameters:
                sourcedir (string, required): path of sources folder
                patchdir  (string, required): path of patches folder
            
        Raises:    
            PT_ParameterError
            PT_NotFoundError
        """
        #--

        if (not isinstance(params, dict)):
            raise PT_ParameterError(self.name, 'params')
    
        if (not ut.is_file(checkpath)):
            raise PT_NotFoundError(self.name, checkpath)
        
        sourcedir = self._check_directory_param(params, 'sourcedir')
        patchdir  = self._check_directory_param(params, 'patchdir')
        patchpath = self._check_filename_param(patchdir, patchname, 'patchname')
        
        # Get list of source filenames referenced in patch.
        # Note that a patch may refer to files that do not exist in the source tree.
        filelist = Patch.list_files(patchpath)
        filepaths = []
        for file_ in filelist:
            path = ut.join_path(sourcedir, file_)
            if (ut.is_file(path)):
                filepaths += [path]
            
        paths = [checkpath, patchpath] + filepaths
            
        return self._view(paths)
예제 #12
0
    def __init__(self, path):
        """ Constructor
        
        Args:
            path (string): path to patch file
            
        Raises:
            PT_ParameterError
            PT_NotFoundError
        
        Notes:
            Commented out diff and hunk sections are omitted.
        """
        #--

        self.name = 'Patch'

        if (not ut.is_string_type(path)):
            raise PT_ParameterError(self.name, path)

        if (not ut.is_file(path)):
            raise PT_NotFoundError(self.name, path)

        strings = Strings(ut.read_strings(path))
        strings = strings.discard('"""', '"""')

        # Split any email header from the patch data
        (_, body) = strings.partition('diff -')

        if (body is None):  #all diffs commented out?
            self.diffs = []
            self.patch_type = 'text'
            self.patch_mode = 'git'
            print "body is none"
        elif (body[0].startswith('diff --git ')):
            # Split any email footer from the patch data
            (body, _) = body.rpartition('-- ')
            self._parse_body(body, 'diff --git ')
            self.patch_mode = 'git'
            print "git diff"
        else:
            self._parse_body(body, 'diff -')
            self.patch_mode = 'urn'
            print "urn"
예제 #13
0
    def __init__(self, path):
        """ Constructor
        
        Args:
            path (string): path to patch file
            
        Raises:
            PT_ParameterError
            PT_NotFoundError
        
        Notes:
            Commented out diff and hunk sections are omitted.
        """
        #--
 
        self.name = 'Patch'
        
        if (not ut.is_string_type(path)):
            raise PT_ParameterError(self.name, path)
        
        if (not ut.is_file(path)):
            raise PT_NotFoundError(self.name, path)
        
        strings = Strings(ut.read_strings(path))
        strings = strings.discard('"""','"""')
        
        # Split any email header from the patch data
        (_, body) = strings.partition('diff -')
        
        if (body is None): #all diffs commented out?
            self.diffs = []
            self.patch_type = 'text'
            self.patch_mode = 'git'
        elif (body[0].startswith('diff --git ')):
            # Split any email footer from the patch data
            (body, _) = body.rpartition('-- ')
            self._parse_body(body, 'diff --git ')
            self.patch_mode = 'git'
        else:
            self._parse_body(body, 'diff -')
            self.patch_mode = 'urn'
예제 #14
0
    def view(self, files):
        """ Launch specified editor to view the file(s)
    
        Args:
            files (list): paths of files to display
            check_files(bool): verify target files exist
                          
        Raises:
            PT_ParameterError for any missing files
        """
        #--

        if (not isinstance(files, list)):
            raise PT_ParameterError(self.name, 'files')

        # The user may specify a file that does not exist
        paths = []
        for path in files:
            if (ut.is_file(path)):
                paths += [path]

        return self._view(paths)
예제 #15
0
 def view(self, files):
     """ Launch specified editor to view the file(s)
 
     Args:
         files (list): paths of files to display
         check_files(bool): verify target files exist
                       
     Raises:
         PT_ParameterError for any missing files
     """
     #--
     
     
     if (not isinstance(files, list)):
         raise PT_ParameterError(self.name, 'files')
     
     # The user may specify a file that does not exist
     paths = []
     for path in files:
         if (ut.is_file(path)):
             paths += [path]
     
     return self._view(paths)
예제 #16
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)