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


Python models.ReplicaSet类代码示例

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


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

示例1: test_get_master

 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,代码行数:7,代码来源:tests.py

示例2: error_torrents

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,代码行数:12,代码来源:parts.py

示例3: refresh_oldest_torrent

def refresh_oldest_torrent(request):
    bibliotik_id = request.GET['bibliotik_id']
    bibliotik_client = BibliotikClient(bibliotik_id)
    most_recent = BibliotikTorrent.objects.defer('torrent_file').order_by('retrieved')[0]
    most_recent_id = most_recent.id
    try:
        most_recent.import_bibliotik_data(bibliotik_client)
    except Exception as ex:
        try:
            BibliotikTransTorrent.objects.get(instance__in=ReplicaSet.get_bibliotik_master().transinstance_set.all(),
                                              bibliotik_torrent=most_recent)
            return {
                'success': False,
                'id': most_recent_id,
                'status': 'request error',
            }
        except BibliotikTransTorrent.DoesNotExist:
            most_recent.delete()
            return {
                'success': True,
                'id': most_recent_id,
                'status': 'deleted',
            }

    old_retrieved = most_recent.retrieved
    most_recent.retrieved = timezone.now()
    most_recent.save()
    return {
        'success': True,
        'id': most_recent_id,
        'status': 'refreshed',
        'retrieved': unicode(old_retrieved),
    }
开发者ID:jimrollenhagen,项目名称:WhatManager2,代码行数:33,代码来源:maintenance_views.py

示例4: sync_replicas

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,代码行数:29,代码来源:views.py

示例5: move_torrent_to_location

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,代码行数:27,代码来源:views.py

示例6: download_bibliotik_zip

def download_bibliotik_zip(request, bibliotik_id):
    b_torrent = None
    for instance in ReplicaSet.get_bibliotik_master().transinstance_set.all():
        try:
            b_torrent = BibliotikTransTorrent.objects.get(instance=instance,
                                                          bibliotik_torrent_id=bibliotik_id)
        except BibliotikTransTorrent.DoesNotExist:
            pass
    if not b_torrent:
        return HttpResponse('Could not find that torrent.')

    torrent_files = []
    for root, rel_path, files in os.walk(b_torrent.path):
        for file in files:
            assert root.find(b_torrent.path) != -1
            rel_path = root.replace(b_torrent.path, '')
            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 = u'[{0}] {1}.zip'.format(bibliotik_id, b_torrent.torrent_name)

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

示例7: add_torrent

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,代码行数:60,代码来源:views.py

示例8: handle

 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,代码行数:27,代码来源:import_external_what_torrent.py

示例9: download_zip

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,代码行数:33,代码来源:views.py

示例10: download_torrent_group

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,代码行数:28,代码来源:views.py

示例11: downloading

def downloading(request):
    downloading = []
    for m_torrent in TransTorrent.objects.filter(
            instance__in=ReplicaSet.get_what_master().transinstance_set.all(),
            torrent_done__lt=1).prefetch_related('what_torrent'):
        m_torrent.sync_t_torrent()
        downloading.append(m_torrent)
    for b_torrent in BibliotikTransTorrent.objects.filter(
            instance__in=ReplicaSet.get_bibliotik_master().transinstance_set.all(),
            torrent_done__lt=1
    ).prefetch_related('bibliotik_torrent'):
        b_torrent.sync_t_torrent()
        downloading.append(b_torrent)
    downloading.sort(key=lambda t: t.torrent_date_added)
    data = {
        'torrents': downloading
    }
    return render(request, 'home/part_ui/downloading.html', data)
开发者ID:ChaosTherum,项目名称:WhatManager2,代码行数:18,代码来源:parts.py

示例12: remove_transmission_dupes

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,代码行数:9,代码来源:views.py

示例13: files_sync

    def files_sync(self):
        check_running()

        print 'Running initial rsync...'
        self.call_rsyncs()

        print 'Iterating instances...'
        current_torrents = {}
        best_instance = None
        for instance in ReplicaSet.get_bibliotik_master().transinstance_set.all():
            t_torrents = instance.get_t_torrents(TransTorrentBase.sync_t_arguments)
            if best_instance is None or len(t_torrents) < best_instance[0]:
                best_instance = (len(t_torrents), instance)
            for t_torrent in t_torrents:
                part = t_torrent.downloadDir.rpartition('/')
                current_torrents[int(part[2])] = {
                    'download_dir': part[0],
                }

        new_torrents = {}
        print 'Iterating locations...'
        for location in DownloadLocation.objects.filter(zone=ReplicaSet.ZONE_BIBLIOTIK):
            for i in os.listdir(location.path):
                torrent_id = int(i)
                if torrent_id not in current_torrents:
                    new_torrents[torrent_id] = {
                        'id': torrent_id,
                        'location': location,
                    }
                else:
                    del current_torrents[torrent_id]

        to_add = list()
        for batch_number, batch in enumerate(chunks(new_torrents.itervalues(), 100)):
            print 'Requests status for batch {0}...'.format(batch_number)
            batch_status = torrents_status(unicode(i['id']) for i in batch)
            for row in batch_status:
                if row['status'] == 'downloaded':
                    to_add.append(new_torrents[row['id']])

        print 'Running second rsync...'
        self.call_rsyncs()

        preferred_instance = best_instance[1]
        for row in to_add:
            print 'Downloading torrent {0}'.format(row['id'])
            torrent_file = get_torrent(row['id'])
            print 'Adding torrent {0}'.format(row['id'])
            t_torrent = preferred_instance.client.add_torrent(
                base64.b64encode(torrent_file),
                download_dir=os.path.join(str(row['location'].path), str(row['id'])),
                paused=False
            )
            monitor_torrent(preferred_instance.client, t_torrent.id)

        print 'Completed.'
开发者ID:ChaosTherum,项目名称:WhatManager2,代码行数:56,代码来源:transmission_files_sync.py

示例14: run_load_balance

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,代码行数:10,代码来源:views.py

示例15: torrent_stats

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,代码行数:11,代码来源:parts.py


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