Esempio n. 1
0
def test_save_load_jobs():
    jobs = [
        UrlJob(name='news', url='http://news.orf.at/'),
        ShellJob(name='list homedir', command='ls ~'),
        ShellJob(name='list proc', command='ls /proc'),
    ]

    with tempfile.NamedTemporaryFile() as tmp:
        UrlsYaml(tmp.name).save(jobs)
        jobs2 = UrlsYaml(tmp.name).load()
        os.chmod(tmp.name, 0o777)
        jobs3 = UrlsYaml(tmp.name).load_secure()

    assert len(jobs2) == len(jobs)
    # Assert that the shell jobs have been removed due to secure loading
    assert len(jobs3) == 1
Esempio n. 2
0
def main():
    config_file = os.path.join(urlwatch_dir, CONFIG_FILE)
    urls_file = os.path.join(urlwatch_dir, URLS_FILE)
    hooks_file = os.path.join(urlwatch_dir, HOOKS_FILE)
    new_cache_file = os.path.join(urlwatch_cache_dir, CACHE_FILE)
    old_cache_file = os.path.join(urlwatch_dir, CACHE_FILE)
    cache_file = new_cache_file
    if os.path.exists(old_cache_file) and not os.path.exists(new_cache_file):
        cache_file = old_cache_file

    command_config = CommandConfig(pkgname, urlwatch_dir, bindir, prefix,
                                   config_file, urls_file, hooks_file,
                                   cache_file, False)
    setup_logger(command_config.verbose)

    # setup storage API
    config_storage = YamlConfigStorage(command_config.config)
    cache_storage = CacheMiniDBStorage(command_config.cache)
    urls_storage = UrlsYaml(command_config.urls)

    # setup urlwatcher
    urlwatch = Urlwatch(command_config, config_storage, cache_storage,
                        urls_storage)
    urlwatch_command = UrlwatchCommand(urlwatch)

    # run urlwatcher
    urlwatch_command.run()
Esempio n. 3
0
def main():
    config_file = os.path.join(urlwatch_dir, CONFIG_FILE)
    urls_file = os.path.join(urlwatch_dir, URLS_FILE)
    hooks_file = os.path.join(urlwatch_dir, HOOKS_FILE)
    new_cache_file = os.path.join(urlwatch_cache_dir, CACHE_FILE)
    old_cache_file = os.path.join(urlwatch_dir, CACHE_FILE)
    cache_file = new_cache_file
    if os.path.exists(old_cache_file) and not os.path.exists(new_cache_file):
        cache_file = old_cache_file

    command_config = CommandConfig(sys.argv[1:], pkgname, urlwatch_dir, bindir,
                                   prefix, config_file, urls_file, hooks_file,
                                   cache_file, False)
    setup_logger(command_config.verbose)

    # setup storage API
    config_storage = YamlConfigStorage(command_config.config)

    if any(
            command_config.cache.startswith(prefix)
            for prefix in ('redis://', 'rediss://')):
        cache_storage = CacheRedisStorage(command_config.cache)
    else:
        cache_storage = CacheMiniDBStorage(command_config.cache)

    urls_storage = UrlsYaml(command_config.urls)

    # setup urlwatcher
    urlwatch = Urlwatch(command_config, config_storage, cache_storage,
                        urls_storage)
    urlwatch_command = UrlwatchCommand(urlwatch)

    # run urlwatcher
    urlwatch_command.run()
Esempio n. 4
0
def test_save_load_jobs():
    jobs = [
        UrlJob(name='news', url='http://news.orf.at/'),
        ShellJob(name='list homedir', command='ls ~'),
        ShellJob(name='list proc', command='ls /proc'),
    ]

    # tempfile.NamedTemporaryFile() doesn't work on Windows
    # because the returned file object cannot be opened again
    fd, name = tempfile.mkstemp()
    UrlsYaml(name).save(jobs)
    jobs2 = UrlsYaml(name).load()
    os.chmod(name, 0o777)
    jobs3 = UrlsYaml(name).load_secure()
    os.close(fd)
    os.remove(name)

    assert len(jobs2) == len(jobs)
    # Assert that the shell jobs have been removed due to secure loading
    if sys.platform != 'win32':
        assert len(jobs3) == 1
Esempio n. 5
0
def prepare_retry_test():
    urls = os.path.join(here, 'data', 'invalid-url.yaml')
    config = os.path.join(here, 'data', 'urlwatch.yaml')
    cache = os.path.join(here, 'data', 'cache.db')
    hooks = ''

    config_storage = YamlConfigStorage(config)
    cache_storage = CacheMiniDBStorage(cache)
    urls_storage = UrlsYaml(urls)

    urlwatch_config = ConfigForTest(config, urls, cache, hooks, True)
    urlwatcher = Urlwatch(urlwatch_config, config_storage, cache_storage, urls_storage)

    return urlwatcher, cache_storage
Esempio n. 6
0
def test_run_watcher():
    urls = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'share', 'urlwatch', 'examples', 'urls.yaml.example')
    config = os.path.join(os.path.dirname(__file__), 'data', 'urlwatch.yaml')
    cache = os.path.join(os.path.dirname(__file__), 'data', 'cache.db')
    hooks = ''

    config_storage = YamlConfigStorage(config)
    urls_storage = UrlsYaml(urls)
    cache_storage = CacheMiniDBStorage(cache)
    try:
        urlwatch_config = TestConfig(config, urls, cache, hooks, True)

        urlwatcher = Urlwatch(urlwatch_config, config_storage, cache_storage, urls_storage)
        urlwatcher.run_jobs()
    finally:
        cache_storage.close()
Esempio n. 7
0
def test_run_watcher():
    with teardown_func():
        urls = os.path.join(root, 'share', 'urlwatch', 'examples', 'urls.yaml.example')
        config = os.path.join(here, 'data', 'urlwatch.yaml')
        cache = os.path.join(here, 'data', 'cache.db')
        hooks = ''

        config_storage = YamlConfigStorage(config)
        urls_storage = UrlsYaml(urls)
        cache_storage = CacheMiniDBStorage(cache)
        try:
            urlwatch_config = ConfigForTest(config, urls, cache, hooks, True)

            urlwatcher = Urlwatch(urlwatch_config, config_storage, cache_storage, urls_storage)
            urlwatcher.run_jobs()
        finally:
            cache_storage.close()
Esempio n. 8
0
def test_load_urls_yaml():
    urls_yaml = 'share/urlwatch/examples/urls.yaml.example'
    if os.path.exists(urls_yaml):
        assert len(UrlsYaml(urls_yaml).load_secure()) > 0
Esempio n. 9
0
        root_logger.info('turning on verbose logging mode')


if __name__ == '__main__':
    config_file = os.path.join(urlwatch_dir, CONFIG_FILE)
    urls_file = os.path.join(urlwatch_dir, URLS_FILE)
    hooks_file = os.path.join(urlwatch_dir, HOOKS_FILE)
    new_cache_file = os.path.join(urlwatch_cache_dir, CACHE_FILE)
    old_cache_file = os.path.join(urlwatch_dir, CACHE_FILE)
    cache_file = new_cache_file
    if os.path.exists(old_cache_file) and not os.path.exists(new_cache_file):
        cache_file = old_cache_file

    command_config = CommandConfig(pkgname, urlwatch_dir, bindir, prefix,
                                   config_file, urls_file, hooks_file,
                                   cache_file, False)
    setup_logger(command_config.verbose)

    # setup storage API
    config_storage = YamlConfigStorage(command_config.config)
    cache_storage = CacheMiniDBStorage(command_config.cache)
    urls_storage = UrlsYaml(command_config.urls)

    # setup urlwatcher
    urlwatch = Urlwatch(command_config, config_storage, cache_storage,
                        urls_storage)
    urlwatch_command = UrlwatchCommand(urlwatch)

    # run urlwatcher
    urlwatch_command.run()