예제 #1
0
    def stop(self, download):
        self.log("stopping transfer %s (%s) ..." %
                 (str(self.name), str(self.tf.transferowner)))

        # stat
        self.statShutdown(download)

        # stop transfer
        retVal = True
        try:
            download.stop()
            retVal = True
        except:
            self.log("exception when stopping transfer :")
            printException()
            retVal = False

        # delete pid
        self.deletePid()

        # log
        self.log("transfer stopped.")

        # states
        self.state = Transfer.TF_STOPPED
        self.state_azu = Transfer.AZ_STOPPED

        # return
        return retVal
예제 #2
0
    def start(self, download):
        self.log("starting transfer %s (%s) ..." %
                 (str(self.name), str(self.tf.transferowner)))

        # stat
        self.statStartup(download)

        # write pid
        self.writePid()

        # start transfer
        try:
            download.restart()
        except:
            self.log("exception when starting transfer :")
            printException()

        # refresh
        download.refresh_object()

        # set state
        self.state = Transfer.STATE_MAP[download.getState()]

        # set rates
        self.setRateU(download, int(self.tf.max_upload_rate))
        self.setRateD(download, int(self.tf.max_download_rate))

        # log
        self.log("transfer started.")

        # return
        return True
예제 #3
0
    def start(self, download):
        self.log("starting transfer %s (%s) ..." % (str(self.name), str(self.tf.transferowner)))

        # stat
        self.statStartup(download)

        # write pid
        self.writePid()

        # start transfer
        try:
            download.restart()
        except:
            self.log("exception when starting transfer :")
            printException()

        # refresh
        download.refresh_object()

        # set state
        self.state = Transfer.STATE_MAP[download.getState()]

        # set rates
        self.setRateU(download, int(self.tf.max_upload_rate))
        self.setRateD(download, int(self.tf.max_download_rate))

        # log
        self.log("transfer started.")

        # return
        return True
예제 #4
0
    def stop(self, download):
        self.log("stopping transfer %s (%s) ..." % (str(self.name), str(self.tf.transferowner)))

        # stat
        self.statShutdown(download)

        # stop transfer
        retVal = True
        try:
            download.stop()
            retVal = True
        except:
            self.log("exception when stopping transfer :")
            printException()
            retVal = False

        # delete pid
        self.deletePid()

        # log
        self.log("transfer stopped.")

        # states
        self.state = Transfer.TF_STOPPED
        self.state_azu = Transfer.AZ_STOPPED

        # return
        return retVal
예제 #5
0
 def statStartup(self, download):
     # set some values
     self.sf.running = Transfer.TF_RUNNING
     self.sf.percent_done = 0
     self.sf.time_left = "Starting..."
     self.sf.down_speed = "0.00 kB/s"
     self.sf.up_speed = "0.00 kB/s"
     self.sf.transferowner = self.tf.transferowner
     self.sf.seeds = ""
     self.sf.peers = ""
     self.sf.sharing = ""
     self.sf.seedlimit = ""
     self.sf.uptotal = 0
     self.sf.downtotal = 0
     try:
         # get size
         try:
             size = str(download.getTorrent().getSize())
             self.sf.size = size
         except:
             printException()
         # write
         return self.sf.write()
     except:
         printException()
         return False
예제 #6
0
 def statStartup(self, download):
     # set some values
     self.sf.running = Transfer.TF_RUNNING
     self.sf.percent_done = 0
     self.sf.time_left = "Starting..."
     self.sf.down_speed = "0.00 kB/s"
     self.sf.up_speed = "0.00 kB/s"
     self.sf.transferowner = self.tf.transferowner
     self.sf.seeds = ""
     self.sf.peers = ""
     self.sf.sharing = ""
     self.sf.seedlimit = ""
     self.sf.uptotal = 0
     self.sf.downtotal = 0
     try:
         # get size
         try:
             size = str(download.getTorrent().getSize())
             self.sf.size = size
         except:
             printException()
         # write
         return self.sf.write()
     except:
         printException()
         return False
예제 #7
0
    def checkAzuConnection(self):

        # con valid
        try:
            if self.connection.is_connection_valid():
                return True
            else:
                raise

        # con not valid
        except:

            # out
            printMessage(
                "connection to Azureus-server lost, reconnecting to %s:%d ..." % (self.azu_host, self.azu_port)
            )

            # try to reconnect
            for i in range(FluAzuD.MAX_RECONNECT_TRIES):

                # sleep
                time.sleep(i << 2)

                # out
                printMessage("reconnect-try %d ..." % (i + 1))

                # establish con
                try:
                    self.connection.establish_connection(True)
                    printMessage("established connection to Azureus-server")
                except:
                    printError("Error establishing connection to Azureus-server")
                    printException()
                    continue

                # interface
                try:
                    self.interface = self.connection.get_plugin_interface()
                except LinkError, error:
                    printError("Error getting interface object")
                    printException()
                    self.interface = None
                    continue

                # download-manager
                try:
                    self.dm = None
                    self.dm = self.interface.getDownloadManager()
                    if self.dm is None:
                        raise
                    else:
                        return True
                except:
                    printError("Error getting Download-Manager object")
                    continue

            # seems like azu is down. give up
            printError("no connection after %d tries, i give up, azu is gone" % FluAzuD.MAX_RECONNECT_TRIES)
            return False
예제 #8
0
 def setRateU(self, download, rate):
     try:
         download.setUploadRateLimitBytesPerSecond((int(rate) << 10))
         return True
     except:
         printMessage("Failed to set upload-rate.")
         printException()
         return False
예제 #9
0
 def setRateU(self, download, rate):
     try:
         download.setUploadRateLimitBytesPerSecond((int(rate) << 10))
         return True
     except:
         printMessage("Failed to set upload-rate.")
         printException()
         return False
예제 #10
0
 def setRateD(self, download, rate):
     try:
         download.setMaximumDownloadKBPerSecond(int(rate))
         return True
     except:
         printMessage("Failed to set download-rate.")
         printException()
         return False
예제 #11
0
 def setRateD(self, download, rate):
     try:
         download.setMaximumDownloadKBPerSecond(int(rate))
         return True
     except:
         printMessage("Failed to set download-rate.")
         printException()
         return False
예제 #12
0
 def setRateD(self, rate):
     try:
         config_object = self.interface.getPluginconfig()
         config_object.set_download_speed_limit(rate)
         return True
     except:
         printMessage("Failed to set download-rate.")
         printException()
         return False
예제 #13
0
 def removeTransfer(self, tname):
     printMessage("removing transfer %s ..." % tname)
     try:
         self.downloads[tname].remove()
         return True
     except:
         printMessage("exception when removing transfer:")
         printException()
         return False
예제 #14
0
파일: FluAzuD.py 프로젝트: safvan010/123
 def setRateU(self, rate):
     try:
         config_object = self.interface.getPluginconfig()
         config_object.set_upload_speed_limit(rate)
         return True
     except:
         printMessage("Failed to set upload-rate.")
         printException()
         return False
예제 #15
0
파일: FluAzuD.py 프로젝트: safvan010/123
 def removeTransfer(self, tname):
     printMessage("removing transfer %s ..." % tname)
     try:
         self.downloads[tname].remove()
         return True
     except:
         printMessage("exception when removing transfer:")
         printException()
         return False
예제 #16
0
파일: FluAzuD.py 프로젝트: safvan010/123
    def writeStatFile(self):
        try:

            # get plugin-config
            try:
                config_object = self.interface.getPluginconfig()
                config_ok = 1
            except:
                printMessage(
                    "getPluginconfig: Ignoring Incompatible Plugin Config :")
                printException()
                config_ok = 0
                #return True

            if config_ok == 1:
                # get vars
                coreVars = [ \
                    config_object.CORE_PARAM_INT_MAX_ACTIVE, \
                    config_object.CORE_PARAM_INT_MAX_ACTIVE_SEEDING, \
                    config_object.CORE_PARAM_INT_MAX_CONNECTIONS_GLOBAL, \
                    config_object.CORE_PARAM_INT_MAX_CONNECTIONS_PER_TORRENT, \
                    config_object.CORE_PARAM_INT_MAX_DOWNLOAD_SPEED_KBYTES_PER_SEC, \
                    config_object.CORE_PARAM_INT_MAX_DOWNLOADS, \
                    config_object.CORE_PARAM_INT_MAX_UPLOAD_SPEED_KBYTES_PER_SEC, \
                    config_object.CORE_PARAM_INT_MAX_UPLOAD_SPEED_SEEDING_KBYTES_PER_SEC, \
                    config_object.CORE_PARAM_INT_MAX_UPLOADS, \
                    config_object.CORE_PARAM_INT_MAX_UPLOADS_SEEDING \
                ]
                coreParams = {}
                for coreVar in coreVars:
                    try:
                        coreParams[coreVar] = config_object.getIntParameter(
                            coreVar, 0)
                        printError("writeStatFile2: %s %s" %
                                   (coreVar, coreParams[coreVar]))
                    except:
                        printException()
                        coreParams[coreVar] = 0
                        continue

            # write file
            try:
                f = open(self.flu_fileStat, 'w')
                f.write("%s\n" % self.azu_host)
                f.write("%d\n" % self.azu_port)
                f.write("%s\n" % self.azu_version_str)
                if config_ok == 1:
                    for coreVar in coreVars:
                        f.write("%d\n" % coreParams[coreVar])
                f.flush()
                f.close()
                return True
            except:
                printError("Failed to write statfile %s " % self.flu_fileStat)
                printException()

        except:
            printMessage("Failed to get Plugin-Config.")
            printException()
        return False
예제 #17
0
    def writeStatFile(self):
        try:

            # get plugin-config
            try:
                config_object = self.interface.getPluginconfig()
                config_ok = 1
            except:
                printMessage("getPluginconfig: Ignoring Incompatible Plugin Config :")
                printException()
                config_ok = 0
                #return True
            
            if config_ok == 1:
                # get vars
                coreVars = [ \
                    config_object.CORE_PARAM_INT_MAX_ACTIVE, \
                    config_object.CORE_PARAM_INT_MAX_ACTIVE_SEEDING, \
                    config_object.CORE_PARAM_INT_MAX_CONNECTIONS_GLOBAL, \
                    config_object.CORE_PARAM_INT_MAX_CONNECTIONS_PER_TORRENT, \
                    config_object.CORE_PARAM_INT_MAX_DOWNLOAD_SPEED_KBYTES_PER_SEC, \
                    config_object.CORE_PARAM_INT_MAX_DOWNLOADS, \
                    config_object.CORE_PARAM_INT_MAX_UPLOAD_SPEED_KBYTES_PER_SEC, \
                    config_object.CORE_PARAM_INT_MAX_UPLOAD_SPEED_SEEDING_KBYTES_PER_SEC, \
                    config_object.CORE_PARAM_INT_MAX_UPLOADS, \
                    config_object.CORE_PARAM_INT_MAX_UPLOADS_SEEDING \
                ]
                coreParams = {}
                for coreVar in coreVars:
                    try:
                        coreParams[coreVar] = config_object.getIntParameter(coreVar, 0)
                        printError("writeStatFile2: %s %s" % (coreVar, coreParams[coreVar]))
                    except:
                        printException()
                        coreParams[coreVar] = 0
                        continue
                
            # write file
            try:
                f = open(self.flu_fileStat, 'w')
                f.write("%s\n" % self.azu_host)
                f.write("%d\n" % self.azu_port)
                f.write("%s\n" % self.azu_version_str)
                if config_ok == 1:                
                    for coreVar in coreVars:
                        f.write("%d\n" % coreParams[coreVar])
                f.flush()
                f.close()
                return True
            except:
                printError("Failed to write statfile %s " % self.flu_fileStat)
                printException()

        except:
            printMessage("Failed to get Plugin-Config.")
            printException()
        return False
예제 #18
0
파일: Transfer.py 프로젝트: safvan010/123
    def start(self, download):

        bRes = True

        self.log("starting transfer %s (%s) ..." %
                 (str(self.name), str(self.tf.transferowner)))

        # stat
        self.statStartup(download)

        # write pid
        self.writePid()

        # start transfer
        try:
            download.startDownload(True)
            # download.restart()
        except:
            self.log("exception when (re)starting transfer :")
            printException()
            bRes = False

        # refresh
        download.refresh_object()

        # azu-state
        self.state_azu = download.getState()

        # set state
        self.state = Transfer.STATE_MAP[self.state_azu]

        # set rates
        self.setRateU(download, int(self.tf.max_upload_rate))
        self.setRateD(download, int(self.tf.max_download_rate))

        # log
        if self.state != Transfer.TF_STOPPED:
            self.log("transfer started.")

        # self.log("start() state= %d" % download.getState())

        # return
        return bRes
예제 #19
0
    def start(self, download):

        bRes = True

        self.log("starting transfer %s (%s) ..." % (str(self.name), str(self.tf.transferowner)))

        # stat
        self.statStartup(download)

        # write pid
        self.writePid()

        # start transfer
        try:
            download.startDownload(True)
            # download.restart()
        except:
            self.log("exception when (re)starting transfer :")
            printException()
            bRes = False

        # refresh
        download.refresh_object()

        # azu-state
        self.state_azu = download.getState()

        # set state
        self.state = Transfer.STATE_MAP[self.state_azu]

        # set rates
        self.setRateU(download, int(self.tf.max_upload_rate))
        self.setRateD(download, int(self.tf.max_download_rate))

        # log
        if self.state != Transfer.TF_STOPPED:
            self.log("transfer started.")

        # self.log("start() state= %d" % download.getState())

        # return
        return bRes
예제 #20
0
    def addTransfer(self, tname):
        printMessage("adding new transfer %s ..." % tname)
        try:
            # transfer-object
            transfer = Transfer(self.tf_pathTransfers, self.flu_pathTransfers, tname)

            # torrent-object
            torrent = self.interface.getTorrentManager().createFromBEncodedFile(transfer.fileTorrent)

            # file-objects
            fileSource = dopal.aztypes.wrap_file(transfer.fileTorrent)
            fileTarget = dopal.aztypes.wrap_file(transfer.tf.savepath)

            # add
            self.dm.addDownload(torrent, fileSource, fileTarget)

            # return
            return True
        except:
            printMessage("exception when adding transfer:")
            printException()
            return False
예제 #21
0
    def changeSetting(self, key, val):
        try:

            # get plugin-config
            config_object = self.interface.getPluginconfig()

            # core-keys
            coreKeys = {
                "CORE_PARAM_INT_MAX_ACTIVE": config_object.CORE_PARAM_INT_MAX_ACTIVE,
                "CORE_PARAM_INT_MAX_ACTIVE_SEEDING": config_object.CORE_PARAM_INT_MAX_ACTIVE_SEEDING,
                "CORE_PARAM_INT_MAX_CONNECTIONS_GLOBAL": config_object.CORE_PARAM_INT_MAX_CONNECTIONS_GLOBAL,
                "CORE_PARAM_INT_MAX_CONNECTIONS_PER_TORRENT": config_object.CORE_PARAM_INT_MAX_CONNECTIONS_PER_TORRENT,
                "CORE_PARAM_INT_MAX_DOWNLOAD_SPEED_KBYTES_PER_SEC": config_object.CORE_PARAM_INT_MAX_DOWNLOAD_SPEED_KBYTES_PER_SEC,
                "CORE_PARAM_INT_MAX_DOWNLOADS": config_object.CORE_PARAM_INT_MAX_DOWNLOADS,
                "CORE_PARAM_INT_MAX_UPLOAD_SPEED_KBYTES_PER_SEC": config_object.CORE_PARAM_INT_MAX_UPLOAD_SPEED_KBYTES_PER_SEC,
                "CORE_PARAM_INT_MAX_UPLOAD_SPEED_SEEDING_KBYTES_PER_SEC": config_object.CORE_PARAM_INT_MAX_UPLOAD_SPEED_SEEDING_KBYTES_PER_SEC,
                "CORE_PARAM_INT_MAX_UPLOADS": config_object.CORE_PARAM_INT_MAX_UPLOADS,
                "CORE_PARAM_INT_MAX_UPLOADS_SEEDING": config_object.CORE_PARAM_INT_MAX_UPLOADS_SEEDING,
            }
            if key not in coreKeys:
                printMessage("settings-key unknown: %s" % key)
                return False

            # change setting
            try:
                config_object.setIntParameter(coreKeys[key], int(val))
                return True
            except:
                printMessage("Failed to change setting %s to %s" % (key, val))
                printException()
                return False

        except:
            printMessage("Failed to get Plugin-Config.")
            printException()
        return False
예제 #22
0
파일: FluAzuD.py 프로젝트: safvan010/123
    def addTransfer(self, tname):
        printMessage("adding new transfer %s ..." % tname)
        try:
            # transfer-object
            transfer = Transfer(self.tf_pathTransfers, self.flu_pathTransfers,
                                tname)

            # torrent-object
            torrent = self.interface.getTorrentManager(
            ).createFromBEncodedFile(transfer.fileTorrent)

            # file-objects
            fileSource = dopal.aztypes.wrap_file(transfer.fileTorrent)
            fileTarget = dopal.aztypes.wrap_file(transfer.tf.savepath)

            # add
            self.dm.addDownload(torrent, fileSource, fileTarget)

            # return
            return torrent
        except:
            printMessage("exception when adding transfer:")
            printException()
            return False
예제 #23
0
파일: FluAzuD.py 프로젝트: safvan010/123
    def changeSetting(self, key, val):
        try:

            # get plugin-config
            config_object = self.interface.getPluginconfig()

            # core-keys
            coreKeys = { \
                'CORE_PARAM_INT_MAX_ACTIVE': config_object.CORE_PARAM_INT_MAX_ACTIVE, \
                'CORE_PARAM_INT_MAX_ACTIVE_SEEDING': config_object.CORE_PARAM_INT_MAX_ACTIVE_SEEDING, \
                'CORE_PARAM_INT_MAX_CONNECTIONS_GLOBAL': config_object.CORE_PARAM_INT_MAX_CONNECTIONS_GLOBAL, \
                'CORE_PARAM_INT_MAX_CONNECTIONS_PER_TORRENT': config_object.CORE_PARAM_INT_MAX_CONNECTIONS_PER_TORRENT, \
                'CORE_PARAM_INT_MAX_DOWNLOAD_SPEED_KBYTES_PER_SEC': config_object.CORE_PARAM_INT_MAX_DOWNLOAD_SPEED_KBYTES_PER_SEC, \
                'CORE_PARAM_INT_MAX_DOWNLOADS': config_object.CORE_PARAM_INT_MAX_DOWNLOADS, \
                'CORE_PARAM_INT_MAX_UPLOAD_SPEED_KBYTES_PER_SEC': config_object.CORE_PARAM_INT_MAX_UPLOAD_SPEED_KBYTES_PER_SEC, \
                'CORE_PARAM_INT_MAX_UPLOAD_SPEED_SEEDING_KBYTES_PER_SEC': config_object.CORE_PARAM_INT_MAX_UPLOAD_SPEED_SEEDING_KBYTES_PER_SEC, \
                'CORE_PARAM_INT_MAX_UPLOADS': config_object.CORE_PARAM_INT_MAX_UPLOADS, \
                'CORE_PARAM_INT_MAX_UPLOADS_SEEDING': config_object.CORE_PARAM_INT_MAX_UPLOADS_SEEDING \
            }
            if key not in coreKeys:
                printMessage("settings-key unknown: %s" % key)
                return False

            # change setting
            try:
                config_object.setIntParameter(coreKeys[key], int(val))
                return True
            except:
                printMessage("Failed to change setting %s to %s" % (key, val))
                printException()
                return False

        except:
            printMessage("Failed to get Plugin-Config.")
            printException()
        return False
예제 #24
0
    def writeStatFile(self):
        try:

            # get plugin-config
            config_object = self.interface.getPluginconfig()

            # get vars
            coreVars = [
                config_object.CORE_PARAM_INT_MAX_ACTIVE,
                config_object.CORE_PARAM_INT_MAX_ACTIVE_SEEDING,
                config_object.CORE_PARAM_INT_MAX_CONNECTIONS_GLOBAL,
                config_object.CORE_PARAM_INT_MAX_CONNECTIONS_PER_TORRENT,
                config_object.CORE_PARAM_INT_MAX_DOWNLOAD_SPEED_KBYTES_PER_SEC,
                config_object.CORE_PARAM_INT_MAX_DOWNLOADS,
                config_object.CORE_PARAM_INT_MAX_UPLOAD_SPEED_KBYTES_PER_SEC,
                config_object.CORE_PARAM_INT_MAX_UPLOAD_SPEED_SEEDING_KBYTES_PER_SEC,
                config_object.CORE_PARAM_INT_MAX_UPLOADS,
                config_object.CORE_PARAM_INT_MAX_UPLOADS_SEEDING,
            ]
            coreParams = {}
            for coreVar in coreVars:
                try:
                    coreParams[coreVar] = config_object.getIntParameter(coreVar, 0)
                except:
                    coreParams[coreVar] = 0
                    printException()

            # write file
            try:
                f = open(self.flu_fileStat, "w")
                f.write("%s\n" % self.azu_host)
                f.write("%d\n" % self.azu_port)
                f.write("%s\n" % self.azu_version_str)
                for coreVar in coreVars:
                    f.write("%d\n" % coreParams[coreVar])
                f.flush()
                f.close()
                return True
            except:
                printError("Failed to write statfile %s " % self.flu_fileStat)
                printException()

        except:
            printMessage("Failed to get Plugin-Config.")
            printException()
        return False
예제 #25
0
    def loadCurrentNotInVuze(self):

        printMessage("loading missing transfers... %s" % self.flu_pathTransfers)

        needReload = 0
        requests = []
        try:
            vuzePathExists = os.path.isdir(self.azu_pathTransfers);
            for fileName in os.listdir(self.flu_pathTransfers):
                if os.path.isfile(self.tf_pathTransfers + fileName):                	
                    if vuzePathExists and not os.path.isfile(self.azu_pathTransfers + fileName):
                        # add to vuze (but dont start)
                        #printMessage("adding missing transfer... %s" % fileName)
                        #requests.append(fileName)
                        try:
                          os.remove(self.flu_pathTransfers + fileName + ".cmd")
                        except:
                          printMessage("ignoring existing cmd file... %s" % fileName)
                        needReload = 1
                else:
                    if os.path.isfile(self.tf_pathTransfers + fileName + ".pid"):
                        try:
                            printMessage("cleaning transfer pid... %s" % fileName)
                            os.remove(self.tf_pathTransfers + fileName + ".pid")
                        except:
                            printError("exception when cleaning old transfer %s" % fileName+ ".pid")
                            continue
        except:
            return False

        # process requests
        if len(requests) > 0:
            try:
                # update downloads
                #self.downloads = {}
                #self.updateDownloads()
                for fileName in requests:
                    # add if needed
                    if fileName not in self.downloads:
                        try:
                            # add
                            torrent = self.addTransfer(fileName)
                        except:
                            printError("exception when adding new transfer %s" % fileName)
                            raise
                    
                        # downloads
                        tries = 0
                        while torrent and (tries < 10) and fileName not in self.downloads:                       
                            download = self.dm.getDownload(torrent)
                            if (torrent and download):
                                self.downloads[fileName] = download
                                self.needUpdate=1
                                break
                            else:
                                printMessage("download %s missing, update downloads..." % torrent)
                            
                            # sleep + increment
                            time.sleep(0.5)
                            tries += 1
                        
                        # start transfer
                        if fileName in self.downloads:
                            try:
                                transfer = Transfer(self.tf_pathTransfers, self.flu_pathTransfers, fileName)
                                #transfer.start(self.downloads[fileName])
                            except:
                                printError("exception when starting new transfer %s" % fileName)
                                raise
                        else:
                            printError("download %s not in azureus-downloads, cannot start it." % fileName)
            except:
                printMessage("exception when processing run-requests:")
                printException()

        if needReload == 1:
            self.reload()

        # return
        return True
예제 #26
0
    def initialize(self):

        # flu

        # check dirs
        if not self.checkDirs():
            printError("Error checking dirs. path: %s" % self.tf_path)
            return False

        # write pid-file
        self.pid = (str(os.getpid())).strip()
        printMessage("writing pid-file %s (%s)" % (self.flu_filePid, self.pid))
        try:
            pidFile = open(self.flu_filePid, "w")
            pidFile.write(self.pid + "\n")
            pidFile.flush()
            pidFile.close()
        except:
            printError("Failed to write pid-file %s (%s)" % (self.flu_filePid, self.pid))
            return False

        # delete command-file if exists
        if os.path.isfile(self.flu_fileCommand):
            try:
                printMessage("removing command-file %s ..." % self.flu_fileCommand)
                os.remove(self.flu_fileCommand)
            except:
                printError("Failed to delete commandfile %s" % self.flu_fileCommand)
                return False

        # load transfers
        self.loadTransfers()

        # azu
        printMessage("connecting to Azureus-Server (%s:%d)..." % (self.azu_host, self.azu_port))

        # set connection details
        connection_details = {}
        connection_details["host"] = self.azu_host
        connection_details["port"] = self.azu_port
        connection_details["secure"] = self.azu_secure
        if len(self.azu_user) > 0:
            connection_details["user"] = self.azu_user
            connection_details["password"] = self.azu_pass

        # make connection
        try:
            self.connection = make_connection(**connection_details)
            self.connection.is_persistent_connection = True
            self.interface = self.connection.get_plugin_interface()
        except:
            printError("could not connect to Azureus-Server")
            printException()
            return False

        # azureus version
        self.azu_version_str = str(self.connection.get_azureus_version())
        self.azu_version_str = self.azu_version_str.replace(", ", ".")
        self.azu_version_str = self.azu_version_str.replace("(", "")
        self.azu_version_str = self.azu_version_str.replace(")", "")
        printMessage("connected. Azureus-Version: %s" % self.azu_version_str)

        # download-manager
        self.dm = self.interface.getDownloadManager()
        if self.dm is None:
            printError("Error getting Download-Manager object")
            return False

        # write stat-file and return
        return self.writeStatFile()
예제 #27
0
    def processRunRequests(self):
        printMessage("processing run-requests...")

        # read requests
        requests = []
        try:
            for fileName in os.listdir(self.flu_pathTransfersRun):
                inputFile = self.flu_pathTransfersRun + fileName
                outputFile = self.flu_pathTransfers + fileName
                # move file + add to requests
                try:
                    # read file to mem
                    f = open(inputFile, "r")
                    data = f.read()
                    f.close()
                    # delete
                    os.remove(inputFile)
                    # write file
                    f = open(outputFile, "w")
                    f.write(data)
                    f.flush()
                    f.close()
                    # add
                    requests.append(fileName)
                except:
                    printError("Failed to move file : %s" % inputFile)
        except:
            return False

        # process requests
        if len(requests) > 0:
            try:
                # update downloads
                self.downloads = {}
                self.updateDownloads()
                for fileName in requests:
                    # add if needed
                    if fileName not in self.downloads:
                        try:
                            # add
                            self.addTransfer(fileName)
                        except:
                            printError("exception when adding new transfer %s" % fileName)
                            raise
                    # downloads
                    tries = 0
                    while tries < 5 and fileName not in self.downloads:
                        # if fileName not in self.downloads:
                        printMessage("download %s missing, update downloads..." % fileName)
                        self.updateDownloads()
                        # sleep + increment
                        time.sleep(1)
                        tries += 1
                    # start transfer
                    if fileName in self.downloads:
                        try:
                            transfer = Transfer(self.tf_pathTransfers, self.flu_pathTransfers, fileName)
                            transfer.start(self.downloads[fileName])
                        except:
                            printError("exception when starting new transfer %s" % fileName)
                            raise
                    else:
                        printError("download %s not in azureus-downloads, cannot start it." % fileName)
            except:
                printMessage("exception when processing run-requests:")
                printException()

        # return
        return True
예제 #28
0
    def statShutdown(self, download, error=None):

        # set some values
        self.sf.running = Transfer.TF_STOPPED
        self.sf.down_speed = "0.00 kB/s"
        self.sf.up_speed = "0.00 kB/s"
        self.sf.transferowner = self.tf.transferowner
        self.sf.seeds = ""
        self.sf.peers = ""
        self.sf.sharing = ""
        self.sf.seedlimit = ""
        try:

            # stats
            try:
                stats = download.getStats()

                # done
                if download.isComplete():
                    self.sf.percent_done = 100
                    self.sf.time_left = "Download Succeeded!"

                # not done
                else:
                    try:
                        pctf = float(stats.getCompleted())
                        pctf /= 10
                        pcts = "-" + str(pctf)
                        pctf = float(pcts)
                        pctf -= 100
                        self.sf.percent_done = str(pctf)
                    except:
                        printException()
                    self.sf.time_left = "Transfer Stopped"

                # uptotal
                try:
                    self.sf.uptotal = str(stats.getUploaded())
                except:
                    printException()

                # downtotal
                try:
                    self.sf.downtotal = str(stats.getDownloaded())
                except:
                    printException()
            except:
                printException()

            # size
            try:
                self.sf.size = str(download.getTorrent().getSize())
            except:
                printException()

            # error
            if error is not None:
                self.sf.time_left = "Error: %s" % error

            # write
            return self.sf.write()

        except:
            printException()
            return False
예제 #29
0
    # check argv-length
    if len(sys.argv) < 7:
        from fluazu import __version_str__
        print "fluazu %s" % __version_str__
        print "\nError: missing arguments.\n"
        print "Usage:"
        print "fluazu.py path host port secure username password\n"
        print " path     : flux-path"
        print " host     : host of azureus-server"
        print " port     : port of azureus-server (xml/http, default: 6884)"
        print " secure   : use secure connection to azureus (0/1)"
        print " username : username to use when connecting to azureus-server"
        print " password : password to use when connecting to azureus-server\n"
        sys.exit(0)

    # run daemon
    daemon = FluAzuD()
    exitVal = 0
    try:
        exitVal = daemon.run(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5], sys.argv[6])
    except KeyboardInterrupt:
        daemon.shutdown()
        exitVal = 0
    except Exception, e:
    	print "Exception:"
    	printException()

    # exit
    sys.exit(exitVal)
예제 #30
0
파일: FluAzuD.py 프로젝트: safvan010/123
    def checkAzuConnection(self):

        # con valid
        try:
            if self.connection.is_connection_valid():
                return True
            else:
                raise

        # con not valid
        except:

            # out
            printMessage(
                "connection to Azureus-server lost, reconnecting to %s:%d ..."
                % (self.azu_host, self.azu_port))

            # try to reconnect
            for i in range(FluAzuD.MAX_RECONNECT_TRIES):

                # sleep
                time.sleep(i << 2)

                # out
                printMessage("reconnect-try %d ..." % (i + 1))

                # establish con
                try:
                    self.connection.establish_connection(True)
                    printMessage("established connection to Azureus-server")
                except:
                    printError(
                        "Error establishing connection to Azureus-server")
                    printException()
                    continue

                # interface
                try:
                    self.interface = self.connection.get_plugin_interface()
                except LinkError, error:
                    printError("Error getting interface object")
                    printException()
                    self.interface = None
                    continue

                # download-manager
                try:
                    self.dm = None
                    self.dm = self.interface.getDownloadManager()
                    if self.dm is None:
                        raise
                    else:
                        return True
                except:
                    printError("Error getting Download-Manager object")
                    continue

            # seems like azu is down. give up
            printError("no connection after %d tries, i give up, azu is gone" %
                       FluAzuD.MAX_RECONNECT_TRIES)
            return False
예제 #31
0
파일: FluAzuD.py 프로젝트: safvan010/123
    def initialize(self):

        # flu

        # check dirs
        if not self.checkDirs():
            printError("Error checking dirs. path: %s" % self.tf_path)
            return False

        # write pid-file
        self.pid = (str(os.getpid())).strip()
        printMessage("writing pid-file %s (%s)" % (self.flu_filePid, self.pid))
        try:
            pidFile = open(self.flu_filePid, 'w')
            pidFile.write(self.pid + "\n")
            pidFile.flush()
            pidFile.close()
        except:
            printError("Failed to write pid-file %s (%s)" %
                       (self.flu_filePid, self.pid))
            return False

        # delete command-file if exists
        if os.path.isfile(self.flu_fileCommand):
            try:
                printMessage("removing command-file %s ..." %
                             self.flu_fileCommand)
                os.remove(self.flu_fileCommand)
            except:
                printError("Failed to delete commandfile %s" %
                           self.flu_fileCommand)
                return False

        # load transfers
        self.loadTransfers()

        # azu
        printMessage("connecting to Azureus-Server (%s:%d)..." %
                     (self.azu_host, self.azu_port))

        # set connection details
        connection_details = {}
        connection_details['host'] = self.azu_host
        connection_details['port'] = self.azu_port
        connection_details['secure'] = self.azu_secure
        if len(self.azu_user) > 0:
            connection_details['user'] = self.azu_user
            connection_details['password'] = self.azu_pass

        # make connection
        try:
            self.connection = make_connection(**connection_details)
            self.connection.is_persistent_connection = True
            self.interface = self.connection.get_plugin_interface()
        except:
            printError("could not connect to Azureus-Server")
            printException()
            return False

        # azureus version
        self.azu_version_str = str(self.connection.get_azureus_version())
        self.azu_version_str = self.azu_version_str.replace(", ", ".")
        self.azu_version_str = self.azu_version_str.replace("(", "")
        self.azu_version_str = self.azu_version_str.replace(")", "")
        printMessage("connected. Azureus-Version: %s" % self.azu_version_str)

        # download-manager
        self.dm = self.interface.getDownloadManager()
        if self.dm is None:
            printError("Error getting Download-Manager object")
            return False

        # write stat-file and return
        return self.writeStatFile()
예제 #32
0
파일: FluAzuD.py 프로젝트: safvan010/123
    def loadCurrentNotInVuze(self):

        printMessage("loading missing transfers... %s" %
                     self.flu_pathTransfers)

        needReload = 0
        requests = []
        try:
            vuzePathExists = os.path.isdir(self.azu_pathTransfers)
            for fileName in os.listdir(self.flu_pathTransfers):
                if os.path.isfile(self.tf_pathTransfers + fileName):
                    if vuzePathExists and not os.path.isfile(
                            self.azu_pathTransfers + fileName):
                        # add to vuze (but dont start)
                        #printMessage("adding missing transfer... %s" % fileName)
                        #requests.append(fileName)
                        try:
                            os.remove(self.flu_pathTransfers + fileName +
                                      ".cmd")
                        except:
                            printMessage("ignoring existing cmd file... %s" %
                                         fileName)
                        needReload = 1
                else:
                    if os.path.isfile(self.tf_pathTransfers + fileName +
                                      ".pid"):
                        try:
                            printMessage("cleaning transfer pid... %s" %
                                         fileName)
                            os.remove(self.tf_pathTransfers + fileName +
                                      ".pid")
                        except:
                            printError(
                                "exception when cleaning old transfer %s" %
                                fileName + ".pid")
                            continue
        except:
            return False

        # process requests
        if len(requests) > 0:
            try:
                # update downloads
                #self.downloads = {}
                #self.updateDownloads()
                for fileName in requests:
                    # add if needed
                    if fileName not in self.downloads:
                        try:
                            # add
                            torrent = self.addTransfer(fileName)
                        except:
                            printError(
                                "exception when adding new transfer %s" %
                                fileName)
                            raise

                        # downloads
                        tries = 0
                        while torrent and (
                                tries < 10) and fileName not in self.downloads:
                            download = self.dm.getDownload(torrent)
                            if (torrent and download):
                                self.downloads[fileName] = download
                                self.needUpdate = 1
                                break
                            else:
                                printMessage(
                                    "download %s missing, update downloads..."
                                    % torrent)

                            # sleep + increment
                            time.sleep(0.5)
                            tries += 1

                        # start transfer
                        if fileName in self.downloads:
                            try:
                                transfer = Transfer(self.tf_pathTransfers,
                                                    self.flu_pathTransfers,
                                                    fileName)
                                #transfer.start(self.downloads[fileName])
                            except:
                                printError(
                                    "exception when starting new transfer %s" %
                                    fileName)
                                raise
                        else:
                            printError(
                                "download %s not in azureus-downloads, cannot start it."
                                % fileName)
            except:
                printMessage("exception when processing run-requests:")
                printException()

        if needReload == 1:
            self.reload()

        # return
        return True
예제 #33
0
파일: FluAzuD.py 프로젝트: safvan010/123
    def processRunRequests(self):
        printMessage("processing run-requests... %s" %
                     self.flu_pathTransfersRun)

        # read requests
        requests = []
        try:
            for fileName in os.listdir(self.flu_pathTransfersRun):
                inputFile = self.flu_pathTransfersRun + fileName
                outputFile = self.flu_pathTransfers + fileName
                # move file + add to requests
                try:
                    # read file to mem
                    f = open(inputFile, 'r')
                    data = f.read()
                    f.close()
                    # delete
                    os.remove(inputFile)
                    # write file
                    f = open(outputFile, 'w')
                    f.write(data)
                    f.flush()
                    f.close()
                    # add
                    requests.append(fileName)
                except:
                    printError("Failed to move file : %s" % inputFile)
        except:
            return False

        # process requests
        if len(requests) > 0:
            try:
                # update downloads
                #self.downloads = {}
                #self.updateDownloads()
                for fileName in requests:
                    # add if needed
                    if fileName not in self.downloads:
                        try:
                            # add
                            torrent = self.addTransfer(fileName)
                        except:
                            printError(
                                "exception when adding new transfer %s" %
                                fileName)
                            raise

                        # downloads
                        tries = 0
                        while torrent and (
                                tries < 10) and fileName not in self.downloads:
                            download = self.dm.getDownload(torrent)
                            if (torrent and download):
                                self.downloads[fileName] = download
                                self.needUpdate = 1
                                break
                            else:
                                printMessage(
                                    "download %s missing, update downloads..."
                                    % torrent)

                            # sleep + increment
                            time.sleep(0.5)
                            tries += 1

                        # start transfer
                        if fileName in self.downloads:
                            try:
                                transfer = Transfer(self.tf_pathTransfers,
                                                    self.flu_pathTransfers,
                                                    fileName)
                                transfer.start(self.downloads[fileName])
                            except:
                                printError(
                                    "exception when starting new transfer %s" %
                                    fileName)
                                raise
                        else:
                            printError(
                                "download %s not in azureus-downloads, cannot start it."
                                % fileName)
            except:
                printMessage("exception when processing run-requests:")
                printException()

        # return
        return True
예제 #34
0
파일: fluazu.py 프로젝트: safvan010/123
    # check argv-length
    if len(sys.argv) < 7:
        from fluazu import __version_str__
        print "fluazu %s" % __version_str__
        print "\nError: missing arguments.\n"
        print "Usage:"
        print "fluazu.py path host port secure username password\n"
        print " path     : flux-path"
        print " host     : host of azureus-server"
        print " port     : port of azureus-server (xml/http, default: 6884)"
        print " secure   : use secure connection to azureus (0/1)"
        print " username : username to use when connecting to azureus-server"
        print " password : password to use when connecting to azureus-server\n"
        sys.exit(0)

    # run daemon
    daemon = FluAzuD()
    exitVal = 0
    try:
        exitVal = daemon.run(sys.argv[1], sys.argv[2], sys.argv[3],
                             sys.argv[4], sys.argv[5], sys.argv[6])
    except KeyboardInterrupt:
        daemon.shutdown()
        exitVal = 0
    except Exception, e:
        print "Exception:"
        printException()

    # exit
    sys.exit(exitVal)
예제 #35
0
    def statRunning(self, download):

        # die-when-done
        if self.state_azu == Transfer.AZ_SEEDING and self.tf.die_when_done.lower() == 'true':
            self.log("die-when-done set, setting shutdown-flag...")
            self.stop(download)
            return

        # set some values
        self.sf.running = Transfer.TF_RUNNING
        try:
            try:

                # stats
                if download == None:
                    return
                stats = download.getStats()
                if stats == None:
                    return

                # die-on-seed-limit
                if self.state_azu == Transfer.AZ_SEEDING:
                    sk = float(self.tf.sharekill)
                    if sk > 0:
                        try:
                            shareRatio = (float(stats.getShareRatio())) / 10
                            if shareRatio >= sk:
                                self.log("seed-limit %s reached (%s), setting shutdown-flag..." % (self.tf.sharekill, str(shareRatio)))
                                self.stop(download)
                                return
                        except:
                            printException()

                # completed
                try:
                    pctf = (float(stats.getCompleted())) / 10
                    self.sf.percent_done = str(pctf)
                except:
                    printException()

                # time_left
                try:
                    self.sf.time_left = str(stats.getETA())
                except:
                    self.sf.time_left = '-'

                # down_speed
                try:
                    self.sf.down_speed = "%.1f kB/s" % ((float(stats.getDownloadAverage())) / 1024)
                except:
                    printException()

                # up_speed
                try:
                    self.sf.up_speed = "%.1f kB/s" % ((float(stats.getUploadAverage())) / 1024)
                except:
                    printException()

                # uptotal
                try:
                    self.sf.uptotal = str(stats.getUploaded())
                except:
                    printException()

                # downtotal
                try:
                    self.sf.downtotal = str(stats.getDownloaded())
                except:
                    printException()

            except:
                printException()

            # hosts
            try:
                ps = download.getPeerManager().getStats()
                scrape = download.getLastScrapeResult()

                # seeds
                try:
                    countS = int(scrape.getSeedCount())
                    if (countS < 0):
                        countS = 0
                    countSC = int(ps.getConnectedSeeds())
                    if (countSC < 0):
                        countSC = 0
                    self.sf.seeds = "%d (%d)" % (countSC, countS)
                except:
                    printException()

                # peers
                try:
                    countP = int(scrape.getNonSeedCount())
                    if (countP < 0):
                        countP = 0
                    countPC = int(ps.getConnectedLeechers())
                    if (countPC < 0):
                        countPC = 0
                    self.sf.peers = "%d (%d)" % (countPC, countP)
                except:
                    printException()

            except:
                printException()

            # write
            return self.sf.write()

        except:
            printException()
            return False
예제 #36
0
    def statShutdown(self, download, error = None):

        # set some values
        self.sf.running = Transfer.TF_STOPPED
        self.sf.down_speed = "0.00 kB/s"
        self.sf.up_speed = "0.00 kB/s"
        self.sf.transferowner = self.tf.transferowner
        self.sf.seeds = ""
        self.sf.peers = ""
        self.sf.sharing = ""
        self.sf.seedlimit = ""
        try:

            # stats
            try:
                stats = download.getStats()

                # done
                if download.isComplete():
                    self.sf.percent_done = 100
                    self.sf.time_left = "Download Succeeded!"

                # not done
                else:
                    try:
                        pctf = float(stats.getCompleted())
                        pctf /= 10
                        pcts = "-" + str(pctf)
                        pctf = float(pcts)
                        pctf -= 100
                        self.sf.percent_done = str(pctf)
                    except:
                        printException()
                    self.sf.time_left = "Transfer Stopped"

                # uptotal
                try:
                    self.sf.uptotal = str(stats.getUploaded())
                except:
                    printException()

                # downtotal
                try:
                    self.sf.downtotal = str(stats.getDownloaded())
                except:
                    printException()
            except:
                printException()

            # size
            try:
                self.sf.size = str(download.getTorrent().getSize())
            except:
                printException()

            # error
            if error is not None:
                self.sf.time_left = "Error: %s" % error

            # write
            return self.sf.write()

        except:
            printException()
            return False
예제 #37
0
    def statRunning(self, download):

        # die-when-done
        if self.state_azu == Transfer.AZ_SEEDING and self.tf.die_when_done.lower(
        ) == 'true':
            self.log("die-when-done set, setting shutdown-flag...")
            self.stop(download)
            return

        # set some values
        self.sf.running = Transfer.TF_RUNNING
        try:
            try:

                # stats
                if download == None:
                    return
                stats = download.getStats()
                if stats == None:
                    return

                # die-on-seed-limit
                if self.state_azu == Transfer.AZ_SEEDING:
                    sk = float(self.tf.sharekill)
                    if sk > 0:
                        try:
                            shareRatio = (float(stats.getShareRatio())) / 10
                            if shareRatio >= sk:
                                self.log(
                                    "seed-limit %s reached (%s), setting shutdown-flag..."
                                    % (self.tf.sharekill, str(shareRatio)))
                                self.stop(download)
                                return
                        except:
                            printException()

                # completed
                try:
                    pctf = (float(stats.getCompleted())) / 10
                    self.sf.percent_done = str(pctf)
                except:
                    printException()

                # time_left
                try:
                    self.sf.time_left = str(stats.getETA())
                except:
                    self.sf.time_left = '-'

                # down_speed
                try:
                    self.sf.down_speed = "%.1f kB/s" % (
                        (float(stats.getDownloadAverage())) / 1024)
                except:
                    printException()

                # up_speed
                try:
                    self.sf.up_speed = "%.1f kB/s" % (
                        (float(stats.getUploadAverage())) / 1024)
                except:
                    printException()

                # uptotal
                try:
                    self.sf.uptotal = str(stats.getUploaded())
                except:
                    printException()

                # downtotal
                try:
                    self.sf.downtotal = str(stats.getDownloaded())
                except:
                    printException()

            except:
                printException()

            # hosts
            try:
                ps = download.getPeerManager().getStats()
                scrape = download.getLastScrapeResult()

                # seeds
                try:
                    countS = int(scrape.getSeedCount())
                    if (countS < 0):
                        countS = 0
                    countSC = int(ps.getConnectedSeeds())
                    if (countSC < 0):
                        countSC = 0
                    self.sf.seeds = "%d (%d)" % (countSC, countS)
                except:
                    printException()

                # peers
                try:
                    countP = int(scrape.getNonSeedCount())
                    if (countP < 0):
                        countP = 0
                    countPC = int(ps.getConnectedLeechers())
                    if (countPC < 0):
                        countPC = 0
                    self.sf.peers = "%d (%d)" % (countPC, countP)
                except:
                    printException()

            except:
                printException()

            # write
            return self.sf.write()

        except:
            printException()
            return False