Logo Search packages:      
Sourcecode: hellanzb version File versions  Download package

def Hellanzb::PostProcessorUtil::par2 (   postProcessor,
  parFiles,
  wildcard,
  needAssembly = None 
)

Verify (and repair) the integrity of the files in the specified directory via par2. If
files need repair and there are not enough recovery blocks, raise a fatal exception 

Definition at line 762 of file PostProcessorUtil.py.

00762                                                                 :
    """ Verify (and repair) the integrity of the files in the specified directory via par2. If
    files need repair and there are not enough recovery blocks, raise a fatal exception """
    dirName = postProcessor.dirName
    info(archiveName(dirName) + ': Verifying via par group: ' + wildcard + '..')
    if needAssembly == None:
        needAssembly = {}
        
    repairCmd = Hellanzb.PAR2_CMD + ' r --'
    for parFile in parFiles:
        repairCmd += ' "%s" "*._hellanzb_dupe.*"' % (pathjoin(dirName, parFile))
        
    t = Topen(repairCmd, postProcessor)
    output, returnCode = t.readlinesAndWait()

    if returnCode == 0:
        # FIXME: checkout for 'repaired blah' messages.
        # for line in output:
        #     if line.find(''):
        #         parRepaired = True
        #
        # if parRepaired:
        #     info(archiveName(dirName) + ': Par repair successfully completed')
        # else:
        
        # Verified
        return

    elif returnCode == 2:
        # Repair required and impossible

        # First, if the repair is not possible, double check the output for what files are
        # missing or damaged (a missing file is considered as damaged in this case). they
        # may be unimportant
        damagedAndRequired, missingFiles, targetsFound, neededBlocks, parType = \
            parseParNeedsBlocksOutput(archiveName(dirName), output)
        needType = getParRecoveryName(parType)

        for file in missingFiles:
            if needAssembly.has_key(file):
                # Found a file we need to assemble for Par2. Throw us back out to handle
                # that work, we'll run par2 again later
                raise ParExpectsUnsplitFiles('')

        if postProcessor.hasMorePars:
            # Damaged data, more par data is needed that hasn't been downloaded yet
            warn(archiveName(dirName) + ': Failed par verify, requires ' + neededBlocks + \
                 ' more recovery ' + getParRecoveryName(parType))

            parPrefix = None
            if parType == PAR1:
                # Remove '.*' from the wildcard of pattern: Data.part01.*
                parPrefix = wildcard[:-2]
            elif parType == PAR2:
                # Remove '*.{par2,PAR2}' from the wildcard of pattern: dataGroupA*.{par2,PAR2}
                parPrefix = wildcard[:-13]

            raise NeedMorePars(neededBlocks, parType, parPrefix)

        # par did not find any valid 'Target:' files, and more blocks are needed. This is
        # probably a bad archive
        if targetsFound == 0 and neededBlocks > 0:
            raise FatalError('Unable to par repair: archive requires ' + neededBlocks + \
                             ' more recovery ' + needType + \
                             ' for repair. No valid files found (bad archive?)')

        # The archive is only totally broken when we're missing required files
        if len(damagedAndRequired) > 0:
            growlNotify('Error', 'hellanzb Cannot par repair:', archiveName(dirName) + \
                        '\nNeed ' + neededBlocks + ' more recovery ' + needType, True)
            raise FatalError('Unable to par repair: archive requires ' + neededBlocks + \
                             ' more recovery ' + needType + ' for repair')

    else:
        # Abnormal behavior -- let the user deal with it
        raise FatalError('par2 repair failed: returned code: ' + str(returnCode) + \
                         '. Please run par2 manually for more information, par2 cmd: ' + \
                         repairCmd)

RAR_NOT_FOUND_RE = re.compile(r'.*File:\ "(.*)"\ -\ no\ data\ found\..*')


Generated by  Doxygen 1.6.0   Back to index