Coverage for src/utils.py: 100%

11 statements  

« prev     ^ index     » next       coverage.py v7.3.0, created at 2024-11-20 12:27 +0000

1import pathlib 

2 

3 

4def pave_webroot(webroot: pathlib.Path | str) -> int: 

5 """ 

6 Delete all old generated files from webroot 

7 

8 Returns the number of old files detected and destroyed. This is 

9 so you have something interesting to log. 

10 

11 ```python 

12 logger.info('paved %d old file(s) from webroot!', src.pave_webroot('./www')) 

13 ``` 

14 """ 

15 

16 webroot = pathlib.Path(webroot) 

17 

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')) 

23 

24 for target in old_files: 

25 target.unlink() 

26 

27 return len(old_files)