1# vim:set et sw=4: 

2 

3""" 

4Central repository of regexes for dak 

5 

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

7@copyright: 2001, 2002, 2003, 2004, 2005, 2006 James Troup <james@nocrew.org> 

8@copyright: 2009 Mark Hymers <mhy@debian.org> 

9@copyright: 2009, 2010 Joerg Jaspert <joerg@debian.org> 

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

11""" 

12 

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

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

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

16# (at your option) any later version. 

17 

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

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

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

21# GNU General Public License for more details. 

22 

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

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

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

26 

27############################################################################### 

28 

29import re 

30 

31#: Is it a number? 

32re_isanum = re.compile(r"^\d+$") 

33 

34#: Looking for the default reply 

35re_default_answer = re.compile(r"\[(.*)\]") 

36#: Detect a binnmu 

37re_bin_only_nmu = re.compile(r"\+b\d+$") 

38 

39#: To sort out comment lines 

40re_comments = re.compile(r"\#.*") 

41#: To ignore comment and whitespace lines. 

42re_whitespace_comment = re.compile(r"^\s*(#|$)") 

43re_no_epoch = re.compile(r"^\d+\:") 

44re_extract_src_version = re.compile(r"(\S+)\s*\((.*)\)") 

45re_isadeb = re.compile(r"(.+?)_(.+?)_(.+)\.u?deb$") 

46 

47orig_source_ext_re = r"orig(?:-[a-zA-Z0-9-]+)?\.tar\.(?:gz|bz2|xz)(?:\.asc)?" 

48file_source_ext_re = "(" + orig_source_ext_re + r"|(?:debian\.)?tar\.(?:gz|bz2|xz)|diff\.gz)" 

49re_source_ext = re.compile("(" + file_source_ext_re + r"|dsc)$") 

50re_issource = re.compile(r"(.+)_(.+?)\." + re_source_ext.pattern) 

51 

52re_single_line_field = re.compile(r"^(\S*?)\s*:\s*(.*)") 

53re_multi_line_field = re.compile(r"^\s(.*)") 

54re_taint_free = re.compile(r"^[-+~/\.\w]+$") 

55 

56re_parse_maintainer = re.compile(r"^\s*(\S.*\S)\s*\<([^\>]+)\>") 

57 

58re_srchasver = re.compile(r"^(\S+)\s+\((\S+)\)$") 

59re_verwithext = re.compile(r"^(\d+)(?:\.(\d+))(?:\s+\((\S+)\))?$") 

60 

61# From clean_proposed_updates.py 

62re_isdeb = re.compile(r"^(.+)_(.+?)_(.+?).u?deb$") 

63 

64# From examine_package.py 

65re_package = re.compile(r"^(.+?)_.*") 

66re_doc_directory = re.compile(r".*/doc/([^/]*).*") 

67 

68re_contrib = re.compile('^contrib/') 

69re_nonfree = re.compile('^(?:non-free-firmware|non-free)/') 

70 

71re_localhost = re.compile(r"localhost\.localdomain") 

72re_version = re.compile(r'^(.*)\((.*)\)') 

73 

74re_newlinespace = re.compile('\n') 

75re_spacestrip = re.compile(r'(\s)') 

76 

77# From new_security_install.py 

78re_taint_free = re.compile(r"^['/;\-\+\.~\s\w]+$") 

79 

80# From process_unchecked.py 

81re_changelog_versions = re.compile(r"^\w[-+0-9a-z.]+ \([^\(\) \t]+\)") 

82 

83# From dak/rm.py 

84re_strip_source_version = re.compile(r'\s+.*$') 

85re_build_dep_arch = re.compile(r"\[[^]]+\]") 

86 

87# From dak/transitions.py 

88re_broken_package = re.compile(r"[a-zA-Z]\w+\s+\-.*") 

89 

90# From dak/add_user.py 

91re_gpg_fingerprint_colon = re.compile(r"^fpr:+(.*):$", re.MULTILINE) 

92# The next one is dirty 

93re_user_address = re.compile(r"^pub:.*<(.*)@.*>.*$", re.MULTILINE) 

94re_user_mails = re.compile(r"^(pub|uid):[^rdin].*<(.*@.*)>.*$", re.MULTILINE) 

95re_user_name = re.compile(r"^pub:.*:(.*)<.*$", re.MULTILINE) 

96re_re_mark = re.compile(r'^RE:') 

97 

98re_parse_lintian = re.compile(r"^(?P<level>W|E|O): (?P<package>.*?): (?P<tag>[^ ]*) ?(?P<description>.*)$") 

99 

100# in generate-releases 

101re_gensubrelease = re.compile(r".*/(binary-[0-9a-z-]+|source)$") 

102re_includeinrelease_byhash = re.compile(r"(Translation-[a-zA-Z_]+\.(?:bz2|xz|zst)|Contents-[0-9a-z-]+.gz|Index|Packages(.gz|.bz2|.xz|.zst)?|Sources(.gz|.bz2|.xz|.zst)?|Components-[0-9a-z-]+.yml(.gz|.xz)|icons-[0-9x-]+.tar(.gz|.xz)|Release)$") 

103re_includeinrelease_plain = re.compile(r"(MD5SUMS|SHA256SUMS)$") 

104 

105# in generate_index_diffs 

106re_includeinpdiff = re.compile(r"(Translation-[a-zA-Z_]+\.(?:bz2|xz|zst))") 

107 

108 

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

110# Patterns matching filenames # 

111###################################################################### 

112 

113# Match safe filenames 

114re_file_safe = re.compile(r'^[a-zA-Z0-9][a-zA-Z0-9_.~+-]*$') 

115 

116# Match safe filenames, including slashes 

117re_file_safe_slash = re.compile(r'^[a-zA-Z0-9][/a-zA-Z0-9_.~+-]*$') 

118 

119# Prefix of binary and source filenames 

120_re_file_prefix = r'^(?P<package>[a-z0-9][a-z0-9.+-]+)_(?P<version>[A-Za-z0-9.~+-]+?)' 

121 

122# Match binary packages 

123# Groups: package, version, architecture, type 

124re_file_binary = re.compile(_re_file_prefix + r'_(?P<architecture>[a-z0-9-]+)\.(?P<type>u?deb)$') 

125 

126# Match changes files 

127# Groups: package, version, suffix 

128re_file_changes = re.compile(_re_file_prefix + r'_(?P<suffix>[a-zA-Z0-9+-]+)\.changes$') 

129 

130# Match dsc files 

131# Groups: package, version 

132re_file_dsc = re.compile(_re_file_prefix + r'\.dsc$') 

133 

134# Match other source files 

135# Groups: package, version 

136re_file_source = re.compile(_re_file_prefix + r'\.' + file_source_ext_re) 

137 

138# Match upstream tarball 

139# Groups: package, version 

140re_file_orig = re.compile(_re_file_prefix + r'\.' + orig_source_ext_re) 

141 

142# Match buildinfo file 

143# Groups: package, version, suffix 

144re_file_buildinfo = re.compile(_re_file_prefix + r'_(?P<suffix>[a-zA-Z0-9+-]+)\.buildinfo$') 

145 

146###################################################################### 

147# Patterns matching fields # 

148###################################################################### 

149 

150# Match package name 

151re_field_package = re.compile(r'^[a-z0-9][a-z0-9.+-]+$') 

152 

153# Match version 

154# Groups: without-epoch 

155re_field_version = re.compile(r'^(?:[0-9]+:)?(?P<without_epoch>[A-Za-z0-9.:~+-]+)$') 

156 

157# Extract upstream version 

158# Groups: upstream 

159re_field_version_upstream = re.compile(r'^(?:[0-9]+:)?(?P<upstream>.*)-[^-]*$') 

160 

161# Match source field 

162# Groups: package, version 

163re_field_source = re.compile(r'^(?P<package>[a-z0-9][a-z0-9.+-]+)(?:\s*\((?P<version>[A-Za-z0-9.:~+-]+)\))?$')