本文整理匯總了Python中tracker.Tracker.has_torrent方法的典型用法代碼示例。如果您正苦於以下問題:Python Tracker.has_torrent方法的具體用法?Python Tracker.has_torrent怎麽用?Python Tracker.has_torrent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tracker.Tracker
的用法示例。
在下文中一共展示了Tracker.has_torrent方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Cloud
# 需要導入模塊: from tracker import Tracker [as 別名]
# 或者: from tracker.Tracker import has_torrent [as 別名]
#.........這裏部分代碼省略.........
for h in handles:
if h.is_valid() and h.has_metadata():
data = lt.bencode(h.write_resume_data())
open(os.path.join(options.save_path, h.get_torrent_info().name() + '.fastresume'), 'wb').write(data)
# save session settings here
def start(self):
"""
Start the cloud from a saved state
"""
if self.serving_files():
log.debug("Cloud already started.")
return False
# Open our database, and grind through it.
try:
self.db = anydbm.open(self.torr_db, 'c')
except:
return False
flag = 0
for info_hash, filename in self.db.iteritems():
log.debug("Loading... %s %s..." % (info_hash, filename,))
print os.path.join(self.torr_dir, filename+self.ext)
ti = TorrentMetaInfo(self.torr_dir, self.data_dir, self.my_tracker.tracker_ip, filename, str(filename+self.ext))
# if we have it, and the tracker has it, serve it
if not ti.is_valid_torr():
log.debug("Torrent invalid: %s, %s." % (info_hash, filename, ))
self.unstor_torr(info_hash)
elif not self.my_tracker.has_torrent(ti):
log.debug("Torrent does not exist on tracker: %s, %s." % (str(ti.info_hash), filename, ))
self.unstor_torr(info_hash)
else:
self.session.serve(ti)
flag = 1 # serve at least one torrent...
self.db.close()
if flag:
return True
else:
log.debug("Nothing in the database to serve.")
return False
def serving_files(self):
"""
Tells us if the cloud is serving any files.
"""
if len(self.session.handles) > 0:
return True
else:
return False
###########################################
# Database functions
###########################################
def stor_torr(self, info_hash, torr_name):
"""
Store torrents we're serving in the database. If it's already in our database, just
ignore it. Pairs are stored as key => infohash, value=>torr_name