예제 #1
0
파일: toolbox.py 프로젝트: fsgrbv/torrt
def set_walk_interval(interval_hours):
    """Sets torrent updates checks interval (in hours).

    :param interval_hours: int - hours interval
    :return:
    """
    TorrtConfig.update({'walk_interval_hours': int(interval_hours)})
예제 #2
0
파일: toolbox.py 프로젝트: Anidetrix/torrt
def set_walk_interval(interval_hours):
    """Sets torrent updates checks interval (in hours).

    :param interval_hours: int - hours interval
    :return:
    """
    TorrtConfig.update({'walk_interval_hours': int(interval_hours)})
예제 #3
0
파일: toolbox.py 프로젝트: Anidetrix/torrt
def toggle_rpc(alias, enabled=True):
    """Enables or disables a given RPC.

    :param alias: str - PRC alias
    :param enabled: bool - flag to enable or disable
    :return:
    """
    rpc = RPCClassesRegistry.get(alias)
    if rpc is not None:
        TorrtConfig.update({'rpc': {alias: {'enabled': enabled}}})
        LOGGER.info('RPC `%s` enabled = %s', alias, enabled)
    else:
        LOGGER.info('RPC `%s` class is not registered', alias)
예제 #4
0
파일: toolbox.py 프로젝트: fsgrbv/torrt
def toggle_rpc(alias, enabled=True):
    """Enables or disables a given RPC.

    :param alias: str - PRC alias
    :param enabled: bool - flag to enable or disable
    :return:
    """
    rpc = RPCClassesRegistry.get(alias)
    if rpc is not None:
        TorrtConfig.update({'rpc': {alias: {'enabled': enabled}}})
        LOGGER.info('RPC `%s` enabled = %s', alias, enabled)
    else:
        LOGGER.info('RPC `%s` class is not registered', alias)
예제 #5
0
파일: toolbox.py 프로젝트: Anidetrix/torrt
def register_torrent(hash_str, torrent_data=None):
    """Registers torrent within torrt. Used to register torrents that already exists
    in torrent clients.

    :param hash_str: str - torrent identifying hash
    :param torrent_data: dict
    :return:
    """
    LOGGER.info('Registering `%s` torrent ...', hash_str)
    if torrent_data is None:
        torrent_data = {}
    cfg = {'torrents': {}}
    structure_torrent_data(cfg['torrents'], hash_str, torrent_data)
    TorrtConfig.update(cfg)
예제 #6
0
파일: toolbox.py 프로젝트: fsgrbv/torrt
def register_torrent(hash_str, torrent_data=None):
    """Registers torrent within torrt. Used to register torrents that already exists
    in torrent clients.

    :param hash_str: str - torrent identifying hash
    :param torrent_data: dict
    :return:
    """
    LOGGER.info('Registering `%s` torrent ...', hash_str)
    if torrent_data is None:
        torrent_data = {}
    cfg = {'torrents': {}}
    structure_torrent_data(cfg['torrents'], hash_str, torrent_data)
    TorrtConfig.update(cfg)
예제 #7
0
파일: toolbox.py 프로젝트: dmzkrsk/torrt
def walk(forced=False, silent=False, remove_outdated=True):
    """Performs updates check for the registered torrents.

    :param forced: bool - flag to not to count walk interval setting
    :param silent: bool - flag to suppress possible exceptions
    :param remove_outdated: bool - flag to remove torrents that are superseded by a new ones
    :return:
    """
    LOGGER.info('Torrent walk is triggered')
    now = int(time())
    cfg = TorrtConfig.load()
    next_time = cfg['time_last_check'] + (cfg['walk_interval_hours'] * 3600)
    if forced or now >= next_time:
        LOGGER.info('Torrent walk is started')

        updated = {}
        try:
            updated = update_torrents(cfg['torrents'].keys(), remove_outdated=remove_outdated)
        except TorrtException as e:
            if not silent:
                raise
            else:
                LOGGER.error('Walk failed. Reason: %s', e.message)

        new_cfg = {
            'time_last_check': now
        }

        if updated:
            for old_hash, new_data in updated.items():
                del cfg['torrents'][old_hash]
                cfg['torrents'][new_data['hash']] = new_data
            new_cfg['torrents'] = cfg['torrents']
            for _, notifier in iter_notifiers():
                notifier.send(updated)

        # Save updated torrents data into config.
        TorrtConfig.update(new_cfg)

        LOGGER.info('Torrent walk is finished')
    else:
        LOGGER.info(
            'Torrent walk postponed till %s (now %s)',
            get_iso_from_timestamp(next_time),
            get_iso_from_timestamp(now)
        )
예제 #8
0
def register_torrent(hash_str, torrent_data=None, url=None):
    """Registers torrent within torrt. Used to register torrents that already exists
    in torrent clients.

    :param hash_str: str - torrent identifying hash
    :param torrent_data: dict
    :param url: fallback url that will be used in case torrent comment doesn't contain url
    :return:
    """
    LOGGER.debug('Registering `%s` torrent ...', hash_str)
    if torrent_data is None:
        torrent_data = {}
    if url:
        torrent_data['url'] = url
    cfg = {'torrents': {}}
    structure_torrent_data(cfg['torrents'], hash_str, torrent_data)
    TorrtConfig.update(cfg)