예제 #1
0
파일: cache.py 프로젝트: xareelee/pdm
def remove_cache_files(project: Project, pattern: str) -> None:
    if not pattern:
        raise PdmUsageError("Please provide a pattern")

    if pattern == "*":
        files = list(find_files(project.cache_dir, pattern))
    else:
        # Only remove wheel files which specific pattern is given
        files = list(find_files(project.cache("wheels"), pattern))

    if not files:
        raise PdmUsageError("No matching files found")

    for file in files:
        os.unlink(file)
        project.core.ui.echo(f"Removed {file}", verbosity=termui.DETAIL)
    project.core.ui.echo(f"{len(files)} file{'s' if len(files) > 1 else ''} removed")
예제 #2
0
    def handle(self, project: Project, options: argparse.Namespace) -> None:
        if not options.type:
            cache_parent = project.cache_dir
        elif options.type not in self.CACHE_TYPES:
            raise PdmUsageError(
                f"Invalid cache type {options.type}, should one of {self.CACHE_TYPES}"
            )
        else:
            cache_parent = project.cache(options.type)

        with project.core.ui.open_spinner(
                f"Clearing {options.type or 'all'} caches...") as spinner:
            files = list(find_files(cache_parent, "*"))
            for file in files:
                os.unlink(file)
            spinner.succeed(
                f"{len(files)} file{'s' if len(files) > 1 else ''} removed")
예제 #3
0
파일: cache.py 프로젝트: xareelee/pdm
    def handle(self, project: Project, options: argparse.Namespace) -> None:
        with project.core.ui.open_spinner("Calculating cache files"):
            output = [
                f"{termui.cyan('Cache Root')}: {project.cache_dir}, "
                f"Total size: {format_size(directory_size(project.cache_dir))}"
            ]
            for name, description in [
                ("hashes", "File Hashe Cache"),
                ("http", "HTTP Cache"),
                ("wheels", "Wheels Cache"),
                ("metadata", "Metadata Cache"),
            ]:
                cache_location = project.cache(name)
                files = list(find_files(cache_location, "*"))
                size = directory_size(cache_location)
                output.append(f"  {termui.cyan(description)}: {cache_location}")
                output.append(f"    Files: {len(files)}, Size: {format_size(size)}")

        project.core.ui.echo("\n".join(output))
예제 #4
0
 def handle(self, project: Project, options: argparse.Namespace) -> None:
     rows = []
     for file in find_files(project.cache("wheels"), options.pattern):
         rows.append((format_size(file_size(file)), os.path.basename(file)))
     project.core.ui.display_columns(rows, [">Size", "Filename"])
예제 #5
0
 def _clear_files(root: Path) -> int:
     files = find_files(root.as_posix(), "*")
     for file in files:
         os.unlink(file)
     return len(files)