Пример #1
0
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):
                freeleech_add_torrent(request, master, what_id)
                added += 1

        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. '
                     u'{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
    }
Пример #2
0
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
    }
Пример #3
0
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):
                freeleech_add_torrent(request, master, what_id)
                added += 1

        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. "
            u"{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}