本文整理匯總了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
}