Ejemplo n.º 1
0
def _cached_path(args: argparse.Namespace):
    logger.info("Cache directory: %s", args.cache_dir)
    if args.inspect:
        if args.extract_archive or args.force_extract or args.remove:
            raise RuntimeError(
                "cached-path cannot accept --extract-archive, --force-extract, or --remove "
                "options when --inspect flag is used.")
        inspect_cache(patterns=args.resources, cache_dir=args.cache_dir)
    elif args.remove:
        if args.extract_archive or args.force_extract or args.inspect:
            raise RuntimeError(
                "cached-path cannot accept --extract-archive, --force-extract, or --inspect "
                "options when --remove flag is used.")
        if not args.resources:
            raise RuntimeError(
                "Missing positional argument(s) 'resources'. 'resources' is required when using "
                "the --remove option. If you really want to remove everything, pass '*' for 'resources'."
            )
        reclaimed_space = remove_cache_entries(args.resources,
                                               cache_dir=args.cache_dir)
        print(f"Reclaimed {format_size(reclaimed_space)} of space")
    else:
        for resource in args.resources:
            print(
                cached_path(
                    resource,
                    cache_dir=args.cache_dir,
                    extract_archive=args.extract_archive,
                    force_extract=args.force_extract,
                ))
Ejemplo n.º 2
0
    def test_inspect_with_patterns(self, capsys):
        self.create_cache_entry("http://fake.datastore.com/glove.txt.gz",
                                "etag-1")
        self.create_cache_entry("http://fake.datastore.com/glove.txt.gz",
                                "etag-2")
        self.create_cache_entry("http://other.fake.datastore.com/glove.txt.gz",
                                "etag-4")

        inspect_cache(cache_dir=self.TEST_DIR, patterns=["http://fake.*"])

        captured = capsys.readouterr()
        assert "http://fake.datastore.com/glove.txt.gz" in captured.out
        assert "2 versions" in captured.out
        assert "http://other.fake.datastore.com/glove.txt.gz" not in captured.out
Ejemplo n.º 3
0
    def test_inspect(self, capsys):
        self.create_cache_entry("http://fake.datastore.com/glove.txt.gz",
                                "etag-1")
        self.create_cache_entry("http://fake.datastore.com/glove.txt.gz",
                                "etag-2")
        self.create_cache_entry("http://fake.datastore.com/glove.txt.gz",
                                "etag-3",
                                as_extraction_dir=True)

        inspect_cache(cache_dir=self.TEST_DIR)

        captured = capsys.readouterr()
        assert "http://fake.datastore.com/glove.txt.gz" in captured.out
        assert "2 versions cached" in captured.out
        assert "1 version extracted" in captured.out