Coverage for src/debputy/plugin/debputy/discard_rules.py: 96%

34 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2024-04-07 12:14 +0200

1import re 

2 

3from debputy.plugin.api import VirtualPath 

4 

5_VCS_PATHS = { 

6 ".arch-inventory", 

7 ".arch-ids", 

8 ".be", 

9 ".bzrbackup", 

10 ".bzrignore", 

11 ".bzrtags", 

12 ".cvsignore", 

13 ".hg", 

14 ".hgignore", 

15 ".hgtags", 

16 ".hgsigs", 

17 ".git", 

18 ".gitignore", 

19 ".gitattributes", 

20 ".gitmodules", 

21 ".gitreview", 

22 ".mailmap", 

23 ".mtn-ignore", 

24 ".svn", 

25 "{arch}", 

26 "CVS", 

27 "RCS", 

28 "_MTN", 

29 "_darcs", 

30} 

31 

32_BACKUP_FILES_RE = re.compile( 

33 "|".join( 

34 [ 

35 # Common backup files 

36 r".*~", 

37 r".*[.](?:bak|orig|rej)", 

38 # Editor backup/swap files 

39 r"[.]#.*", 

40 r"[.].*[.]sw.", 

41 # Other known stuff 

42 r"[.]shelf", 

43 r",,.*", # "baz-style junk" (according to dpkg (Dpkg::Source::Package) 

44 r"DEADJOE", # Joe's one line of immortality that just gets cargo cult'ed around ... just in case. 

45 ] 

46 ) 

47) 

48 

49_DOXYGEN_DIR_TEST_FILES = ["doxygen.css", "doxygen.svg", "index.html"] 

50 

51 

52def _debputy_discard_pyc_files(path: "VirtualPath") -> bool: 

53 if path.name == "__pycache__" and path.is_dir: 

54 return True 

55 return path.name.endswith((".pyc", ".pyo")) and path.is_file 

56 

57 

58def _debputy_prune_la_files(path: "VirtualPath") -> bool: 

59 return ( 

60 path.name.endswith(".la") 

61 and path.is_file 

62 and path.absolute.startswith("/usr/lib") 

63 ) 

64 

65 

66def _debputy_prune_backup_files(path: VirtualPath) -> bool: 

67 return bool(_BACKUP_FILES_RE.match(path.name)) 

68 

69 

70def _debputy_prune_vcs_paths(path: VirtualPath) -> bool: 

71 return path.name in _VCS_PATHS 

72 

73 

74def _debputy_prune_info_dir_file(path: VirtualPath) -> bool: 

75 return path.absolute == "/usr/share/info/dir" 

76 

77 

78def _debputy_prune_binary_debian_dir(path: VirtualPath) -> bool: 

79 return path.absolute == "/DEBIAN" 

80 

81 

82def _debputy_prune_doxygen_cruft(path: VirtualPath) -> bool: 

83 if not path.name.endswith((".md5", ".map")) or not path.is_file: 

84 return False 

85 parent_dir = path.parent_dir 

86 while parent_dir: 86 ↛ 97line 86 didn't jump to line 97, because the condition on line 86 was never false

87 is_doxygen_dir = True 

88 for name in _DOXYGEN_DIR_TEST_FILES: 

89 test_file = parent_dir.get(name) 

90 if test_file is None or not test_file.is_file: 

91 is_doxygen_dir = False 

92 break 

93 

94 if is_doxygen_dir: 

95 return True 

96 parent_dir = parent_dir.parent_dir 

97 return False