def scanFile(fp, isVerbose, keepGoing, dumpTellS, theS=sys.stdout):
    #    print(dumpTellS)
    try:
        myPrh = PhysRec.PhysRecRead(fp, fp, keepGoing)
    except PhysRec.ExceptionPhysRec as err:
        print('Can not open file, error: %s' % str(err))
        return
    # Now other stuff generated by this loop
    theS.write('Offset        Length  Type  Logical Data\n')
    myLdSigma = bytes()
    myOffs = myPrh.tellLr()
    # Histogram of lengths and types
    myHistLen = Histogram.Histogram()
    myHistTyp = Histogram.Histogram()
    for myLd, isLdStart in myPrh.genLd():
        if isLdStart:
            if len(myLdSigma) == 0:
                # First time through the loop then don't write anything
                pass
            else:
                # This is not the first time through the loop
                # so write out the trailing LogicalData length
                lrType = -1
                if len(myLdSigma) > 0:
                    lrType = myLdSigma[0]
                    myHistLen.add(len(myLdSigma))
                    myHistTyp.add(lrType)
                theS.write('0x{:08X}  {:8d}  {:4d}'.format(
                    myOffs, len(myLdSigma), lrType))
                if myOffs not in dumpTellS \
                and not isVerbose and len(myLdSigma) > LEN_TRUNCATE:
                    theS.write('  {!r:s}...\n'.format(
                        myLdSigma[0:LEN_TRUNCATE]))
                else:
                    theS.write('  {!r:s}\n'.format(myLdSigma))
                myLdSigma = bytes()
                myOffs = myPrh.tellLr()
        myLdSigma += myLd
    if len(myLdSigma) > 0:
        theS.write('0x{:08X}  {:8d}  {:4d}'.format(myOffs, len(myLdSigma),
                                                   lrType))
        if myOffs not in dumpTellS \
        and not isVerbose and len(myLdSigma) > LEN_TRUNCATE:
            theS.write('  {!r:s}...\n'.format(myLdSigma[0:LEN_TRUNCATE]))
        else:
            theS.write('  {:s}\n'.format(myLdSigma))
    theS.write('Histogram of Logical Data lengths:\n')
    theS.write(myHistLen.strRep(100, valTitle='Bytes', inclCount=True))
    theS.write('\n')
    theS.write('Histogram of Logical Record types:\n')
    theS.write(myHistTyp.strRep(100, inclCount=True))
    theS.write('\n')
Exemple #2
0
def scanFile(fp, keepGoing, theS=sys.stdout):
    try:
        myPrh = PhysRec.PhysRecRead(fp, fp, keepGoing)
    except PhysRec.ExceptionPhysRec as err:
        print('Can not open file, error: %s' % str(err))
        return
    # Now other stuff generated by this loop
    myHeader = myPrh.strHeader() + '   LR Attr [Total LD]'
    theS.write(myHeader)
    theS.write('\n')
    theS.write(' start '.center(len(myHeader), '-'))
    myLdSum = -1
    numPR = 0
    # Histogram of PR lengths
    myLenHist = Histogram.Histogram()
    for myLd, isLdStart in myPrh.genLd():
        myLenHist.add(myPrh.prLen)
        if isLdStart:
            if myLdSum == -1:
                # First time through the loop then don't write anything
                pass
            else:
                # This is not the first time through the loop
                # so write out the trailing LogicalData length
                theS.write(' [%8d]' % myLdSum)
            myLdSum = 0
        myLdSum += len(myLd)
        theS.write('\n')
        theS.write(str(myPrh))
        if isLdStart:
            #theS.write(' >')
            #theS.write(' 0x{0:08X}'.format(myPrh.tellLr()))
            if len(myLd) >= 2:
                #print(myLd)
                h, a = LD_STRUCT_HEAD.unpack(myLd[:LD_STRUCT_HEAD.size])
                theS.write(' 0x{0:02X} 0x{1:02x}'.format(h, a))
            else:
                theS.write(' 0x??')
        else:
            theS.write(' + --   --')
        #theS.write(' %6d' % len(myLd))
        numPR += 1
    theS.write(' [%8d]' % myLdSum)
    theS.write('\n')
    theS.write('%s\n' % str(myPrh))
    theS.write(' EOF '.center(len(myHeader), '-'))
    theS.write('\n')
    theS.write('PR Count: %d\n' % numPR)
    theS.write('Histogram of Physical Record lengths:\n')
    theS.write(myLenHist.strRep(100, valTitle='Bytes', inclCount=True))
    theS.write('\n')
 def setUp(self):
     self._hist = Histogram.Histogram()