本文整理汇总了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