Coverage for src/gitlabracadabra/packages/package_file.py: 97%

31 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-03-10 17:02 +0100

1# 

2# Copyright (C) 2019-2025 Mathieu Parent <math.parent@gmail.com> 

3# 

4# This program is free software: you can redistribute it and/or modify 

5# it under the terms of the GNU Lesser General Public License as published by 

6# the Free Software Foundation, either version 3 of the License, or 

7# (at your option) any later version. 

8# 

9# This program is distributed in the hope that it will be useful, 

10# but WITHOUT ANY WARRANTY; without even the implied warranty of 

11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

12# GNU Lesser General Public License for more details. 

13# 

14# You should have received a copy of the GNU Lesser General Public License 

15# along with this program. If not, see <http://www.gnu.org/licenses/>. 

16 

17from __future__ import annotations 

18 

19 

20class PackageFile: 

21 """Package file.""" 

22 

23 def __init__( 

24 self, 

25 url: str, 

26 package_type: str, 

27 package_name: str, 

28 package_version: str | None = None, 

29 file_name: str | None = None, 

30 *, 

31 metadata: dict[str, str] | None = None, 

32 ) -> None: 

33 """Initialize an package file object. 

34 

35 Args: 

36 url: Package URL. 

37 package_type: Package type. 

38 package_name: Package name. 

39 package_version: Package version. 

40 file_name: Package file name. 

41 metadata: Package file metadata. 

42 """ 

43 self._url = url 

44 self._package_type = package_type 

45 self._package_name = package_name 

46 self._package_version = package_version or "0" 

47 self._file_name = file_name or url.split("/").pop() 

48 self._metadata = metadata or {} 

49 

50 @property 

51 def url(self) -> str: 

52 """Get URL. 

53 

54 Returns: 

55 Package file's source URL. 

56 """ 

57 return self._url 

58 

59 @property 

60 def package_type(self) -> str: 

61 """Get package type. 

62 

63 Returns: 

64 Package type. 

65 """ 

66 return self._package_type 

67 

68 @property 

69 def package_name(self) -> str: 

70 """Get package name. 

71 

72 Returns: 

73 Package name. 

74 """ 

75 return self._package_name 

76 

77 @property 

78 def package_version(self) -> str: 

79 """Get package version. 

80 

81 Returns: 

82 Package version. 

83 """ 

84 return self._package_version 

85 

86 @property 

87 def file_name(self) -> str: 

88 """Get package file name. 

89 

90 Returns: 

91 Package file name. 

92 """ 

93 return self._file_name 

94 

95 @property 

96 def metadata(self) -> dict[str, str]: 

97 """Get package file metadata. 

98 

99 Returns: 

100 Package file metadata. 

101 """ 

102 return self._metadata 

103 

104 def __eq__(self, other: object) -> bool: 

105 """Test equality. 

106 

107 Args: 

108 other: Item to compare with. 

109 

110 Returns: 

111 True if all attributes match. 

112 """ 

113 return self.__dict__ == other.__dict__ 

114 

115 def __repr__(self) -> str: 

116 """Representation. 

117 

118 Returns: 

119 String representation of the package file. 

120 """ 

121 return str(self.__dict__)