Coverage for dak/make_pkg_file_mapping.py: 95%

33 statements  

« prev     ^ index     » next       coverage.py v7.6.0, created at 2026-08-03 16:46 +0000

1""" 

2Prints out, for every file in the pool, which source package and version it 

3belongs to and for binary packages additionally which arch, binary package 

4and binary package version it has in a standard rfc2822-like format. 

5 

6@contact: Debian FTP Master <ftpmaster@debian.org> 

7@copyright: 2009 Peter Palfrader <peter@palfrader.org> 

8@license: GNU General Public License version 2 or later 

9""" 

10 

11# This program is free software; you can redistribute it and/or modify 

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

13# the Free Software Foundation; either version 2 of the License, or 

14# (at your option) any later version. 

15# 

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

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

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

19# GNU General Public License for more details. 

20# 

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

22# along with this program; if not, write to the Free Software 

23# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 

24 

25 

26################################################################################ 

27 

28# <arma> it's crypto -- think of it like magic if you like. 

29 

30################################################################################ 

31 

32import sys 

33 

34from sqlalchemy import select, sql 

35 

36from daklib.dbconn import Archive, DBConn 

37 

38################################################################################ 

39 

40 

41def build_mapping(archive, session): 

42 # The ORDER BY is in the queries so that compression of the output works 

43 # better. It's the difference between a 9 megabyte bzip2 and a 2.5 mb 

44 # bzip2 file. 

45 

46 query_sources = """ 

47 SELECT 

48 source.source, 

49 source.version, 

50 './pool/' || component.name || '/' || files.filename AS path 

51 FROM source 

52 JOIN dsc_files ON source.id=dsc_files.source 

53 JOIN files ON files.id=dsc_files.file 

54 JOIN files_archive_map ON files.id = files_archive_map.file_id 

55 JOIN component ON files_archive_map.component_id = component.id 

56 JOIN files_archive_map fam_dsc ON fam_dsc.file_id=source.file AND fam_dsc.component_id=component.id AND fam_dsc.archive_id=files_archive_map.archive_id 

57 WHERE files_archive_map.archive_id = :archive_id 

58 ORDER BY source, version, component.id, files.filename 

59 """ 

60 

61 query_binaries = """ 

62 SELECT 

63 source.source, 

64 source.version, 

65 architecture.arch_string AS arch, 

66 './pool/' || component.name || '/' || files.filename AS path, 

67 binaries.package, 

68 binaries.version AS bin_version 

69 FROM source 

70 JOIN binaries ON source.id=binaries.source 

71 JOIN files ON binaries.file=files.id 

72 JOIN files_archive_map ON files.id = files_archive_map.file_id 

73 JOIN component ON files_archive_map.component_id = component.id 

74 JOIN architecture ON architecture.id=binaries.architecture 

75 WHERE files_archive_map.archive_id = :archive_id 

76 ORDER BY source, version, package, bin_version 

77 """ 

78 

79 for row in session.execute( 

80 sql.text(query_sources), {"archive_id": archive.archive_id} 

81 ).fetchall(): 

82 (source, version, path) = row 

83 print("Path: %s" % path) 

84 print("Source: %s" % source) 

85 print("Source-Version: %s" % version) 

86 print() 

87 

88 for row in session.execute( 

89 sql.text(query_binaries), {"archive_id": archive.archive_id} 

90 ).fetchall(): 

91 (source, version, arch, path, bin, binv) = row 

92 print("Path: %s" % path) 

93 print("Source: %s" % source) 

94 print("Source-Version: %s" % version) 

95 print("Architecture: %s" % arch) 

96 print("Binary: %s" % bin) 

97 print("Binary-Version: %s" % binv) 

98 print() 

99 

100 

101################################################################################ 

102 

103 

104def usage(status=0): 

105 print("usage: dak make-pkg-file-mapping <archive>") 

106 sys.exit(status) 

107 

108 

109################################################################################ 

110 

111 

112def main(): 

113 if len(sys.argv) != 2: 113 ↛ 114line 113 didn't jump to line 114 because the condition on line 113 was never true

114 usage(1) 

115 elif sys.argv[1] in ("-h", "--help"): 

116 usage(0) 

117 

118 archive_name = sys.argv[1] 

119 

120 session = DBConn().session() 

121 archive = session.execute( 

122 select(Archive).filter_by(archive_name=archive_name) 

123 ).scalar_one() 

124 build_mapping(archive, session)