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

def Hellanzb::NZBLeecher::DupeHandler::handleDupeOnDisk (   filename,
  workingDirDupeMap 
)

Determine if the specified filename on disk (in the WORKING_DIR) is a duplicate
file. Simply returns False if that's not the case, otherwise it returns True and takes
account of the dupe

Duplicate file information is stored in the workingDirDupeMap, in the format (Given
the following duplicate files on disk):

file.rar
file.rar.hellanzb_dupe0
file.rar.hellanzb_dupe2

Would produce:

workingDirDupeMap = { 'file.rar': [
                                   [0, None],
                                   [1, None],
                                   [2, None],
                                   [-1, None]
                                  ]
                    }


This represents a mapping of the original file (file.rar) to a list containing each
duplicate file's number and its associated NZBFile object. At this point (just prior
to parsing of the NZB) the NZBFile object associated with the dupe is not known, so
this function leaves it as None. This will be filled in later by
handleDupeNZBFileNeedsDownload (called from NZBFile.needsDownload)

The duplicate with index -1 is special -- it represents the origin: 'file.rar'. This
ordering correlates to how these duplicates were originally written to disk, and the
order they'll be encountered in the NZB (hence the origin appearing last)

This represents the full RANGE of files that SHOULD be on disk (that we currently know
about). The file 'file.rar.hellanzb_dupe1' is missing from disk, but given the fact
that 'file.rar.hellanzb_dupe2' exists means it WILL be there at some point

Encountering a file listing like this (missing the dupe_1) is going to be a rare
occurence but it could happen under the right situations. The point is to avoid even
these rare situations as they could lead to inconsistent state of the NZB archive (and
ultimately ugly hellanzb lockups) 

Definition at line 103 of file DupeHandler.py.

00103                                                  :
    """ Determine if the specified filename on disk (in the WORKING_DIR) is a duplicate
    file. Simply returns False if that's not the case, otherwise it returns True and takes
    account of the dupe

    Duplicate file information is stored in the workingDirDupeMap, in the format (Given
    the following duplicate files on disk):

    file.rar
    file.rar.hellanzb_dupe0
    file.rar.hellanzb_dupe2

    Would produce:
    
    workingDirDupeMap = { 'file.rar': [
                                       [0, None],
                                       [1, None],
                                       [2, None],
                                       [-1, None]
                                      ]
                        }


    This represents a mapping of the original file (file.rar) to a list containing each
    duplicate file's number and its associated NZBFile object. At this point (just prior
    to parsing of the NZB) the NZBFile object associated with the dupe is not known, so
    this function leaves it as None. This will be filled in later by
    handleDupeNZBFileNeedsDownload (called from NZBFile.needsDownload)

    The duplicate with index -1 is special -- it represents the origin: 'file.rar'. This
    ordering correlates to how these duplicates were originally written to disk, and the
    order they'll be encountered in the NZB (hence the origin appearing last)

    This represents the full RANGE of files that SHOULD be on disk (that we currently know
    about). The file 'file.rar.hellanzb_dupe1' is missing from disk, but given the fact
    that 'file.rar.hellanzb_dupe2' exists means it WILL be there at some point

    Encountering a file listing like this (missing the dupe_1) is going to be a rare
    occurence but it could happen under the right situations. The point is to avoid even
    these rare situations as they could lead to inconsistent state of the NZB archive (and
    ultimately ugly hellanzb lockups) """
    match = DUPE_SUFFIX_RE.match(filename)
    if not match:
        # Not a dupe
        return False
    
    else:
        # A dupe, ending in the _hellanzb_dupeX suffix
        strippedFilename = match.group(1) # _hellanzb_dupeX suffix removed
        dupeNum = int(match.group(2)) # the X in _hellanzb_dupeX

        newDupeMapping = False
        if not workingDirDupeMap.has_key(strippedFilename):
            newDupeMapping = True
            # A brand new dupe not yet in the map. There must always be an associated file
            # without the _hellanzb_dupeX suffix (branded as index -1)
            
            # This will be a list of (lists with indicies):
            # [0] The dupe number (X of hellanzb_dupeX)
            # [1] The associated dupe's NZBFile (or None if not yet found)
            workingDirDupeMap[strippedFilename] = [[-1, None]]

        dupesForFile = workingDirDupeMap[strippedFilename]
        
        if not newDupeMapping:
            # There are previous entries in our mapping (besides -1). Ensure any missing
            # indicies are filled in
            prevDupeEntry = dupesForFile[-2]
            
            if prevDupeEntry[0] != dupeNum - 1:
                # The last entry is not (current - 1), there are missing indicies
                missingIndex = prevDupeEntry[0]
                while missingIndex < dupeNum - 1:
                    missingIndex += 1
                    dupesForFile.insert(-1, [missingIndex, None])
                
        # Finally add the entry we're dealing with -- the dupe represented by the passed
        # in filename
        dupesForFile.insert(-1, [dupeNum, None])
        
        return True

def handleDupeNZBFileNeedsDownload(nzbFile, workingDirDupeMap):


Generated by  Doxygen 1.6.0   Back to index