Coverage for src/utils.py: 100%
11 statements
« prev ^ index » next coverage.py v7.3.0, created at 2024-11-20 12:27 +0000
« prev ^ index » next coverage.py v7.3.0, created at 2024-11-20 12:27 +0000
1import pathlib
4def pave_webroot(webroot: pathlib.Path | str) -> int:
5 """
6 Delete all old generated files from webroot
8 Returns the number of old files detected and destroyed. This is
9 so you have something interesting to log.
11 ```python
12 logger.info('paved %d old file(s) from webroot!', src.pave_webroot('./www'))
13 ```
14 """
16 webroot = pathlib.Path(webroot)
18 old_files = []
19 old_files += list(webroot.glob('*.html'))
20 old_files += list(webroot.glob('*.xml'))
21 old_files += list(webroot.glob('api/*.html'))
22 old_files += list(webroot.glob('api/*.js'))
24 for target in old_files:
25 target.unlink()
27 return len(old_files)