本文整理汇总了Python中home.models.ReplicaSet.get_myanonamouse_master方法的典型用法代码示例。如果您正苦于以下问题:Python ReplicaSet.get_myanonamouse_master方法的具体用法?Python ReplicaSet.get_myanonamouse_master怎么用?Python ReplicaSet.get_myanonamouse_master使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类home.models.ReplicaSet
的用法示例。
在下文中一共展示了ReplicaSet.get_myanonamouse_master方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_mam_torrent
# 需要导入模块: from home.models import ReplicaSet [as 别名]
# 或者: from home.models.ReplicaSet import get_myanonamouse_master [as 别名]
def add_mam_torrent(torrent_id, instance=None, location=None, mam_client=None,
add_to_client=True):
mam_torrent = MAMTorrent.get_or_create(mam_client, torrent_id)
if not instance:
instance = ReplicaSet.get_myanonamouse_master().get_preferred_instance()
if not location:
location = DownloadLocation.get_myanonamouse_preferred()
with LockModelTables(MAMTransTorrent):
try:
MAMTransTorrent.objects.get(info_hash=mam_torrent.info_hash)
raise TorrentAlreadyAddedException(u'Already added.')
except MAMTransTorrent.DoesNotExist:
pass
download_dir = os.path.join(location.path, unicode(mam_torrent.id))
def create_b_torrent():
new_b_torrent = MAMTransTorrent(
instance=instance,
location=location,
mam_torrent=mam_torrent,
info_hash=mam_torrent.info_hash,
)
new_b_torrent.save()
return new_b_torrent
if add_to_client:
with transaction.atomic():
b_torrent = create_b_torrent()
t_torrent = instance.client.add_torrent(
base64.b64encode(mam_torrent.torrent_file),
download_dir=download_dir,
paused=False
)
t_torrent = instance.client.get_torrent(
t_torrent.id, arguments=MAMTransTorrent.sync_t_arguments)
if not os.path.exists(download_dir):
os.mkdir(download_dir)
if not os.stat(download_dir).st_mode & 0777 == 0777:
os.chmod(download_dir, 0777)
norm_t_torrent(t_torrent)
b_torrent.sync_t_torrent(t_torrent)
else:
示例2: sync
# 需要导入模块: from home.models import ReplicaSet [as 别名]
# 或者: from home.models.ReplicaSet import get_myanonamouse_master [as 别名]
def sync(request):
start_time = time.time()
try:
master = ReplicaSet.get_myanonamouse_master()
trans_sync.sync_all_instances_db(master)
except Exception as ex:
tb = traceback.format_exc()
LogEntry.add(request.user, u'error', u'Error syncing MyAnonaMouse master DB: {0}({1})'
.format(type(ex).__name__, ex), tb)
return {
'success': False,
'error': unicode(ex),
'traceback': tb
}
time_taken = time.time() - start_time
LogEntry.add(request.user, u'info',
u'Completed MyAnonaMouse sync in {0:.3f}s.'
.format(time_taken))
return {
'success': True
}