Changeset f9798ad in rtems-libbsd for builder.py


Ignore:
Timestamp:
May 30, 2016, 11:49:31 PM (3 years ago)
Author:
Chris Johns <chrisj@…>
Branches:
afaeccc05a556f6aa25ba044a7e49d6aa634a59e, freebsd-9.3, master
Children:
ab5cd63
Parents:
70d52b8
Message:

Add a stats report command.

The report shows the level of changes we have made to the FreeBSD code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • builder.py

    r70d52b8 rf9798ad  
    5656filesProcessedCount = 0
    5757filesProcessed = []
     58filesTotal = 0
     59filesTotalLines = 0
     60filesTotalInserts = 0
     61filesTotalDeletes = 0
     62diffDetails = { }
    5863
    5964verboseInfo = 1
     
    6570    return verboseLevel >= level
    6671
    67 def changedFileSummary():
     72def changedFileSummary(statsReport = False):
     73
     74    global filesTotal, filesTotalLines, filesTotalInserts, filesTotalDeletes
     75
    6876    if isDiffMode == False:
    69         print('%d file(s) were changed:' % (filesProcessedCount))
    7077        if verbose():
     78            print('%d file(s) were changed:' % (filesProcessedCount))
    7179            for f in sorted(filesProcessed):
    7280                print(' %s' % (f))
     81        else:
     82            print('%d file(s) were changed.' % (filesProcessedCount))
     83    if statsReport:
     84        print('Stats Report:')
     85        transparent = filesTotal - len(diffDetails)
     86        changes = filesTotalInserts + filesTotalDeletes
     87        opacity = (float(changes) / (filesTotalLines + changes)) * 100.0
     88        print(' Total File(s):%d  Unchanged:%d (%.1f%%)  Changed:%d' \
     89              '   Opacity:%5.1f%% Lines:%d Edits:%d (+):%d (-):%d'  % \
     90              (filesTotal, transparent, (float(transparent) / filesTotal) * 100.0, len(diffDetails), \
     91               opacity, filesTotalLines, changes, filesTotalInserts, filesTotalDeletes))
     92        #
     93        # Sort by opacity.
     94        #
     95        ordered_diffs = sorted(diffDetails.items(), key = lambda diff: diff[1].opacity, reverse = True)
     96        for f in ordered_diffs:
     97            print('  %s' % (diffDetails[f[0]].status()))
    7398
    7499def readFile(name):
     
    105130    def __str__(self):
    106131        return self.msg
     132
     133#
     134# Diff Record
     135#
     136class diffRecord:
     137    def __init__(self, src, dst, orig, diff, inserts, deletes):
     138        self.src = src
     139        self.dst = dst
     140        self.orig = orig
     141        self.diff = diff
     142        self.lines = len(orig)
     143        self.inserts = inserts
     144        self.deletes = deletes
     145        self.changes = inserts + deletes
     146        self.opacity = (float(self.changes) / (self.lines + self.changes)) * 100.0
     147
     148    def __repr__(self):
     149        return self.src
     150
     151    def status(self):
     152        return 'opacity:%5.1f%% edits:%4d (+):%-4d (-):%-4d %s' % \
     153            (self.opacity, self.changes, self.inserts, self.deletes, self.src)
    107154
    108155#
     
    222269        sys.exit(2)
    223270
     271def diffSource(dstLines, srcLines, src, dst):
     272    global filesTotal, filesTotalLines, filesTotalInserts, filesTotalDeletes
     273    #
     274    # Diff, note there is no line termination on each string.  Expand the
     275    # generator to list because the generator is not reusable.
     276    #
     277    diff = list(difflib.unified_diff(dstLines,
     278                                     srcLines,
     279                                     fromfile = src,
     280                                     tofile = dst,
     281                                     n = 5,
     282                                     lineterm = ''))
     283    inserts = 0
     284    deletes = 0
     285    if len(diff) > 0:
     286        if src in diffDetails and \
     287           diffDetails[src].dst != dst and diffDetails[src].diff != diff:
     288            raise error('repeated diff of file different: src:%s dst:%s' % (src, dst))
     289        for l in diff:
     290            if l[0] == '-':
     291                deletes += 1
     292            elif l[0] == '+':
     293                inserts += 1
     294        diffDetails[src] = diffRecord(src, dst, srcLines, diff, inserts, deletes)
     295
     296    #
     297    # Count the total files, lines and the level of changes.
     298    #
     299    filesTotal += 1
     300    filesTotalLines += len(srcLines)
     301    filesTotalInserts += inserts
     302    filesTotalDeletes += deletes
     303
     304    return diff
     305
    224306#
    225307# Converters provide a way to alter the various types of code. The conversion
     
    277359
    278360        #
    279         # Diff, note there is no line termination on each string.  Expand the
    280         # generator to list because the generator is not reusable.
    281         #
    282         diff = list(difflib.unified_diff(dstLines,
    283                                          srcLines,
    284                                          fromfile = src,
    285                                          tofile = dst,
    286                                          n = 5,
    287                                          lineterm = ''))
     361        # Diff, note there is no line termination on each string.
     362        #
     363        diff = diffSource(dstLines, srcLines, src, dst)
    288364
    289365        #
Note: See TracChangeset for help on using the changeset viewer.