本文整理汇总了Python中Tribler.Core.DownloadConfig.DownloadStartupConfig类的典型用法代码示例。如果您正苦于以下问题:Python DownloadStartupConfig类的具体用法?Python DownloadStartupConfig怎么用?Python DownloadStartupConfig使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DownloadStartupConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUpDownloadConfig
def setUpDownloadConfig(self):
dscfg = DownloadStartupConfig()
print >> sys.stderr, "test: Downloading to", self.config_path
dscfg.set_dest_dir(self.config_path)
dscfg.set_breakup_seed_bitfield(False)
return dscfg
示例2: __init__
def __init__(self,dlconfig=None):
if DefaultDownloadStartupConfig.__single:
raise RuntimeError, "DefaultDownloadStartupConfig is singleton"
DefaultDownloadStartupConfig.__single = self
DownloadStartupConfig.__init__(self,dlconfig=dlconfig)
示例3: setUpPostSession
def setUpPostSession(self):
""" override TestAsServer """
TestAsServer.setUpPostSession(self)
# Let Tribler start downloading an non-functioning torrent, so
# we can talk to a normal download engine.
self.torrentfn = os.path.join('extend_hs_dir','dummydata.merkle.torrent')
tdef = TorrentDef.load(self.torrentfn)
dscfg = DownloadStartupConfig()
dscfg.set_dest_dir(self.config_path)
self.session.start_download(tdef,dscfg)
# This is the infohash of the torrent in test/extend_hs_dir
self.infohash = '\xccg\x07\xe2\x9e!]\x16\xae{\xb8\x10?\xf9\xa5\xf9\x07\xfdBk'
self.setUpMyListenSocket()
# Must be changed in test/extend_hs_dir/dummydata.merkle.torrent as well
self.mytrackerport = 4901
# Must be Tribler version <= 3.5.0. Changing this to 351 makes this test
# fail, so it's a good test.
self.myid = 'R350-----HgUyPu56789'
self.mytracker = MyTracker(self.mytrackerport,self.myid,'127.0.0.1',self.mylistenport)
self.mytracker.background_serve()
print >>sys.stderr,"test: Giving MyTracker and myself time to start"
time.sleep(5)
示例4: setupSeeder
def setupSeeder(self):
from Tribler.Core.Session import Session
from Tribler.Core.TorrentDef import TorrentDef
from Tribler.Core.DownloadConfig import DownloadStartupConfig
self.setUpPreSession()
self.config.set_libtorrent(True)
self.config2 = self.config.copy()
self.session2 = Session(self.config2, ignore_singleton=True)
upgrader = self.session2.prestart()
while not upgrader.is_done:
time.sleep(0.1)
assert not upgrader.failed, upgrader.current_status
self.session2.start()
tdef = TorrentDef()
tdef.add_content(os.path.join(TESTS_DATA_DIR, "video.avi"))
tdef.set_tracker("http://fake.net/announce")
tdef.finalize()
torrentfn = os.path.join(self.session.get_state_dir(), "gen.torrent")
tdef.save(torrentfn)
dscfg = DownloadStartupConfig()
dscfg.set_dest_dir(TESTS_DATA_DIR) # basedir of the file we are seeding
d = self.session2.start_download(tdef, dscfg)
d.set_state_callback(self.seeder_state_callback)
return torrentfn
示例5: setupSeeder
def setupSeeder(self, hops=0, session=None):
from Tribler.Core.Session import Session
from Tribler.Core.TorrentDef import TorrentDef
from Tribler.Core.DownloadConfig import DownloadStartupConfig
self.setUpPreSession()
self.config.set_libtorrent(True)
self.config2 = self.config.copy()
self.config2.set_state_dir(self.getStateDir(2))
if session is None:
self.session2 = Session(self.config2, ignore_singleton=True, autoload_discovery=False)
upgrader = self.session2.prestart()
while not upgrader.is_done:
time.sleep(0.1)
self.session2.start()
session = self.session2
tdef = TorrentDef()
tdef.add_content(os.path.join(TESTS_DATA_DIR, "video.avi"))
tdef.set_tracker("http://fake.net/announce")
tdef.set_private() # disable dht
tdef.finalize()
torrentfn = os.path.join(session.get_state_dir(), "gen.torrent")
tdef.save(torrentfn)
dscfg = DownloadStartupConfig()
dscfg.set_dest_dir(TESTS_DATA_DIR) # basedir of the file we are seeding
dscfg.set_hops(hops)
d = session.start_download(tdef, dscfg)
d.set_state_callback(self.seeder_state_callback)
return torrentfn
示例6: setup_tunnel_seeder
def setup_tunnel_seeder(self, hops):
"""
Setup the seeder.
"""
from Tribler.Core.Session import Session
self.seed_config = self.config.copy()
self.seed_config.set_state_dir(self.getStateDir(2))
self.seed_config.set_megacache_enabled(True)
self.seed_config.set_tunnel_community_socks5_listen_ports(self.get_socks5_ports())
if self.session2 is None:
self.session2 = Session(self.seed_config)
self.session2.start()
tdef = TorrentDef()
tdef.add_content(os.path.join(TESTS_DATA_DIR, "video.avi"))
tdef.set_tracker("http://localhost/announce")
tdef.finalize()
torrentfn = os.path.join(self.session2.config.get_state_dir(), "gen.torrent")
tdef.save(torrentfn)
self.seed_tdef = tdef
if hops > 0: # Safe seeding enabled
self.tunnel_community_seeder = self.load_tunnel_community_in_session(self.session2)
self.tunnel_community_seeder.build_tunnels(hops)
else:
self.sanitize_network(self.session2)
dscfg = DownloadStartupConfig()
dscfg.set_dest_dir(TESTS_DATA_DIR) # basedir of the file we are seeding
dscfg.set_hops(hops)
d = self.session2.start_download_from_tdef(tdef, dscfg)
d.set_state_callback(self.seeder_state_callback)
示例7: resume_download
def resume_download(self, filename, setupDelay=0):
tdef = dscfg = pstate = None
try:
pstate = self.load_download_pstate(filename)
# SWIFTPROC
metainfo = pstate.get('state', 'metainfo')
if 'infohash' in metainfo:
tdef = TorrentDefNoMetainfo(metainfo['infohash'], metainfo['name'], metainfo.get('url', None))
else:
tdef = TorrentDef.load_from_dict(metainfo)
if pstate.has_option('download_defaults', 'saveas') and \
isinstance(pstate.get('download_defaults', 'saveas'), tuple):
pstate.set('download_defaults', 'saveas', pstate.get('download_defaults', 'saveas')[-1])
dscfg = DownloadStartupConfig(pstate)
except:
# pstate is invalid or non-existing
_, file = os.path.split(filename)
infohash = binascii.unhexlify(file[:-6])
torrent_data = self.torrent_store.get(infohash)
if torrent_data:
try:
tdef = TorrentDef.load_from_memory(torrent_data)
defaultDLConfig = DefaultDownloadStartupConfig.getInstance()
dscfg = defaultDLConfig.copy()
if self.mypref_db is not None:
dest_dir = self.mypref_db.getMyPrefStatsInfohash(infohash)
if dest_dir and os.path.isdir(dest_dir):
dscfg.set_dest_dir(dest_dir)
except ValueError:
self._logger.warning("tlm: torrent data invalid")
if pstate is not None:
has_resume_data = pstate.get('state', 'engineresumedata') is not None
self._logger.debug("tlm: load_checkpoint: resumedata %s",
'len %s ' % len(pstate.get('state', 'engineresumedata')) if has_resume_data else 'None')
if tdef and dscfg:
if dscfg.get_dest_dir() != '': # removed torrent ignoring
try:
if self.download_exists(tdef.get_infohash()):
self._logger.info("tlm: not resuming checkpoint because download has already been added")
elif dscfg.get_credit_mining() and not self.session.config.get_credit_mining_enabled():
self._logger.info("tlm: not resuming checkpoint since token mining is disabled")
else:
self.add(tdef, dscfg, pstate, setupDelay=setupDelay)
except Exception as e:
self._logger.exception("tlm: load check_point: exception while adding download %s", tdef)
else:
self._logger.info("tlm: removing checkpoint %s destdir is %s", filename, dscfg.get_dest_dir())
os.remove(filename)
else:
self._logger.info("tlm: could not resume checkpoint %s %s %s", filename, tdef, dscfg)
示例8: __init__
def __init__(self, dlconfig=None):
if DefaultDownloadStartupConfig.__single:
raise RuntimeError("DefaultDownloadStartupConfig is singleton")
DefaultDownloadStartupConfig.__single = self
DownloadStartupConfig.__init__(self, dlconfig=dlconfig)
self._logger = logging.getLogger(self.__class__.__name__)
示例9: start_anon_download
def start_anon_download(self, hops=1):
"""
Start an anonymous download in the main Tribler session.
"""
dscfg = DownloadStartupConfig()
dscfg.set_dest_dir(self.getDestDir())
dscfg.set_hops(hops)
download = self.session.start_download_from_tdef(self.seed_tdef, dscfg)
download.add_peer(("127.0.0.1", self.session2.config.get_libtorrent_port()))
return download
示例10: start_vod_download
def start_vod_download(self):
self.tdef = TorrentDef()
self.tdef.add_content(self.sourcefn)
self.tdef.set_tracker("http://127.0.0.1:12/announce")
self.tdef.finalize()
dscfg = DownloadStartupConfig()
dscfg.set_dest_dir(os.path.dirname(self.sourcefn))
download = self.session.start_download_from_tdef(self.tdef, dscfg)
return download.get_handle()
示例11: start_anon_download
def start_anon_download(self, hops=1):
"""
Start an anonymous download in the main Tribler session.
"""
dscfg = DownloadStartupConfig()
dscfg.set_dest_dir(self.getDestDir())
dscfg.set_hops(hops)
download = self.session.start_download_from_tdef(self.seed_tdef, dscfg)
tc = self.session.lm.tunnel_community
tc.bittorrent_peers[download] = [("127.0.0.1", self.session2.config.get_libtorrent_port())]
return download
示例12: updated_my_channel
def updated_my_channel(self, tdef):
"""
Notify the core that we updated our channel.
"""
with db_session:
my_channel = self.session.lm.mds.ChannelMetadata.get_my_channel()
if my_channel and my_channel.status == COMMITTED and not self.session.has_download(str(my_channel.infohash)):
dcfg = DownloadStartupConfig()
dcfg.set_dest_dir(self.session.lm.mds.channels_dir)
dcfg.set_channel_download(True)
self.session.lm.add(tdef, dcfg)
示例13: updated_my_channel
def updated_my_channel(self, new_torrent_path):
"""
Notify the core that we updated our channel.
:param new_torrent_path: path to the new torrent file
"""
# Start the new download
tdef = TorrentDef.load(new_torrent_path)
dcfg = DownloadStartupConfig()
dcfg.set_dest_dir(self.mds.channels_dir)
dcfg.set_channel_download(True)
self.add(tdef, dcfg)
示例14: register_file_stream
def register_file_stream(self):
self.tdef = TorrentDef()
self.tdef.add_content(self.sourcefn)
self.tdef.set_tracker("http://127.0.0.1:12/announce")
self.tdef.finalize()
dscfg = DownloadStartupConfig()
dscfg.set_dest_dir(os.path.dirname(self.sourcefn))
download = self.session.start_download(self.tdef, dscfg)
while not download.handle:
time.sleep(1)
示例15: test_remove_torrent_id
def test_remove_torrent_id(self):
"""
Test whether removing a torrent id works.
"""
torrent_def = TorrentDef.load(TORRENT_UBUNTU_FILE)
dcfg = DownloadStartupConfig()
dcfg.set_dest_dir(self.getDestDir())
download = self.session.start_download_from_tdef(torrent_def, download_startup_config=dcfg, hidden=True)
# Create a deferred which forwards the unhexlified string version of the download's infohash
download_started = download.get_handle().addCallback(lambda handle: unhexlify(str(handle.info_hash())))
return download_started.addCallback(self.session.remove_download_by_id)