Exemplo n.º 1
0
def listQueue(includeIds=True, convertToUnicode=True):
    """ Return a listing of the current queue. By default this function will convert all
    strings to unicode, as it's only used right now for the return of XMLRPC calls """
    members = []
    for nzb in Hellanzb.nzbQueue:
        if includeIds:
            name = archiveName(os.path.basename(nzb.nzbFileName))
            rarPassword = nzb.rarPassword

            if convertToUnicode:
                name = toUnicode(name)
                rarPassword = toUnicode(rarPassword)

            member = {
                'id': nzb.id,
                'nzbName': name,
                'is_par_recovery': nzb.isParRecovery
            }

            if rarPassword is not None:
                member['rarPassword'] = rarPassword
            if nzb.msgid is not None:
                member['msgid'] = nzb.msgid
            if not nzb.calculatingBytes:
                member['total_mb'] = nzb.totalBytes / 1024 / 1024
        else:
            member = os.path.basename(nzb.nzbFileName)
        members.append(member)
    return members
Exemplo n.º 2
0
    def xmlrpc_process(self, archiveDir, rarPassword = None):
        """ Post process the specified directory. The -p option is preferable -- it will do this
        for you, or use the current process if this XML-RPC call fails """
        # FIXME: merge this with Daemon.postProcess
        if not os.path.isdir(archiveDir):
            raise Fault(9001, 'Unable to process, not a directory: ' + toUnicode(archiveDir))

        if not os.access(archiveDir, os.R_OK) or not os.access(archiveDir, os.W_OK):
            raise Fault(9001, 'Unable to process, no read/write access to directory: ' + \
                        toUnicode(archiveDir))
        
        dirName = os.path.dirname(archiveDir.rstrip(os.sep))
        # We are the queue daemon -- Symlink to the archiveDir. If we are ctrl-ced, we'll
        # pick up the post processing afterward restart
        if os.path.normpath(dirName) != os.path.normpath(Hellanzb.PROCESSING_DIR):
            destDir = dupeName(os.path.join(Hellanzb.PROCESSING_DIR,
                               os.path.basename(archiveDir.rstrip(os.sep))))
            # UNIX: symlink, windows =[
            os.symlink(archiveDir, destDir)
            archiveDir = destDir

        archive = Archive(archiveDir, rarPassword = rarPassword)
        troll = PostProcessor(archive)
        troll.start()
        return self.xmlrpc_status()
Exemplo n.º 3
0
def listQueue(includeIds=True, convertToUnicode=True):
    """ Return a listing of the current queue. By default this function will convert all
    strings to unicode, as it's only used right now for the return of XMLRPC calls """
    members = []
    for nzb in Hellanzb.nzbQueue:
        if includeIds:
            name = archiveName(os.path.basename(nzb.nzbFileName))
            rarPassword = nzb.rarPassword

            if convertToUnicode:
                name = toUnicode(name)
                rarPassword = toUnicode(rarPassword)

            member = {"id": nzb.id, "nzbName": name, "is_par_recovery": nzb.isParRecovery}

            if rarPassword is not None:
                member["rarPassword"] = rarPassword
            if nzb.msgid is not None:
                member["msgid"] = nzb.msgid
            if not nzb.calculatingBytes:
                member["total_mb"] = nzb.totalBytes / 1024 / 1024
        else:
            member = os.path.basename(nzb.nzbFileName)
        members.append(member)
    return members
Exemplo n.º 4
0
    def xmlrpc_process(self, archiveDir, rarPassword=None):
        """ Post process the specified directory. The -p option is preferable -- it will do this
        for you, or use the current process if this XML-RPC call fails """
        # FIXME: merge this with Daemon.postProcess
        if not os.path.isdir(archiveDir):
            raise Fault(
                9001,
                'Unable to process, not a directory: ' + toUnicode(archiveDir))

        if not os.access(archiveDir, os.R_OK) or not os.access(
                archiveDir, os.W_OK):
            raise Fault(9001, 'Unable to process, no read/write access to directory: ' + \
                        toUnicode(archiveDir))

        dirName = os.path.dirname(archiveDir.rstrip(os.sep))
        # We are the queue daemon -- Symlink to the archiveDir. If we are ctrl-ced, we'll
        # pick up the post processing afterward restart
        if os.path.normpath(dirName) != os.path.normpath(
                Hellanzb.PROCESSING_DIR):
            destDir = dupeName(
                os.path.join(Hellanzb.PROCESSING_DIR,
                             os.path.basename(archiveDir.rstrip(os.sep))))
            # UNIX: symlink, windows =[
            os.symlink(archiveDir, destDir)
            archiveDir = destDir

        archive = Archive(archiveDir, rarPassword=rarPassword)
        troll = PostProcessor(archive)
        troll.start()
        return self.xmlrpc_status()
Exemplo n.º 5
0
 def makeNZBStruct(self, archive):
     """ Create a map (to be an XMLRPC struct) containing NZB meta data (nzb id, name, and
     optionally rarPassword if one exists. Convert potentially Evil(tm) strings to
     unicode """
     d = {'id': archive.id, 'nzbName': toUnicode(archive.archiveName)}
     if archive.rarPassword is not None:
         d['rarPassword'] = toUnicode(archive.rarPassword)
     if archive.msgid is not None:
         d['msgid'] = archive.msgid
     d['is_par_recovery'] = archive.isParRecovery
     if hasattr(archive, 'totalBytes') and hasattr(archive, 'calculatingBytes') and \
         not archive.calculatingBytes:
         d['total_mb'] = archive.totalBytes / 1024 / 1024
     return d
Exemplo n.º 6
0
 def makeNZBStruct(self, archive):
     """ Create a map (to be an XMLRPC struct) containing NZB meta data (nzb id, name, and
     optionally rarPassword if one exists. Convert potentially Evil(tm) strings to
     unicode """
     d = {'id': archive.id,
          'nzbName': toUnicode(archive.archiveName)}
     if archive.rarPassword is not None:
         d['rarPassword'] = toUnicode(archive.rarPassword)
     if archive.msgid is not None:
         d['msgid'] = archive.msgid
     d['is_par_recovery'] = archive.isParRecovery
     if hasattr(archive, 'totalBytes') and hasattr(archive, 'calculatingBytes') and \
         not archive.calculatingBytes:
         d['total_mb'] = archive.totalBytes / 1024 / 1024
     return d
Exemplo n.º 7
0
def sortQueueFromRecoveredState(queuedRecoveredState):
    """ Sort the queue from the order recovered from the on disk STATE_XML_FILE """
    onDiskQueue = [(archiveEntry['order'], archiveName) for archiveName, archiveEntry in \
                   queuedRecoveredState.iteritems()]
    onDiskQueue.sort()

    unsorted = Hellanzb.nzbQueue[:]
    Hellanzb.nzbQueue = []
    arranged = []
    for order, archiveName in onDiskQueue:
        for nzb in unsorted:
            if toUnicode(nzb.archiveName) == toUnicode(archiveName):
                Hellanzb.nzbQueue.append(nzb)
                arranged.append(nzb)
                break
    for nzb in arranged:
        unsorted.remove(nzb)
    for nzb in unsorted:
        Hellanzb.nzbQueue.append(nzb)
Exemplo n.º 8
0
def sortQueueFromRecoveredState(queuedRecoveredState):
    """ Sort the queue from the order recovered from the on disk STATE_XML_FILE """
    onDiskQueue = [(archiveEntry['order'], archiveName) for archiveName, archiveEntry in \
                   queuedRecoveredState.iteritems()]
    onDiskQueue.sort()
    
    unsorted = Hellanzb.nzbQueue[:]
    Hellanzb.nzbQueue = []
    arranged = []
    for order, archiveName in onDiskQueue:
        for nzb in unsorted:
            if toUnicode(nzb.archiveName) == toUnicode(archiveName):
                Hellanzb.nzbQueue.append(nzb)
                arranged.append(nzb)
                break
    for nzb in arranged:
        unsorted.remove(nzb)
    for nzb in unsorted:
        Hellanzb.nzbQueue.append(nzb)
Exemplo n.º 9
0
    def getRecoveredDict(self, type, archiveName):
        """ Attempt to recover attributes (dict) from the STATE_XML_FILE read from disk for the
        specified archiveName of the specified type (valid types: downloading, processing,
        queued) """
        typeDict = getattr(self, type)

        archiveName = toUnicode(archiveName)
        recoveredDict = None
        if archiveName in typeDict:
            recoveredDict = typeDict[archiveName]
            typeDict.pop(archiveName)  # Done with it

        return recoveredDict
Exemplo n.º 10
0
    def getRecoveredDict(self, type, archiveName):
        """ Attempt to recover attributes (dict) from the STATE_XML_FILE read from disk for the
        specified archiveName of the specified type (valid types: downloading, processing,
        queued) """
        typeDict = getattr(self, type)

        archiveName = toUnicode(archiveName)
        recoveredDict = None
        if archiveName in typeDict:
            recoveredDict = typeDict[archiveName]
            typeDict.pop(archiveName)  # Done with it

        return recoveredDict
Exemplo n.º 11
0
    def getStateAttribs(self):
        """ Return attributes to be written out to the """
        attribs = Archive.getStateAttribs(self)

        # NZBs in isParRecovery mode need the par recovery state written
        if self.isParRecovery:
            attribs["isParRecovery"] = "True"
            for attrib in ("neededBlocks", "parPrefix"):
                val = getattr(self, attrib)
                if isinstance(val, int):
                    val = str(val)
                attribs[attrib] = toUnicode(val)
            attribs["parType"] = getParName(self.parType)

        if self.downloadTime:
            attribs["downloadTime"] = str(self.downloadTime)
        if not self.calculatingBytes and self.totalBytes > 0:
            attribs["totalBytes"] = str(self.totalBytes)
        if self.category:
            attribs["category"] = self.category

        return attribs
Exemplo n.º 12
0
    def getStateAttribs(self):
        """ Return attributes to be written out to the """
        attribs = Archive.getStateAttribs(self)

        # NZBs in isParRecovery mode need the par recovery state written
        if self.isParRecovery:
            attribs['isParRecovery'] = 'True'
            for attrib in ('neededBlocks', 'parPrefix'):
                val = getattr(self, attrib)
                if isinstance(val, int):
                    val = str(val)
                attribs[attrib] = toUnicode(val)
            attribs['parType'] = getParName(self.parType)

        if self.downloadTime:
            attribs['downloadTime'] = str(self.downloadTime)
        if not self.calculatingBytes and self.totalBytes > 0:
            attribs['totalBytes'] = str(self.totalBytes)
        if self.category:
            attribs['category'] = self.category

        return attribs
Exemplo n.º 13
0
    def getStateAttribs(self):
        """ Return attributes to be written out to the """
        attribs = Archive.getStateAttribs(self)

        # NZBs in isParRecovery mode need the par recovery state written
        if self.isParRecovery:
            attribs['isParRecovery'] = 'True'
            for attrib in ('neededBlocks', 'parPrefix'):
                val = getattr(self, attrib)
                if isinstance(val, int):
                    val = str(val)
                attribs[attrib] = toUnicode(val)
            attribs['parType'] = getParName(self.parType)

        if self.downloadTime:
            attribs['downloadTime'] = str(self.downloadTime)
        if not self.calculatingBytes and self.totalBytes > 0:
            attribs['totalBytes'] = str(self.totalBytes)
        if self.category:
            attribs['category'] = self.category

        return attribs
Exemplo n.º 14
0
 def cleanLog(self, logEntry):
     """ Return a safe-for-xml version of the specified log entry string """
     return toUnicode(logEntry.replace('\x08', ''))
Exemplo n.º 15
0
    p.addNotification("Archive Error", enabled=True)
    p.addNotification("Archive Success", enabled=True)
    p.addNotification("Error", enabled=True)
    p.addNotification("Queue", enabled=True)
    try:
        s.sendto(p.payload(), addr)
    except socket_error, msg:
        s.close()
        debug('Unable to connect to Growl: ' + str(msg))
        return

    # Unicode the message, so the python Growl lib can succesfully UTF-8 it. It can fail
    # to UTF-8 the description if it contains unusual characters. we also have to force
    # latin-1, otherwise converting to unicode can fail too
    # (e.g. 'São_Paulo')
    description = toUnicode(description)

    p = GrowlNotificationPacket(application="hellanzb",
                                notification=type,
                                title=title,
                                description=description,
                                priority=1,
                                sticky=sticky,
                                password=Hellanzb.GROWL_PASSWORD)
    try:
        s.sendto(p.payload(), addr)
    except socket_error, msg:
        debug('Unable to connect to Growl: ' + str(msg))

    s.close()
Exemplo n.º 16
0
 def isSkippedParSubject(self, subject):
     """ Determine whether the specified subject is that of a known skipped par file """
     if self.skippedParSubjects is None:
         return False
     return toUnicode(subject) in self.skippedParSubjects
Exemplo n.º 17
0
 def isSkippedParSubject(self, subject):
     """ Determine whether the specified subject is that of a known skipped par file """
     if self.skippedParSubjects is None:
         return False
     return toUnicode(subject) in self.skippedParSubjects
Exemplo n.º 18
0
 def cleanLog(self, logEntry):
     """ Return a safe-for-xml version of the specified log entry string """
     return toUnicode(logEntry.replace('\x08', ''))
Exemplo n.º 19
0
    p.addNotification("Archive Error", enabled=True)
    p.addNotification("Archive Success", enabled=True)
    p.addNotification("Error", enabled=True)
    p.addNotification("Queue", enabled=True)
    try:
        s.sendto(p.payload(), addr)
    except socket_error, msg:
        s.close()
        debug('Unable to connect to Growl: ' + str(msg))
        return

    # Unicode the message, so the python Growl lib can succesfully UTF-8 it. It can fail
    # to UTF-8 the description if it contains unusual characters. we also have to force
    # latin-1, otherwise converting to unicode can fail too
    # (e.g. 'São_Paulo')
    description = toUnicode(description)
    
    p = GrowlNotificationPacket(application="hellanzb",
                                notification=type, title=title,
                                description=description, priority=1,
                                sticky=sticky, password=Hellanzb.GROWL_PASSWORD)
    try:
        s.sendto(p.payload(),addr)
    except socket_error, msg:
        debug('Unable to connect to Growl: ' + str(msg))

    s.close()
    
def _scrollBegin():
    """ Let the logger know we're beginning to scroll """
    ScrollableHandler.scrollFlag = True