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

def Hellanzb::PostProcessor::PostProcessor::postProcess (   self  ) 

process the specified directory 

Definition at line 422 of file PostProcessor.py.

00422                          :
        """ process the specified directory """
        # Check for shutting down flag before doing any significant work
        self.startTime = time.time()
        checkShutdown()
        
        # Put files we've processed and no longer need (like pars rars) in this dir
        processedDir = os.path.join(self.dirName, Hellanzb.PROCESSED_SUBDIR)

        if not os.path.exists(self.dirName):
            raise FatalError('Directory does not exist: ' + self.dirName)
        elif not os.path.isdir(self.dirName):
            raise FatalError('Not a directory: ' + self.dirName)
                              
        if not os.path.exists(processedDir):
            try:
                os.mkdir(processedDir)
            except OSError, ose:
                # We might have just unrared something with goofy permissions.
                
                # FIXME: hope we don't need the processed dir! this would typically only
                # happen for say a VIDEO_TS dir anyway
                warn('Unable to create processedDir: ' + processedDir + ' err: ' + str(ose))
                pass

                # FIXME: If we just unrared a directory bad perms, ideally we should fix
                # the perms
                #if ose.errno == errno.EACCES:
                #    os.chmod(processedDir, 

        elif not os.path.isdir(processedDir):
            raise FatalError('Unable to create processed dir, a non dir already exists there: ' + \
                             processedDir)
    
        # First, find broken files, in prep for repair. Grab the msg id and nzb
        # file names while we're at it
        self.brokenFiles = []
        files = os.listdir(self.dirName)
        for file in files:
            absoluteFile = os.path.join(self.dirName, file)
            if os.path.isfile(absoluteFile):
                if file.endswith('_broken'):
                    # Keep track of the broken files
                    self.brokenFiles.append(absoluteFile)
                    
                elif len(file) > 7 and file[0:len('.msgid_')] == '.msgid_':
                    self.msgId = file[len('.msgid_'):]
    
                elif len(file) > 3 and file.find('.') > -1 and getFileExtension(file).lower() == 'nzb':
                    self.nzbFile = file
    
        # If there are required broken files and we lack pars, punt
        if len(self.brokenFiles) > 0 and containsRequiredFiles(self.brokenFiles) and \
                not dirHasPars(self.dirName):
            errorMessage = 'Unable to process directory: ' + self.dirName + '\n' + \
                'This directory has the following broken files: '
            for brokenFile in self.brokenFiles:
                errorMessage += '\n' + ' '*4 + brokenFile
            errorMessage += '\nand contains no par2 files for repair'
            raise FatalError(errorMessage)

        # Find any files that need to assembled (e.g. file.avi.001, file.avi.002)
        needAssembly = findSplitFiles(self.dirName)
        
        foundPars = False
        if dirHasPars(self.dirName):
            foundPars = True
            
            checkShutdown()
            try:
                processPars(self, needAssembly)
            except ParExpectsUnsplitFiles:
                info(archiveName(self.dirName) + ': This archive requires assembly before running par2')
                assembleSplitFiles(self.dirName, needAssembly)
                try:
                    processPars(self, None)
                except NeedMorePars, nmp:
                    if self.triggerParRecovery(nmp):
                        return
            except NeedMorePars, nmp:
                if self.triggerParRecovery(nmp):
                    return

        cleanSkippedPars(self.dirName)

        if self.background and not self.isSubDir and \
                os.path.isfile(os.path.join(self.dirName, Hellanzb.PROCESSED_SUBDIR,
                                            '.par_done')):
            cleanHellanzbTmpFiles(self.dirName)
        
        # Rars may need assembly before unraring
        assembleSplitFiles(self.dirName, findSplitFiles(self.dirName))

        if not Hellanzb.SKIP_UNRAR and dirHasRars(self.dirName):
            checkShutdown()
            moveSamples(self)
            processRars(self)

        if dirHasMusic(self.dirName):
            checkShutdown()
            self.processMusic()

        # Assemble split up files (that were just unrared)
        assembleSplitFiles(self.dirName, findSplitFiles(self.dirName))

        # FIXME: do we need to gc.collect() after post processing a lot of data?

        # Post process sub directories
        trolled = 0
        for file in os.listdir(self.dirName):
            if file == Hellanzb.PROCESSED_SUBDIR:
                continue
            
            if os.path.isdir(pathjoin(self.dirName, file)):
                if not self.isSubDir:
                    troll = PostProcessor(self.archive, background = self.background,
                                          subDir = file)
                else:
                    troll = PostProcessor(self.archive, background = self.background,
                                          subDir = pathjoin(self.subDir, file))
                troll.run()
                trolled += 1

        if foundPars:
            cleanDupeFiles(self.dirName)
                
        self.finishedPostProcess()

    def triggerParRecovery(self, nmp):


Generated by  Doxygen 1.6.0   Back to index