def get_file_count(path: Path, glob: str) -> int: """ Return the count of files in a folder :param path: A path to a folder to check :param glob: The glob pattern :return: Number of files counted """ if path.exists() and path.is_dir(): return sum([1 for f in path.glob(glob) if f.is_file()]) else: return 0
def clean_project(self, project_dir: Path): log.info('Looking for artifacts to clean in project %s. ...', project_dir) for glob in self.args.artifacts: for artifact in project_dir.glob(glob): if artifact.is_dir(): if self.args.dry_run: log.info(' Would recursively remove directory %s', artifact) else: log.info(' Recursively removing directory %s', artifact) shutil.rmtree(artifact) else: if self.args.dry_run: log.info(' Would remove file %s', artifact) else: log.info(' Removing file %s', artifact) artifact.unlink()