예제 #1
0
파일: toolbox.py 프로젝트: Anidetrix/torrt
def get_registerd_torrents():
    """Returns hash-indexed dictionary with information on torrents
    registered for updates.

    :return: torrents dict
    :rtype: dict
    """
    return TorrtConfig.load()['torrents']
예제 #2
0
파일: toolbox.py 프로젝트: fsgrbv/torrt
def get_registerd_torrents():
    """Returns hash-indexed dictionary with information on torrents
    registered for updates.

    :return: torrents dict
    :rtype: dict
    """
    return TorrtConfig.load()['torrents']
예제 #3
0
파일: toolbox.py 프로젝트: Anidetrix/torrt
def unregister_torrent(hash_str):
    """Unregisters torrent from torrt. That doesn't remove torrent
    from torrent clients.

    :param hash_str: str - torrent identifying hash
    :return:
    """
    LOGGER.info('Unregistering `%s` torrent ...', hash_str)
    try:
        cfg = TorrtConfig.load()
        del cfg['torrents'][hash_str]
        TorrtConfig.save(cfg)
    except KeyError:
        pass  # Torrent was not known by torrt
예제 #4
0
파일: toolbox.py 프로젝트: fsgrbv/torrt
def unregister_torrent(hash_str):
    """Unregisters torrent from torrt. That doesn't remove torrent
    from torrent clients.

    :param hash_str: str - torrent identifying hash
    :return:
    """
    LOGGER.info('Unregistering `%s` torrent ...', hash_str)
    try:
        cfg = TorrtConfig.load()
        del cfg['torrents'][hash_str]
        TorrtConfig.save(cfg)
    except KeyError:
        pass  # Torrent was not known by torrt
예제 #5
0
파일: toolbox.py 프로젝트: ALTracer/torrt
def remove_notifier(alias):
    """Removes notifier by alias

    :param alias: str - Notifier alias to remove.

    :return:
    """
    LOGGER.info('Removing `%s` notifier ...', alias)
    try:
        cfg = TorrtConfig.load()
        del cfg['notifiers'][alias]
        TorrtConfig.save(cfg)
    except KeyError:
        pass
예제 #6
0
파일: toolbox.py 프로젝트: dmzkrsk/torrt
def remove_notifier(alias):
    """Removes notifier by alias

    :param alias: str - Notifier alias to remove.

    :return:
    """
    LOGGER.info('Removing `%s` notifier ...', alias)
    try:
        cfg = TorrtConfig.load()
        del cfg['notifiers'][alias]
        TorrtConfig.save(cfg)
    except KeyError:
        pass
예제 #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
파일: toolbox.py 프로젝트: dmzkrsk/torrt
def init_object_registries():
    """Initializes RPC and tracker objects registries with settings
    from configuration file.

    :return:
    """
    LOGGER.debug('Initializing objects registries from configuration file ...')
    cfg = TorrtConfig.load()

    settings_to_registry_map = {
        'rpc': RPCClassesRegistry,
        'trackers': TrackerClassesRegistry,
        'notifiers': NotifierClassesRegistry,
    }

    for settings_entry, registry_cls in settings_to_registry_map.items():
        for alias, settings in cfg[settings_entry].items():
            registry_obj = registry_cls.get(alias)
            registry_obj and registry_obj.spawn_with_settings(settings).register()
예제 #9
0
파일: toolbox.py 프로젝트: Anidetrix/torrt
def init_object_registries():
    """Initializes RPC and tracker objects registries with settings
    from configuration file.

    :return:
    """
    LOGGER.debug('Initializing objects registries from configuration file ...')
    cfg = TorrtConfig.load()

    for alias, rpc_settings in cfg['rpc'].items():
        rpc = RPCClassesRegistry.get(alias)
        if rpc is not None:
            obj = rpc.spawn_with_settings(rpc_settings)
            obj.register()

    for domain, tracker_settings in cfg['trackers'].items():
        tracker = TrackerClassesRegistry.get(domain)
        if tracker is not None:
            obj = tracker.spawn_with_settings(tracker_settings)
            obj.register()
예제 #10
0
파일: toolbox.py 프로젝트: fsgrbv/torrt
def init_object_registries():
    """Initializes RPC and tracker objects registries with settings
    from configuration file.

    :return:
    """
    LOGGER.debug('Initializing objects registries from configuration file ...')
    cfg = TorrtConfig.load()

    for alias, rpc_settings in cfg['rpc'].items():
        rpc = RPCClassesRegistry.get(alias)
        if rpc is not None:
            obj = rpc.spawn_with_settings(rpc_settings)
            obj.register()

    for domain, tracker_settings in cfg['trackers'].items():
        tracker = TrackerClassesRegistry.get(domain)
        if tracker is not None:
            obj = tracker.spawn_with_settings(tracker_settings)
            obj.register()