def run(self):
        """Processing the pipeline."""
        self.logger.info("Running with Python %s", sys.version.replace("\n", ""))
        self.logger.info("Running on platform %s", platform.platform())
        self.logger.info("Current cpu count is %d", multiprocessing.cpu_count())

        configuration = self.load_configuration()
        paths = [os.path.abspath(path) for path in Adapter(self.options).path]
        supported_extension = [
            ext.strip() for entry in configuration for ext in Adapter(entry).extension.split()]

        for path, path_and_filename, extension in Application.walk_files_for(paths, supported_extension):
            entry = Select(*configuration) \
                .where(lambda entry: extension in Adapter(entry).extension.split()) \
                .transform(lambda entry: Adapter(entry)) \
                .build()[0]
            # parsing file with regex to get loc and com values
            # 100 lines of code (total) with 50 lines of comments means: loc=50, com=50
            # the ratio would be then: 1.0
            loc, com = self.analyse(path_and_filename, entry.regex)
            ratio = float(com) / float(loc) if loc > 0 and com < loc else 1.0

            self.results.append({
                'type': entry.type,
                'file': path_and_filename.replace(path + '/', ''),
                'loc': loc,
                'com': com,
                'ratio': "%.2f" % ratio
            })
        # for the table we are mainly interested in ratio below defined threshold
        # (except you want to see all of your code: --show-all)
        ppresults = Select(*self.results).where(
            lambda entry: float(Adapter(entry).ratio) < Adapter(self.options).threshold or
            Adapter(self.options).show_all).build()

        # print out results in table format
        pprint(ppresults, keys=['ratio', 'loc', 'com', 'file', 'type'])

        if Adapter(self.options).average:
            all_ratio = Select(*self.results).transform(lambda entry: float(Adapter(entry).ratio)).build()
            avg_ratio = float(sum(all_ratio)) / float(len(all_ratio)) if len(all_ratio) > 0 else 1.0
            self.logger.info('average ratio is %.2f for %d files', avg_ratio, len(all_ratio))
            return avg_ratio >= Adapter(self.options).threshold

        # providing results (mainly for unittesting)
        return len(Select(*self.results).where(
            lambda entry: float(Adapter(entry).ratio) < Adapter(self.options).threshold).build()) == 0
def run ( self ) : self . logger . info ( "Running with Python %s" , sys . version . replace ( "\n" , "" ) ) self . logger . info ( "Running on platform %s" , platform . platform ( ) ) self . logger . info ( "Current cpu count is %d" , multiprocessing . cpu_count ( ) ) configuration = self . load_configuration ( ) paths = [ os . path . abspath ( path ) for path in Adapter ( self . options ) . path ] supported_extension = [ ext . strip ( ) for entry in configuration for ext in Adapter ( entry ) . extension . split ( ) ] for path , path_and_filename , extension in Application . walk_files_for ( paths , supported_extension ) : entry = Select ( * configuration ) . where ( lambda entry : extension in Adapter ( entry ) . extension . split ( ) ) . transform ( lambda entry : Adapter ( entry ) ) . build ( ) [ 0 ] loc , com = self . analyse ( path_and_filename , entry . regex ) ratio = float ( com ) / float ( loc ) if loc > 0 and com < loc else 1.0 self . results . append ( { 'type' : entry . type , 'file' : path_and_filename . replace ( path + '/' , '' ) , 'loc' : loc , 'com' : com , 'ratio' : "%.2f" % ratio } ) ppresults = Select ( * self . results ) . where ( lambda entry : float ( Adapter ( entry ) . ratio ) < Adapter ( self . options ) . threshold or Adapter ( self . options ) . show_all ) . build ( ) pprint ( ppresults , keys = [ 'ratio' , 'loc' , 'com' , 'file' , 'type' ] ) if Adapter ( self . options ) . average : all_ratio = Select ( * self . results ) . transform ( lambda entry : float ( Adapter ( entry ) . ratio ) ) . build ( ) avg_ratio = float ( sum ( all_ratio ) ) / float ( len ( all_ratio ) ) if len ( all_ratio ) > 0 else 1.0 self . logger . info ( 'average ratio is %.2f for %d files' , avg_ratio , len ( all_ratio ) ) return avg_ratio >= Adapter ( self . options ) . threshold return len ( Select ( * self . results ) . where ( lambda entry : float ( Adapter ( entry ) . ratio ) < Adapter ( self . options ) . threshold ) . build ( ) ) == 0
Processing the pipeline.