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


Python ReplicaSet.get_what_master方法代码示例

本文整理汇总了Python中home.models.ReplicaSet.get_what_master方法的典型用法代码示例。如果您正苦于以下问题:Python ReplicaSet.get_what_master方法的具体用法?Python ReplicaSet.get_what_master怎么用?Python ReplicaSet.get_what_master使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在home.models.ReplicaSet的用法示例。


在下文中一共展示了ReplicaSet.get_what_master方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: sync_replicas

# 需要导入模块: from home.models import ReplicaSet [as 别名]
# 或者: from home.models.ReplicaSet import get_what_master [as 别名]
def sync_replicas(request):
    start_time = time.time()
    part_start_time = time.time()

    master = ReplicaSet.get_what_master()
    try:
        for replica_set in ReplicaSet.objects.all():
            if replica_set.id != master.id:
                trans_sync.sync_all_instances_db(request, replica_set)
        replicas_dbs_time = time.time() - part_start_time
    except Exception as ex:
        tb = traceback.format_exc()
        LogEntry.add(request.user, u"error", u"Error syncing replicas DB: {0}".format(ex), tb)
        return {"success": False, "error": unicode(ex), "traceback": tb}

    try:
        trans_sync.sync_all_replicas_to_master()
    except Exception as ex:
        tb = traceback.format_exc()
        LogEntry.add(request.user, u"error", u"Error running replica sync: {0}".format(ex), tb)
        return {"success": False, "error": unicode(ex), "traceback": tb}
    time_taken = time.time() - start_time

    LogEntry.add(
        request.user,
        u"info",
        u"Completed replica sync in {0:.3f}s. DB in {1:.3f}s.".format(time_taken, replicas_dbs_time),
    )
    return {"success": True}
开发者ID:valentine,项目名称:WhatManager2,代码行数:31,代码来源:views.py

示例2: download_torrent_group

# 需要导入模块: from home.models import ReplicaSet [as 别名]
# 或者: from home.models.ReplicaSet import get_what_master [as 别名]
def download_torrent_group(request, group_id):
    if not request.user.has_perm('home.add_whattorrent'):
        return {
            'success': False,
            'error': 'You don\'t have permission to add torrents. Talk to the administrator.',
        }
    try:
        torrent_group = WhatTorrentGroup.objects.get(id=group_id)
    except WhatTorrentGroup.DoesNotExist:
        torrent_group = WhatTorrentGroup.update_from_what(get_what_client(request), group_id)
    if torrent_group.torrents_json is None:
        torrent_group = WhatTorrentGroup.update_from_what(get_what_client(request), group_id)
    ids = get_ids_to_download(torrent_group)
    try:
        instance = ReplicaSet.get_what_master().get_preferred_instance()
        download_location = DownloadLocation.get_what_preferred()
        for torrent_id in ids:
            add_torrent(request, instance, download_location, torrent_id)
    except Exception as ex:
        return {
            'success': False,
            'error': unicode(ex),
            'traceback': traceback.format_exc(),
        }
    return {
        'success': True,
        'added': len(ids),
    }
开发者ID:ChaosTherum,项目名称:WhatManager2,代码行数:30,代码来源:views.py

示例3: add_torrent

# 需要导入模块: from home.models import ReplicaSet [as 别名]
# 或者: from home.models.ReplicaSet import get_what_master [as 别名]
def add_torrent(request):
    if not request.user.has_perm("home.add_whattorrent"):
        return {"success": False, "error": "You don't have permission to add torrents. Talk to the administrator."}

    try:
        if "dir" in request.POST:
            download_location = DownloadLocation.objects.get(zone=ReplicaSet.ZONE_WHAT, path=request.POST["dir"])
        else:
            download_location = DownloadLocation.get_what_preferred()
    except DownloadLocation.DoesNotExist:
        return {"success": False, "error": u"Download location does not exist."}

    if download_location.free_space_percent < MIN_FREE_DISK_SPACE:
        LogEntry.add(request.user, u"error", u"Failed to add torrent. Not enough disk space.")
        return {"success": False, "error": u"Not enough free space on disk."}

    try:
        what_id = int(request.POST["id"])
    except (ValueError, MultiValueDictKeyError):
        return {"success": False, "error": u"Invalid id"}

    instance = ReplicaSet.get_what_master().get_preferred_instance()

    try:
        if WhatTorrent.is_downloaded(request, what_id=what_id):
            m_torrent = TransTorrent.objects.filter(what_torrent_id=what_id)[0]
            raise TorrentAlreadyAddedException()
        m_torrent = manage_torrent.add_torrent(request, instance, download_location, what_id, True)
        m_torrent.what_torrent.added_by = request.user
        m_torrent.what_torrent.save()
    except TorrentAlreadyAddedException:
        LogEntry.add(request.user, u"info", u"Tried adding what_id={0}, already added.".format(what_id))
        what_torrent = WhatTorrent.get_or_none(request, what_id=what_id)
        result = {
            "success": False,
            "error_code": u"already_added",
            "error": u"Already added.",
            "torrent_id": m_torrent.what_torrent_id,
        }
        if m_torrent.what_torrent.info_category_id == 1:
            result["artist"] = what_torrent.info_artist if what_torrent else "<<< Unable to find torrent >>>"
            result["title"] = what_torrent.info_title if what_torrent else "<<< Unable to find torrent >>>"
        return result
    except Exception as ex:
        tb = traceback.format_exc()
        LogEntry.add(request.user, u"error", u"Tried adding what_id={0}. Error: {1}".format(what_id, unicode(ex)), tb)
        return {"success": False, "error": unicode(ex), "traceback": tb}

    tags = request.POST.get("tags")
    if tags:
        m_torrent.what_torrent.tags = tags
        m_torrent.what_torrent.save()

    LogEntry.add(request.user, u"action", u"Added {0} to {1}".format(m_torrent, m_torrent.instance))

    result = {"success": True}
    if m_torrent.what_torrent.info_category_id == 1:
        result["artist"] = (m_torrent.what_torrent.info_artist,)
        result["title"] = (m_torrent.what_torrent.info_title,)
    return result
开发者ID:valentine,项目名称:WhatManager2,代码行数:62,代码来源:views.py

示例4: handle

# 需要导入模块: from home.models import ReplicaSet [as 别名]
# 或者: from home.models.ReplicaSet import get_what_master [as 别名]
 def handle(self, *args, **options):
     if not self.check_args(args):
         print u'Pass the torrent data directory as a first argument, ' \
               u'a path to the .torrent file as a second.'
         return
     self.data_path, self.torrent_path = [wm_unicode(i) for i in args]
     with open(wm_str(self.torrent_path), 'rb') as f:
         self.torrent_info = bencode.bdecode(f.read())
     if options['base_dir']:
         self.data_path = os.path.join(self.data_path,
                                       wm_unicode(self.torrent_info['info']['name']))
     print u'Checking to see if torrent is already loaded into WM..'
     masters = list(ReplicaSet.get_what_master().transinstance_set.all())
     try:
         TransTorrent.objects.get(instance__in=masters, info_hash=self.info_hash)
         print u'Torrent already added to WM. Skipping...'
         return False
     except TransTorrent.DoesNotExist:
         pass
     self.what_torrent = WhatTorrent.get_or_create(self.pseudo_request, info_hash=self.info_hash)
     if not self.check_files():
         return
     self.move_files()
     print 'Adding torrent to WM...'
     manage_torrent.add_torrent(self.pseudo_request, self.trans_instance,
                                self.download_location, self.what_torrent.id)
     print 'Done!'
开发者ID:ChaosTherum,项目名称:WhatManager2,代码行数:29,代码来源:import_external_what_torrent.py

示例5: test_get_master

# 需要导入模块: from home.models import ReplicaSet [as 别名]
# 或者: from home.models.ReplicaSet import get_what_master [as 别名]
 def test_get_master(self):
     what_master = ReplicaSet.get_what_master()
     self.assertEqual(what_master.zone, ReplicaSet.ZONE_WHAT)
     self.assertEqual(what_master.name, 'master')
     bib_master = ReplicaSet.get_bibliotik_master()
     self.assertEqual(bib_master.zone, ReplicaSet.ZONE_BIBLIOTIK)
     self.assertEqual(bib_master.name, 'master')
开发者ID:ChaosTherum,项目名称:WhatManager2,代码行数:9,代码来源:tests.py

示例6: download_zip

# 需要导入模块: from home.models import ReplicaSet [as 别名]
# 或者: from home.models.ReplicaSet import get_what_master [as 别名]
def download_zip(request, what_id):
    t_torrent = None
    for instance in ReplicaSet.get_what_master().transinstance_set.all():
        try:
            t_torrent = TransTorrent.objects.get(instance=instance, what_torrent_id=what_id)
        except TransTorrent.DoesNotExist:
            pass
    if not t_torrent:
        return HttpResponse('Could not find that torrent.')

    torrent_file = [f for f in os.listdir(t_torrent.path) if '.torrent' in f]
    if len(torrent_file) == 1:
        torrent_file = os.path.splitext(torrent_file[0])[0]
    else:
        return HttpResponse('Not one .torrent in dir: ' + t_torrent.path)

    target_dir = os.path.join(t_torrent.path, t_torrent.torrent_name).encode('utf-8')
    torrent_files = []
    for root, rel_path, files in os.walk(target_dir):
        for file in files:
            rel_path = root.replace(target_dir, '')
            if rel_path.startswith('/') or rel_path.startswith('\\'):
                rel_path = rel_path[1:]
            rel_path = os.path.join(rel_path.encode('utf-8'), file)
            torrent_files.append((rel_path, os.path.join(root, file)))

    download_filename = '[{0}] {1}.zip'.format(what_id, torrent_file)

    response = download_zip_handler(download_filename, torrent_files)
    LogEntry.add(request.user, u'action', u'Downloaded {0} - {1}'.format(
        t_torrent, filesizeformat(response['Content-Length'])
    ))
    return response
开发者ID:davols,项目名称:WhatManager2,代码行数:35,代码来源:views.py

示例7: move_torrent_to_location

# 需要导入模块: from home.models import ReplicaSet [as 别名]
# 或者: from home.models.ReplicaSet import get_what_master [as 别名]
def move_torrent_to_location(request):
    what_id = int(request.GET["id"])
    new_location = DownloadLocation.objects.get(zone=ReplicaSet.ZONE_WHAT, path=request.GET["path"])
    what_torrent = WhatTorrent.objects.get(id=what_id)
    trans_torrent = TransTorrent.objects.get(
        instance__in=ReplicaSet.get_what_master().transinstance_set.all(), what_torrent=what_torrent
    )

    if trans_torrent.location.id == new_location.id:
        raise Exception("Torrent is already there.")

    print "Source is", trans_torrent.location.path
    print "Destination is", new_location.path
    print "Instance is", trans_torrent.instance.name
    print "Size is", trans_torrent.torrent_size
    print "Name is", trans_torrent.torrent_name

    client = trans_torrent.instance.client
    client.stop_torrent(trans_torrent.torrent_id)
    source_path = os.path.join(trans_torrent.location.path, unicode(what_torrent.id))
    shutil.move(source_path, new_location.path)
    client.move_torrent_data(trans_torrent.torrent_id, os.path.join(new_location.path, unicode(what_torrent.id)))
    trans_torrent.location = new_location
    trans_torrent.save()
    client.verify_torrent(trans_torrent.torrent_id)
    client.start_torrent(trans_torrent.torrent_id)
    return {"success": True}
开发者ID:valentine,项目名称:WhatManager2,代码行数:29,代码来源:views.py

示例8: remove_transmission_dupes

# 需要导入模块: from home.models import ReplicaSet [as 别名]
# 或者: from home.models.ReplicaSet import get_what_master [as 别名]
def remove_transmission_dupes(request):
    dupes = defaultdict(list)
    for instance in ReplicaSet.get_what_master().transinstance_set.all():
        for m_torrent in instance.transtorrent_set.all():
            dupes[m_torrent.what_torrent_id].append(instance.name + '/' + str(m_torrent.torrent_id))
            if len(dupes[m_torrent.what_torrent_id]) > 1:
                if 'remove' in request.GET:
                    instance.client.remove_torrent(m_torrent.torrent_id)
    return list(i for i in dupes.iteritems() if len(i[1]) > 1)
开发者ID:ChaosTherum,项目名称:WhatManager2,代码行数:11,代码来源:views.py

示例9: run_load_balance

# 需要导入模块: from home.models import ReplicaSet [as 别名]
# 或者: from home.models.ReplicaSet import get_what_master [as 别名]
def run_load_balance(request):
    torrent_count = int(request.GET["count"])
    source_instance = request.GET["source"]

    instance = TransInstance.objects.get(name=source_instance)
    for i in xrange(torrent_count):
        t = choice(instance.transtorrent_set.filter(torrent_uploaded=0))
        t = manage_torrent.move_torrent(t, ReplicaSet.get_what_master().get_preferred_instance())

    return {"success": True}
开发者ID:valentine,项目名称:WhatManager2,代码行数:12,代码来源:views.py

示例10: torrent_stats

# 需要导入模块: from home.models import ReplicaSet [as 别名]
# 或者: from home.models.ReplicaSet import get_what_master [as 别名]
def torrent_stats(request):
    what_buffer = 0
    try:
        what_buffer = WhatUserSnapshot.get_last().buffer_105
    except WhatUserSnapshot.DoesNotExist:
        pass
    data = {
        'master': ReplicaSet.get_what_master(),
        'buffer': what_buffer,
    }
    return render(request, 'home/part_ui/torrent_stats.html', data)
开发者ID:ChaosTherum,项目名称:WhatManager2,代码行数:13,代码来源:parts.py

示例11: __init__

# 需要导入模块: from home.models import ReplicaSet [as 别名]
# 或者: from home.models.ReplicaSet import get_what_master [as 别名]
 def __init__(self):
     super(Command, self).__init__()
     self.pseudo_request = lambda: None
     self.trans_instance = ReplicaSet.get_what_master().get_preferred_instance()
     self.download_location = DownloadLocation.get_what_preferred()
     self.data_path = None
     self.torrent_path = None
     self.torrent_info = None
     self.info_hash = None
     self.dest_path = None
     self.what_torrent = None
开发者ID:ChaosTherum,项目名称:WhatManager2,代码行数:13,代码来源:import_external_what_torrent.py

示例12: error_torrents

# 需要导入模块: from home.models import ReplicaSet [as 别名]
# 或者: from home.models.ReplicaSet import get_what_master [as 别名]
def error_torrents(request):
    error_torrents = []
    error_torrents.extend(TransTorrent.objects.filter(
        instance__in=ReplicaSet.get_what_master().transinstance_set.all()
    ).exclude(torrent_error=0).prefetch_related('what_torrent'))
    error_torrents.extend(BibliotikTransTorrent.objects.filter(
        instance__in=ReplicaSet.get_bibliotik_master().transinstance_set.all()
    ).exclude(torrent_error=0).prefetch_related('bibliotik_torrent'))
    data = {
        'torrents': error_torrents
    }
    return render(request, 'home/part_ui/error_torrents.html', data)
开发者ID:ChaosTherum,项目名称:WhatManager2,代码行数:14,代码来源:parts.py

示例13: update_freeleech

# 需要导入模块: from home.models import ReplicaSet [as 别名]
# 或者: from home.models.ReplicaSet import get_what_master [as 别名]
def update_freeleech(request):
    start_time = time.time()

    added = 0
    total_bytes = 0
    total_torrents = 0
    try:
        master = ReplicaSet.get_what_master()
        what_client = get_what_client(request)
        for what_id, what_group, what_torrent in what_client.get_free_torrent_ids():
            total_bytes += what_torrent['size']
            total_torrents += 1
            if not WhatTorrent.is_downloaded(request, what_id=what_id):
                download_locations = DownloadLocation.objects.filter(zone=ReplicaSet.ZONE_WHAT)
                download_locations = [l for l in download_locations if l.free_space_percent >= MIN_FREE_DISK_SPACE]
                if len(download_locations) == 0:
                    LogEntry.add(request.user, u'error',
                                 u'Unable to update freeleech: not enough space on disk.')
                    return {
                        'success': False,
                        'error': u'Not enough free space on disk.'
                    }
                download_location = choice(download_locations)

                instance = master.get_preferred_instance()
                m_torrent = manage_torrent.add_torrent(request, instance, download_location, what_id, True)
                m_torrent.what_torrent.tags = 'seed'
                m_torrent.what_torrent.added_by = request.user
                m_torrent.what_torrent.save()
                added += 1

                LogEntry.add(request.user, u'action',
                             u'Added freeleech {0} to {1} - {2}'.format(m_torrent, m_torrent.instance,
                                                                        download_location.path))

        log_type = u'action' if added > 0 else u'info'

        if added >= FREELEECH_EMAIL_THRESHOLD and socket.gethostname() == FREELEECH_HOSTNAME:
            send_freeleech_email(u'Added {0} freeleech torrents'.format(added))

        time_taken = time.time() - start_time
        LogEntry.add(request.user, log_type,
                     u'Successfully updated freeleech in {0:.3f}s. {1} added. {2} / {3} torrents total.'.format(
                         time_taken, added, filesizeformat(total_bytes), total_torrents))
    except Exception as ex:
        tb = traceback.format_exc()
        LogEntry.add(request.user, u'error',
                     u'Error updating freeleech: {0}({1})'.format(type(ex).__name__, unicode(ex)), tb)

    return {
        'success': True,
        'added': added
    }
开发者ID:jimrollenhagen,项目名称:WhatManager2,代码行数:55,代码来源:views.py

示例14: handle

# 需要导入模块: from home.models import ReplicaSet [as 别名]
# 或者: from home.models.ReplicaSet import get_what_master [as 别名]
 def handle(self, *args, **options):
     print 'Initiating what client...'
     what = get_what_client(dummy_request, True)
     index_response = what.request('index')
     print 'Status:', index_response['status']
     print 'Scanning replica sets...'
     try:
         ReplicaSet.objects.get(zone='what.cd')
         raise Exception('Please delete your what.cd replica set now')
     except ReplicaSet.DoesNotExist:
         pass
     try:
         pth_replica_set = ReplicaSet.get_what_master()
         if pth_replica_set.transinstance_set.count() < 1:
             raise ReplicaSet.DoesNotExist()
     except ReplicaSet.DoesNotExist:
         raise Exception('Please get your PTH replica set ready')
     print 'Scanning locations...'
     location_mapping = {}
     with open('what_manager2_torrents.jsonl', 'rb') as torrents_input:
         for line in torrents_input:
             data = ujson.loads(line)
             location_path = data['location']['path']
             if location_path not in location_mapping:
                 try:
                     new_location = DownloadLocationEquivalent.objects.get(
                         old_location=location_path).new_location
                 except DownloadLocationEquivalent.DoesNotExist:
                     new_location = raw_input(
                         'Enter the new location to map to {}: '.format(location_path))
                     DownloadLocationEquivalent.objects.create(
                         old_location=location_path,
                         new_location=new_location,
                     )
                 location_mapping[location_path] = new_location
     print 'Location mappings:'
     for old_location, new_location in location_mapping.items():
         try:
             DownloadLocation.objects.get(zone='redacted.ch', path=new_location)
         except DownloadLocation.DoesNotExist:
             raise Exception(
                 'Please create the {} location in the DB in zone redacted.ch'.format(
                     new_location))
         print old_location, '=', new_location
     with open('what_manager2_torrents.jsonl', 'rb') as torrents_input:
         for line in torrents_input:
             data = ujson.loads(line)
             migration_job = TorrentMigrationJob(what, location_mapping, data,
                                                 flac_only=options['flac_only'])
             migration_job.process()
开发者ID:karamanolev,项目名称:WhatManager2,代码行数:52,代码来源:perform_pth_mass_upload.py

示例15: do_pop

# 需要导入模块: from home.models import ReplicaSet [as 别名]
# 或者: from home.models.ReplicaSet import get_what_master [as 别名]
def do_pop(request):
    download_location = DownloadLocation.get_what_preferred()
    if download_location.free_space_percent < MIN_FREE_DISK_SPACE:
        LogEntry.add(request.user, u'error', u'Failed to add torrent. Not enough disk space.')
        return {
            'success': False,
            'error': u'Not enough free space on disk.'
        }

    front = QueueItem.get_front()
    if not front:
        return {
            'success': False,
            'message': 'Queue is empty.'
        }

    instance = ReplicaSet.get_what_master().get_preferred_instance()

    if WhatTorrent.is_downloaded(request, what_id=front.what_id):
        front.delete()
        return {
            'success': True,
            'message': 'Already added.'
        }

    try:
        m_torrent = manage_torrent.add_torrent(request, instance, download_location, front.what_id)
        m_torrent.what_torrent.added_by = request.user
        m_torrent.what_torrent.tags = 'seed project'
        m_torrent.what_torrent.save()

        front.delete()

        LogEntry.add(request.user, u'action', u'Popped {0} from queue.'.format(m_torrent))
    except Exception as ex:
        tb = traceback.format_exc()
        LogEntry.add(request.user, u'error',
                     u'Tried popping what_id={0} from queue. Error: {1}'.format(front.what_id,
                                                                                unicode(ex)), tb)
        return {
            'success': False,
            'error': unicode(ex),
            'traceback': tb
        }

    return {
        'success': True
    }
开发者ID:ChaosTherum,项目名称:WhatManager2,代码行数:50,代码来源:parts.py


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