def xmlrpc_cancel(self): """ Cancel the current download and move the current NZB to Hellanzb.TEMP_DIR """ from Hellanzb.Daemon import cancelCurrent cancelCurrent() return self.xmlrpc_status()
def fetchNextNZBSegment(self): """ Pop nzb article from the queue, and attempt to retrieve it if it hasn't already been retrieved""" if self.currentSegment is None: try: priority, self.currentSegment = \ Hellanzb.queue.getSmart(self.factory) cachedArticleDataBytes = self.currentSegment.nzbFile.nzb.cachedArticleDataBytes if Hellanzb.CACHE_LIMIT < 0 or cachedArticleDataBytes < Hellanzb.CACHE_LIMIT: self.currentSegment.cachedToDisk = False self.currentSegment.encodedDataList = [] self.write = self.currentSegment.encodedDataList.append else: self.currentSegment.cachedToDisk = True self.currentSegment.encodedDataFile = \ open(os.path.join(Hellanzb.DOWNLOAD_TEMP_DIR, self.currentSegment.getTempFileName() + \ '_ENC'), 'wb') self.write = self.currentSegment.encodedDataFile.write if Hellanzb.DEBUG_MODE_ENABLED: debug(str(self) + ' PULLED FROM QUEUE: ' + \ self.currentSegment.getDestination()) # got a segment - set ourselves as active unless we're already set as so self.activate() # Determine the filename to show in the UI if self.currentSegment.nzbFile.showFilename == None: if self.currentSegment.nzbFile.filename == None: self.currentSegment.nzbFile.showFilenameIsTemp = True self.currentSegment.nzbFile.showFilename = self.currentSegment.nzbFile.getFilename() except EmptyForThisPool: debug(str(self) + ' EMPTY QUEUE (for just this pool)') # done for this download pool self.deactivate(justThisDownloadPool = True) return except Empty: debug(str(self) + ' EMPTY QUEUE') # all done self.deactivate() return if not self.factory.skipGroupCmd: # Change group for group in self.currentSegment.nzbFile.groups: # NOTE: we could get away with activating only one of the groups instead # of all if group not in self.activeGroups and group not in self.failedGroups: debug(str(self) + ' getting GROUP: ' + group) self.fetchGroup(group) return # We only need to get the groups once during the lifetime of this # NZBLeecher. Once we've ensured all groups have been attempted to be # retrieved (the above block of code), check that we haven't failed # finding all groups (if so, punt) here instead of getGroupFailed elif self.allGroupsFailed(self.currentSegment.nzbFile.groups): try: Hellanzb.queue.requeueMissing(self.factory, self.currentSegment) debug(str(self) + \ ' All groups failed, requeueing to another pool!') self.resetCurrentSegment(removeEncFile = True) reactor.callLater(0, self.fetchNextNZBSegment) except PoolsExhausted: error('(' + self.factory.serverPoolName + \ '): Unable to retrieve *any* groups for file (subject: ' + \ self.currentSegment.nzbFile.subject + \ '). If this shouldn\'t happen, enable skipGroupCmd=True in your ' 'config\'s defineServer line') msg = 'Groups:' for group in self.currentSegment.nzbFile.groups: msg += ' ' + group error(msg) error('Cancelling NZB download: ' + \ self.currentSegment.nzbFile.nzb.archiveName) # cancelCurrent will deactivate, kill the connections (and # connectionLost will take care of closing file handles etc) cancelCurrent() return # Don't call later here -- we could be disconnected and lose our currentSegment # before it even happens! #reactor.callLater(0, self.fetchBody, str(self.currentSegment.messageId)) self.fetchBody(str(self.currentSegment.messageId))
def fetchNextNZBSegment(self): """ Pop nzb article from the queue, and attempt to retrieve it if it hasn't already been retrieved""" if self.currentSegment is None: try: priority, self.currentSegment = \ Hellanzb.queue.getSmart(self.factory) cachedArticleDataBytes = self.currentSegment.nzbFile.nzb.cachedArticleDataBytes if Hellanzb.CACHE_LIMIT < 0 or cachedArticleDataBytes < Hellanzb.CACHE_LIMIT: self.currentSegment.cachedToDisk = False self.currentSegment.encodedDataList = [] self.write = self.currentSegment.encodedDataList.append else: self.currentSegment.cachedToDisk = True self.currentSegment.encodedDataFile = \ open(os.path.join(Hellanzb.DOWNLOAD_TEMP_DIR, self.currentSegment.getTempFileName() + \ '_ENC'), 'wb') self.write = self.currentSegment.encodedDataFile.write if Hellanzb.DEBUG_MODE_ENABLED: debug(str(self) + ' PULLED FROM QUEUE: ' + \ self.currentSegment.getDestination()) # got a segment - set ourselves as active unless we're already set as so self.activate() # Determine the filename to show in the UI if self.currentSegment.nzbFile.showFilename == None: if self.currentSegment.nzbFile.filename == None: self.currentSegment.nzbFile.showFilenameIsTemp = True self.currentSegment.nzbFile.showFilename = self.currentSegment.nzbFile.getFilename( ) except EmptyForThisPool: debug(str(self) + ' EMPTY QUEUE (for just this pool)') # done for this download pool self.deactivate(justThisDownloadPool=True) return except Empty: debug(str(self) + ' EMPTY QUEUE') # all done self.deactivate() return if not self.factory.skipGroupCmd: # Change group for group in self.currentSegment.nzbFile.groups: # NOTE: we could get away with activating only one of the groups instead # of all if group not in self.activeGroups and group not in self.failedGroups: debug(str(self) + ' getting GROUP: ' + group) self.fetchGroup(group) return # We only need to get the groups once during the lifetime of this # NZBLeecher. Once we've ensured all groups have been attempted to be # retrieved (the above block of code), check that we haven't failed # finding all groups (if so, punt) here instead of getGroupFailed elif self.allGroupsFailed(self.currentSegment.nzbFile.groups): try: Hellanzb.queue.requeueMissing(self.factory, self.currentSegment) debug(str(self) + \ ' All groups failed, requeueing to another pool!') self.resetCurrentSegment(removeEncFile=True) reactor.callLater(0, self.fetchNextNZBSegment) except PoolsExhausted: error('(' + self.factory.serverPoolName + \ '): Unable to retrieve *any* groups for file (subject: ' + \ self.currentSegment.nzbFile.subject + \ '). If this shouldn\'t happen, enable skipGroupCmd=True in your ' 'config\'s defineServer line') msg = 'Groups:' for group in self.currentSegment.nzbFile.groups: msg += ' ' + group error(msg) error('Cancelling NZB download: ' + \ self.currentSegment.nzbFile.nzb.archiveName) # cancelCurrent will deactivate, kill the connections (and # connectionLost will take care of closing file handles etc) cancelCurrent() return # Don't call later here -- we could be disconnected and lose our currentSegment # before it even happens! #reactor.callLater(0, self.fetchBody, str(self.currentSegment.messageId)) self.fetchBody(str(self.currentSegment.messageId))