def set_video_event_callback(self,usercallback,dlmode=DLMODE_VOD):
     """ Note: this currently works only when the download is stopped. """
     self.dllock.acquire()
     try:
         DownloadConfigInterface.set_video_event_callback(self,usercallback,dlmode=dlmode)
     finally:
         self.dllock.release()
示例#2
0
    def test_set_settings(self):
        """
        Testing whether settings in the API can be successfully set
        """
        download = DownloadConfigInterface()
        download.get_credit_mining = lambda: False
        self.session.get_downloads = lambda: [download]

        def verify_response1(_):
            self.assertEqual(download.get_seeding_mode(), 'time')
            self.assertEqual(download.get_seeding_time(), 100)

        self.should_check_equality = False
        post_data = json.dumps({'libtorrent': {'utp': False, 'max_download_rate': 50},
                                'download_defaults': {'seeding_mode': 'time', 'seeding_time': 100}})
        yield self.do_request('settings', expected_code=200, request_type='POST', raw_data=post_data) \
            .addCallback(verify_response1)

        def verify_response2(_):
            self.assertEqual(download.get_seeding_mode(), 'ratio')
            self.assertEqual(download.get_seeding_ratio(), 3)

        post_data = json.dumps({'download_defaults': {'seeding_mode': 'ratio', 'seeding_ratio': 3}})
        yield self.do_request('settings', expected_code=200, request_type='POST', raw_data=post_data) \
            .addCallback(verify_response2)

        download.get_credit_mining = lambda: True

        def verify_response3(_):
            self.assertNotEqual(download.get_seeding_mode(), 'never')

        post_data = json.dumps({'download_defaults': {'seeding_mode': 'never'}})
        yield self.do_request('settings', expected_code=200, request_type='POST', raw_data=post_data) \
            .addCallback(verify_response3)
 def set_mode(self,mode):
     """ Note: this currently works only when the download is stopped. """
     self.dllock.acquire()
     try:
         DownloadConfigInterface.set_mode(self,mode)
     finally:
         self.dllock.release()
 def set_mode(self, mode):
     """ Note: this has no effect, swift currently doesn't have DL modes """
     self.dllock.acquire()
     try:
         DownloadConfigInterface.set_mode(self, mode)
     finally:
         self.dllock.release()
示例#5
0
 def set_mode(self, mode):
     """ Note: this currently works only when the download is stopped. """
     self.dllock.acquire()
     try:
         DownloadConfigInterface.set_mode(self, mode)
     finally:
         self.dllock.release()
示例#6
0
 def set_video_event_callback(self, usercallback):
     """ Note: this currently works only when the download is stopped. """
     self.dllock.acquire()
     try:
         DownloadConfigInterface.set_video_event_callback(self, usercallback)
     finally:
         self.dllock.release()
 def set_mode(self,mode):
     """ Note: this has no effect, swift currently doesn't have DL modes """
     self.dllock.acquire()
     try:
         DownloadConfigInterface.set_mode(self,mode)
     finally:
         self.dllock.release()
 def set_selected_files(self,files):
     """ Note: this currently works only when the download is stopped. """
     self.dllock.acquire()
     try:
         DownloadConfigInterface.set_selected_files(self,files)
         self.set_filepieceranges(self.tdef.get_metainfo())
     finally:
         self.dllock.release()
示例#9
0
 def set_selected_files(self, files):
     """ Note: this currently works only when the download is stopped. """
     self.dllock.acquire()
     try:
         DownloadConfigInterface.set_selected_files(self, files)
         self.set_filepieceranges(self.tdef.get_metainfo())
     finally:
         self.dllock.release()
示例#10
0
    def test_set_settings(self):
        """
        Testing whether settings in the API can be successfully set
        """
        download = DownloadConfigInterface()
        download.get_share_mode = lambda: False
        self.session.get_downloads = lambda: [download]

        old_filter_setting = self.session.tribler_config.get_family_filter_enabled(
        )

        def verify_response1(_):
            self.assertNotEqual(
                self.session.tribler_config.get_family_filter_enabled(),
                old_filter_setting)
            self.assertEqual(download.get_seeding_mode(), 'time')
            self.assertEqual(download.get_seeding_time(), 100)

        self.should_check_equality = False
        post_data = json.dumps({
            'general': {
                'family_filter': not old_filter_setting
            },
            'Tribler': {
                'maxuploadrate': '1234'
            },
            'libtorrent': {
                'utp': False,
                'max_download_rate': 50
            },
            'downloadconfig': {
                'seeding_mode': 'time',
                'seeding_time': 100
            }
        })
        yield self.do_request('settings', expected_code=200, request_type='POST', post_data=post_data, raw_data=True) \
            .addCallback(verify_response1)

        def verify_response2(_):
            self.assertEqual(download.get_seeding_mode(), 'ratio')
            self.assertEqual(download.get_seeding_ratio(), 3)

        post_data = json.dumps(
            {'downloadconfig': {
                'seeding_mode': 'ratio',
                'seeding_ratio': 3
            }})
        yield self.do_request('settings', expected_code=200, request_type='POST', post_data=post_data, raw_data=True) \
            .addCallback(verify_response2)

        download.get_share_mode = lambda: True

        def verify_response3(_):
            self.assertNotEqual(download.get_seeding_mode(), 'never')

        post_data = json.dumps({'downloadconfig': {'seeding_mode': 'never'}})
        yield self.do_request('settings', expected_code=200, request_type='POST', post_data=post_data, raw_data=True) \
            .addCallback(verify_response3)
    def set_selected_files(self, selected_files=None):
        if not isinstance(self.tdef, TorrentDefNoMetainfo):

            if selected_files is None:
                selected_files = self.get_selected_files()
            else:
                DownloadConfigInterface.set_selected_files(self, selected_files)

            is_multifile = len(self.orig_files) > 1
            commonprefix = os.path.commonprefix(self.orig_files) if is_multifile else u''
            swarmname = commonprefix.partition(os.path.sep)[0]
            unwanteddir = os.path.join(swarmname, u'.unwanted')
            unwanteddir_abs = os.path.join(self.get_save_path().decode('utf-8'), unwanteddir)

            filepriorities = []
            torrent_storage = get_info_from_handle(self.handle).files()

            for index, orig_path in enumerate(self.orig_files):
                filename = orig_path[len(swarmname) + 1:] if swarmname else orig_path

                if filename in selected_files or not selected_files:
                    filepriorities.append(1)
                    new_path = orig_path
                else:
                    filepriorities.append(0)
                    new_path = os.path.join(unwanteddir, '%s%d' % (hexlify(self.tdef.get_infohash()), index))

                # as from libtorrent 1.0, files returning file_storage (lazy-iterable)
                if hasattr(lt, 'file_storage') and isinstance(torrent_storage, lt.file_storage):
                    cur_path = torrent_storage.at(index).path.decode('utf-8')
                else:
                    cur_path = torrent_storage[index].path.decode('utf-8')

                if cur_path != new_path:
                    if not os.path.exists(unwanteddir_abs) and unwanteddir in new_path:
                        try:
                            os.makedirs(unwanteddir_abs)
                            if sys.platform == "win32":
                                ctypes.windll.kernel32.SetFileAttributesW(
                                    unwanteddir_abs, 2)  # 2 = FILE_ATTRIBUTE_HIDDEN
                        except OSError:
                            self._logger.error("LibtorrentDownloadImpl: could not create %s" % unwanteddir_abs)
                            # Note: If the destination directory can't be accessed, libtorrent will not be able to store the files.
                            # This will result in a DLSTATUS_STOPPED_ON_ERROR.

                    # Path should be unicode if Libtorrent is using std::wstring (on Windows),
                    # else we use str (on Linux).
                    try:
                        self.handle.rename_file(index, new_path)
                    except TypeError:
                        self.handle.rename_file(index, new_path.encode("utf-8"))

            # if in share mode, don't change priority of the file
            if not self.get_share_mode():
                self.handle.prioritize_files(filepriorities)

            self.unwanteddir_abs = unwanteddir_abs
示例#12
0
 def set_max_conns_to_initiate(self, nconns):
     self.dllock.acquire()
     try:
         if self.sd is not None:
             set_max_conns2init_lambda = lambda: self.sd is not None and self.sd.set_max_conns_to_initiate(nconns, None)
             self.session.lm.rawserver.add_task(set_max_conns2init_lambda, 0.0)
         DownloadConfigInterface.set_max_conns_to_initiate(self, nconns)
     finally:
         self.dllock.release()
示例#13
0
    def set_selected_files(self, selected_files=None):
        if not isinstance(self.tdef, TorrentDefNoMetainfo):

            if selected_files is None:
                selected_files = self.get_selected_files()
            else:
                DownloadConfigInterface.set_selected_files(self, selected_files)

            is_multifile = len(self.orig_files) > 1
            commonprefix = os.path.commonprefix(self.orig_files) if is_multifile else u''
            swarmname = commonprefix.partition(os.path.sep)[0]
            unwanteddir = os.path.join(swarmname, u'.unwanted')
            unwanteddir_abs = os.path.join(self.get_save_path().decode('utf-8'), unwanteddir)

            filepriorities = []
            torrent_storage = get_info_from_handle(self.handle).files()

            for index, orig_path in enumerate(self.orig_files):
                filename = orig_path[len(swarmname) + 1:] if swarmname else orig_path

                if filename in selected_files or not selected_files:
                    filepriorities.append(1)
                    new_path = orig_path
                else:
                    filepriorities.append(0)
                    new_path = os.path.join(unwanteddir, '%s%d' % (hexlify(self.tdef.get_infohash()), index))

                # as from libtorrent 1.0, files returning file_storage (lazy-iterable)
                if hasattr(lt, 'file_storage') and isinstance(torrent_storage, lt.file_storage):
                    cur_path = torrent_storage.at(index).path.decode('utf-8')
                else:
                    cur_path = torrent_storage[index].path.decode('utf-8')

                if cur_path != new_path:
                    if not os.path.exists(unwanteddir_abs) and unwanteddir in new_path:
                        try:
                            os.makedirs(unwanteddir_abs)
                            if sys.platform == "win32":
                                ctypes.windll.kernel32.SetFileAttributesW(
                                    unwanteddir_abs, 2)  # 2 = FILE_ATTRIBUTE_HIDDEN
                        except OSError:
                            self._logger.error("LibtorrentDownloadImpl: could not create %s" % unwanteddir_abs)
                            # Note: If the destination directory can't be accessed, libtorrent will not be able to store the files.
                            # This will result in a DLSTATUS_STOPPED_ON_ERROR.

                    # Path should be unicode if Libtorrent is using std::wstring (on Windows),
                    # else we use str (on Linux).
                    try:
                        self.handle.rename_file(index, new_path)
                    except TypeError:
                        self.handle.rename_file(index, new_path.encode("utf-8"))

            # if in share mode, don't change priority of the file
            if not self.get_share_mode():
                self.handle.prioritize_files(filepriorities)

            self.unwanteddir_abs = unwanteddir_abs
 def update_peerlist(self,peerlist):
     self.dllock.acquire()
     try:
         if self.sd is not None:
             set_max_conns2init_lambda = lambda:self.sd.update_peerlist(peerlist,None)
             self.session.lm.rawserver.add_task(set_max_conns2init_lambda,0.0)
         DownloadConfigInterface.update_peerlist(self,peerlist)
     finally:
         self.dllock.release()
 def set_max_conns_to_initiate(self,nconns):
     self.dllock.acquire()
     try:
         if self.sd is not None:
             set_max_conns2init_lambda = lambda:self.sd is not None and self.sd.set_max_conns_to_initiate(nconns,None)
             self.session.lm.rawserver.add_task(set_max_conns2init_lambda,0.0)
         DownloadConfigInterface.set_max_conns_to_initiate(self,nconns)
     finally:
         self.dllock.release()
 def set_proxyservice_role(self, value):
     """ Set the proxyservice role for current download
     .
     @param value: the proxyservice role: PROXYSERVICE_ROLE_NONE, PROXYSERVICE_ROLE_DOE or PROXYSERVICE_ROLE_PROXY
     """
     self.dllock.acquire()
     try:
         DownloadConfigInterface.set_proxyservice_role(self, value)
     finally:
         self.dllock.release()
 def set_proxyservice_role(self, value):
     """ Set the proxyservice role for current download
     .
     @param value: the proxyservice role: PROXYSERVICE_ROLE_NONE, PROXYSERVICE_ROLE_DOE or PROXYSERVICE_ROLE_PROXY
     """
     self.dllock.acquire()
     try:
         DownloadConfigInterface.set_proxyservice_role(self, value)
     finally:
         self.dllock.release()
 def set_doe_mode(self, value):
     """ Set the doemode for current download
     .
     @param value: the doe mode: DOE_MODE_OFF, DOE_MODE_PRIVATE or DOE_MODE_SPEED
     """
     self.dllock.acquire()
     try:
         DownloadConfigInterface.set_doe_mode(self, value)
     finally:
         self.dllock.release()
 def set_doe_mode(self,value):
     """ Set the doemode for current download
     .
     @param value: the doe mode: DOE_MODE_OFF, DOE_MODE_PRIVATE or DOE_MODE_SPEED
     """
     self.dllock.acquire()
     try:
         DownloadConfigInterface.set_doe_mode(self, value)
     finally:
         self.dllock.release()
示例#20
0
 def update_peerlist(self, peerlist):
     self.dllock.acquire()
     try:
         if self.sd is not None:
             set_max_conns2init_lambda = lambda: self.sd.update_peerlist(
                 peerlist, None)
             self.session.lm.rawserver.add_task(set_max_conns2init_lambda,
                                                0.0)
         DownloadConfigInterface.update_peerlist(self, peerlist)
     finally:
         self.dllock.release()
示例#21
0
    def test_user_stopped(self):
        dlcfg = DownloadConfigInterface()
        dlcfg.set_user_stopped(False)
        self.assertFalse(dlcfg.get_user_stopped())

        dlcfg.set_user_stopped(True)
        self.assertTrue(dlcfg.get_user_stopped())
示例#22
0
 def get_rarest_first_priority_cutoff(self):
     self.dllock.acquire()
     try:
         return DownloadConfigInterface.get_rarest_first_priority_cutoff(
             self)
     finally:
         self.dllock.release()
    def set_max_speed(self, direct, speed):
        if DEBUG:
            print >>sys.stderr, "SwiftDownload: set_max_speed", self.get_def().get_name(), direct, speed
        # print_stack()

        self.dllock.acquire()
        try:
            # Don't need to throw an exception when stopped, we then just
            # save the new value and use it at (re)startup.
            if self.sp is not None:
                self.sp.set_max_speed(self, direct, speed)

            # At the moment we can't catch any errors in the engine that this
            # causes, so just assume it always works.
            DownloadConfigInterface.set_max_speed(self, direct, speed)
        finally:
            self.dllock.release()
示例#24
0
    def test_user_stopped(self):
        dlcfg = DownloadConfigInterface()
        dlcfg.set_user_stopped(False)
        self.assertFalse(dlcfg.get_user_stopped())

        dlcfg.set_user_stopped(True)
        self.assertTrue(dlcfg.get_user_stopped())
 def set_max_speed(self,direct,speed):
     if DEBUG:
         print >>sys.stderr,"Download: set_max_speed",`self.get_def().get_metainfo()['info']['name']`,direct,speed
     #print_stack()
     
     self.dllock.acquire()
     try:
         # Don't need to throw an exception when stopped, we then just save the new value and
         # use it at (re)startup.
         if self.sd is not None:
             set_max_speed_lambda = lambda:self.sd is not None and self.sd.set_max_speed(direct,speed,None)
             self.session.lm.rawserver.add_task(set_max_speed_lambda,0)
             
         # At the moment we can't catch any errors in the engine that this 
         # causes, so just assume it always works.
         DownloadConfigInterface.set_max_speed(self,direct,speed)
     finally:
         self.dllock.release()
 def get_proxyservice_role(self):
     """ Returns the proxyservice role of the client.
     @return: one of the possible three values: PROXYSERVICE_ROLE_NONE, PROXYSERVICE_ROLE_DOE or PROXYSERVICE_ROLE_PROXY
     """
     self.dllock.acquire()
     try:
         return DownloadConfigInterface.get_proxyservice_role(self)
     finally:
         self.dllock.release()
 def set_no_proxies(self,value):
     """ Set the maximum number of proxies used for a download.
     @param value: a positive integer number
     """
     self.dllock.acquire()
     try:
         return DownloadConfigInterface.set_no_proxies(self, value)
     finally:
         self.dllock.release()
 def get_doe_mode(self):
     """ Returns the doemode of the client.
     @return: one of the possible three values: DOE_MODE_OFF, DOE_MODE_PRIVATE, DOE_MODE_SPEED
     """
     self.dllock.acquire()
     try:
         return DownloadConfigInterface.get_doe_mode(self)
     finally:
         self.dllock.release()
 def get_proxyservice_role(self):
     """ Returns the proxyservice role of the client.
     @return: one of the possible three values: PROXYSERVICE_ROLE_NONE, PROXYSERVICE_ROLE_DOE or PROXYSERVICE_ROLE_PROXY
     """
     self.dllock.acquire()
     try:
         return DownloadConfigInterface.get_proxyservice_role(self)
     finally:
         self.dllock.release()
    def set_max_speed(self, direct, speed):
        if DEBUG:
            print >> sys.stderr, "SwiftDownload: set_max_speed", self.get_def(
            ).get_name(), direct, speed
        #print_stack()

        self.dllock.acquire()
        try:
            # Don't need to throw an exception when stopped, we then just
            # save the new value and use it at (re)startup.
            if self.sp is not None:
                self.sp.set_max_speed(self, direct, speed)

            # At the moment we can't catch any errors in the engine that this
            # causes, so just assume it always works.
            DownloadConfigInterface.set_max_speed(self, direct, speed)
        finally:
            self.dllock.release()
 def get_no_proxies(self):
     """ Returns the maximum number of proxies used for a download. 
     @return: a positive integer number
     """
     self.dllock.acquire()
     try:
         return DownloadConfigInterface.get_no_proxies(self)
     finally:
         self.dllock.release()
 def set_no_proxies(self, value):
     """ Set the maximum number of proxies used for a download.
     @param value: a positive integer number
     """
     self.dllock.acquire()
     try:
         return DownloadConfigInterface.set_no_proxies(self, value)
     finally:
         self.dllock.release()
 def get_no_proxies(self):
     """ Returns the maximum number of proxies used for a download. 
     @return: a positive integer number
     """
     self.dllock.acquire()
     try:
         return DownloadConfigInterface.get_no_proxies(self)
     finally:
         self.dllock.release()
 def get_doe_mode(self):
     """ Returns the doemode of the client.
     @return: one of the possible three values: DOE_MODE_OFF, DOE_MODE_PRIVATE, DOE_MODE_SPEED
     """
     self.dllock.acquire()
     try:
         return DownloadConfigInterface.get_doe_mode(self)
     finally:
         self.dllock.release()
示例#35
0
    def set_max_speed(self, direct, speed):
        if DEBUG:
            print >> sys.stderr, "Download: set_max_speed", ` self.get_def(
            ).get_metainfo()['info']['name'] `, direct, speed
        #print_stack()

        self.dllock.acquire()
        try:
            # Don't need to throw an exception when stopped, we then just save the new value and
            # use it at (re)startup.
            if self.sd is not None:
                set_max_speed_lambda = lambda: self.sd.set_max_speed(
                    direct, speed, None)
                self.session.lm.rawserver.add_task(set_max_speed_lambda, 0)

            # At the moment we can't catch any errors in the engine that this
            # causes, so just assume it always works.
            DownloadConfigInterface.set_max_speed(self, direct, speed)
        finally:
            self.dllock.release()
示例#36
0
 def get_video_events(self):
     self.dllock.acquire()
     try:
         return DownloadConfigInterface.get_video_events(self)
     finally:
         self.dllock.release()
 def set_poa(self, poa):
     self.dllock.acquire()
     try:
         DownloadConfigInterface.set_poa(self, poa)
     finally:
         self.dllock.release()
 def get_ut_pex_max_addrs_from_peer(self):
     self.dllock.acquire()
     try:
         return DownloadConfigInterface.get_ut_pex_max_addrs_from_peer(self)
     finally:
         self.dllock.release()
 def get_same_nat_try_internal(self):
     self.dllock.acquire()
     try:
         return DownloadConfigInterface.get_same_nat_try_internal(self)
     finally:
         self.dllock.release()
 def get_unchoke_bias_for_internal(self):
     self.dllock.acquire()
     try:
         return DownloadConfigInterface.get_unchoke_bias_for_internal(self)
     finally:
         self.dllock.release()
示例#41
0
 def get_auto_flush(self):
     self.dllock.acquire()
     try:
         return DownloadConfigInterface.get_auto_flush(self)
     finally:
         self.dllock.release()
示例#42
0
 def get_triple_check_writes(self):
     self.dllock.acquire()
     try:
         return DownloadConfigInterface.get_triple_check(self)
     finally:
         self.dllock.release()
示例#43
0
 def get_round_robin_period(self):
     self.dllock.acquire()
     try:
         return DownloadConfigInterface.get_round_robin_period(self)
     finally:
         self.dllock.release()
示例#44
0
 def get_max_files_open(self):
     self.dllock.acquire()
     try:
         return DownloadConfigInterface.get_max_files_open(self)
     finally:
         self.dllock.release()
 def get_exclude_ips(self):
     self.dllock.acquire()
     try:
         return DownloadConfigInterface.get_exclude_ips(self)
     finally:
         self.dllock.release()
示例#46
0
 def get_min_uploads(self):
     self.dllock.acquire()
     try:
         return DownloadConfigInterface.get_min_uploads(self)
     finally:
         self.dllock.release()
 def get_auto_flush(self):
     self.dllock.acquire()
     try:
         return DownloadConfigInterface.get_auto_flush(self)
     finally:
         self.dllock.release()
示例#48
0
 def get_max_speed(self, direct):
     self.dllock.acquire()
     try:
         return DownloadConfigInterface.get_max_speed(self, direct)
     finally:
         self.dllock.release()
 def get_security(self):
     self.dllock.acquire()
     try:
         return DownloadConfigInterface.get_security(self)
     finally:
         self.dllock.release()
示例#50
0
 def get_security(self):
     self.dllock.acquire()
     try:
         return DownloadConfigInterface.get_security(self)
     finally:
         self.dllock.release()
 def get_round_robin_period(self):
     self.dllock.acquire()
     try:
         return DownloadConfigInterface.get_round_robin_period(self)
     finally:
         self.dllock.release()
示例#52
0
 def get_lock_while_reading(self):
     self.dllock.acquire()
     try:
         return DownloadConfigInterface.get_lock_while_reading(self)
     finally:
         self.dllock.release()
示例#53
0
 def get_ut_pex_max_addrs_from_peer(self):
     self.dllock.acquire()
     try:
         return DownloadConfigInterface.get_ut_pex_max_addrs_from_peer(self)
     finally:
         self.dllock.release()
示例#54
0
 def get_exclude_ips(self):
     self.dllock.acquire()
     try:
         return DownloadConfigInterface.get_exclude_ips(self)
     finally:
         self.dllock.release()
 def get_video_events(self):
     self.dllock.acquire()
     try:
         return DownloadConfigInterface.get_video_events(self)
     finally:
         self.dllock.release()
 def get_poa(self, poa):
     self.dllock.acquire()
     try:
         return DownloadConfigInterface.get_poa(self)
     finally:
         self.dllock.release()
 def get_triple_check_writes(self):
     self.dllock.acquire()
     try:
         return DownloadConfigInterface.get_triple_check_writes(self)
     finally:
         self.dllock.release()
 def get_max_speed(self,direct):
     self.dllock.acquire()
     try:
         return DownloadConfigInterface.get_max_speed(self,direct)
     finally:
         self.dllock.release()
 def get_lock_while_reading(self):
     self.dllock.acquire()
     try:
         return DownloadConfigInterface.get_lock_while_reading(self)
     finally:
         self.dllock.release()