Ejemplo n.º 1
0
    def _patchCIA1267( self, dryRun=False ):
        """
            Check files for outdated CSV keywords and remove
            these keywords and expanded information from the source code
        """
        files    = FastScript.getFilesInDirRecursive( 'bin' ) | \
                   FastScript.getFilesInDirRecursive( 'examples' ) | \
                   FastScript.getFilesInDirRecursive( 'src' ) | \
                   FastScript.getFilesInDirRecursive( 'test' )

        modified = []

        # CSV keywords
        keywords = frozenset( [ '$Author', '$Date', '$Header', '$Id', '$Log',
                                '$Locker', '$Name', '$RCSfile', '$Revision',
                                '$Source', '$State' ] )

        for filePath in files:
            rewrite     = False

            try:
                fileContent = FastScript.getFileContent( filename=filePath,
                                                         splitLines=True )
            except UnicodeDecodeError:
                # most probably we attempt to read a binary file,
                # e.g. a compiled executable under bin/ or the like
                continue

            # check each line for CSV keyword and remove line if found
            for line in fileContent:
                if any( key in line for key in keywords):
                    rewrite = True
                    fileContent.remove( line )

            if rewrite:
                if dryRun:
                    logging.info( '[DRY-RUN] patching %s', filePath )
                else:
                    logging.info( 'patching %s', filePath )
                    newContent = ''.join( fileContent )
                    FastScript.setFileContent( filePath, newContent )

                modified.append( filePath )

        return modified
Ejemplo n.º 2
0
    def includeDir(self, dirPath):
        Any.requireIsTextNonEmpty(dirPath)

        # FastScript.getFilesInDirRecursive() returns:
        #    * absolute file paths if absolute dir. path provided
        #    * relative file paths if relative dir. Path provided
        #
        # shorten absolute path names to relative ones for shorter outputs:
        searchPath = os.path.relpath(dirPath)

        for filePath in FastScript.getFilesInDirRecursive(searchPath):

            # only consider whitelisted extensions, f.i. do not analyze
            # binaries, bytecode files, PDFs etc.
            fileExt = os.path.splitext(filePath)[-1]

            if fileExt in self.includeExts:
                if not os.path.islink(filePath):
                    self.includeFile(filePath)
Ejemplo n.º 3
0
    def _patchCIA1265( self, dryRun=False ):
        """
            Checks BBCM package for included outdated headerfiles and
            replaces them with the nowadays version.
            Duplicates will be deleted.
        """
        if not self.details.isBBCM():
            return False

        # Get a list of all files to check
        files    = FastScript.getFilesInDirRecursive( 'src' )
        modified = []

        # Check every file
        for filePath in files:
            logging.debug( 'processing %s', filePath )

            # Only rewrite line if changed
            rewrite = False
            # Get file content
            fileContent = FastScript.getFileContent( filename=filePath,
                                                     splitLines=True )
            # Check every line
            for line in fileContent:
                item = line.split()

                # Check for include statement
                if line.find( '#include <BBDM' ) != -1:
                    # Replace old package names with the nowadays form
                    match = re.search( r"-A|-CID|-S", item[ 1 ] )
                    if match:
                        fileContent[ fileContent.index( line ) ] = re.sub(
                            r"-A|-CID|-S", "", line )
                        rewrite = True

            includes = []

            # Check file backwards
            for line in reversed( fileContent ):
                item = line.split()

                if line.find( '#include <BBDM' ) != -1:
                    # Check for duplicates and remove existing ones
                    if line in includes:
                        rewrite = True
                        fileContent.remove( line )

                    # add to list of known includes
                    else:
                        includes.append( line )

            # Overwrite file with new content
            try:
                if rewrite:
                    if dryRun:
                        logging.info( '[DRY-RUN] patching %s', filePath )
                    else:
                        logging.info( 'patching %s', filePath )
                        newContent = ''.join( fileContent )
                        FastScript.setFileContent( filePath, newContent )

                    modified.append( filePath )

            except IOError as e:
                logging.error( e )

        return modified