当前位置: 首页>>代码示例>>Python>>正文


Python ReplicaSet.get_myanonamouse_master方法代码示例

本文整理汇总了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:
开发者ID:ChaosTherum,项目名称:WhatManager2,代码行数:50,代码来源:manage_mam.py

示例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
    }
开发者ID:ChaosTherum,项目名称:WhatManager2,代码行数:25,代码来源:views.py


注:本文中的home.models.ReplicaSet.get_myanonamouse_master方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。