]> git.decadent.org.uk Git - dak.git/blob - daklib/regexes.py
Merge remote-tracking branch 'helmut/smallthings' into merge
[dak.git] / daklib / regexes.py
1 #!/usr/bin/env python
2 # vim:set et sw=4:
3
4 """
5 Central repository of regexes for dak
6
7 @contact: Debian FTP Master <ftpmaster@debian.org>
8 @copyright: 2001, 2002, 2003, 2004, 2005, 2006  James Troup <james@nocrew.org>
9 @copyright: 2009  Mark Hymers <mhy@debian.org>
10 @copyright: 2009, 2010  Joerg Jaspert <joerg@debian.org>
11 @license: GNU General Public License version 2 or later
12 """
13
14 # This program is free software; you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation; either version 2 of the License, or
17 # (at your option) any later version.
18
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 # GNU General Public License for more details.
23
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the Free Software
26 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
27
28 ###############################################################################
29
30 import re
31
32 #: Is it a number?
33 re_isanum = re.compile (r"^\d+$")
34
35 #: Looking for the default reply
36 re_default_answer = re.compile(r"\[(.*)\]")
37 #: Used in build_summaries to make changes output look better
38 re_fdnic = re.compile(r"\n\n")
39 #: Detect a binnmu
40 re_bin_only_nmu = re.compile(r"\+b\d+$")
41
42 #: To sort out comment lines
43 re_comments = re.compile(r"\#.*")
44 #: To ignore comment and whitespace lines.
45 re_whitespace_comment = re.compile(r"^\s*(#|$)")
46 re_no_epoch = re.compile(r"^\d+\:")
47 re_no_revision = re.compile(r"-[^-]+$")
48 re_arch_from_filename = re.compile(r"/binary-[^/]+/")
49 re_extract_src_version = re.compile (r"(\S+)\s*\((.*)\)")
50 re_isadeb = re.compile (r"(.+?)_(.+?)_(.+)\.u?deb$")
51
52 orig_source_ext_re = r"orig(?:-.+)?\.tar\.(?:gz|bz2|xz)"
53 re_orig_source_ext = re.compile(orig_source_ext_re + "$")
54 re_source_ext = re.compile("(" + orig_source_ext_re + r"|debian\.tar\.(?:gz|bz2|xz)|diff\.gz|tar\.(?:gz|bz2|xz)|dsc)$")
55 re_issource = re.compile(r"(.+)_(.+?)\." + re_source_ext.pattern)
56 re_is_orig_source = re.compile (r"(.+)_(.+?)\.orig(?:-.+)?\.tar\.(?:gz|bz2|xz)$")
57 #re_is_orig_source = re.compile (r"(.+)_(.+?)\.(?:orig\.)?tar\.(?:gz|bz2)$")
58
59 re_single_line_field = re.compile(r"^(\S*?)\s*:\s*(.*)")
60 re_multi_line_field = re.compile(r"^\s(.*)")
61 re_taint_free = re.compile(r"^[-+~/\.\w]+$")
62
63 re_parse_maintainer = re.compile(r"^\s*(\S.*\S)\s*\<([^\>]+)\>")
64
65 re_srchasver = re.compile(r"^(\S+)\s+\((\S+)\)$")
66 re_verwithext = re.compile(r"^(\d+)(?:\.(\d+))(?:\s+\((\S+)\))?$")
67
68 re_srchasver = re.compile(r"^(\S+)\s+\((\S+)\)$")
69
70 html_escaping = {'"':'&quot;', '&':'&amp;', '<':'&lt;', '>':'&gt;'}
71 re_html_escaping = re.compile('|'.join(map(re.escape, html_escaping.keys())))
72
73 # From clean_proposed_updates.py
74 re_isdeb = re.compile (r"^(.+)_(.+?)_(.+?).u?deb$")
75
76 # From examine_package.py
77 re_package = re.compile(r"^(.+?)_.*")
78 re_doc_directory = re.compile(r".*/doc/([^/]*).*")
79
80 re_contrib = re.compile('^contrib/')
81 re_nonfree = re.compile('^non\-free/')
82
83 re_localhost = re.compile("localhost\.localdomain")
84 re_version = re.compile('^(.*)\((.*)\)')
85
86 re_newlinespace = re.compile('\n')
87 re_spacestrip = re.compile('(\s)')
88
89 # From import_archive.py
90 re_arch_from_filename = re.compile(r"binary-[^/]+")
91
92 # From new_security_install.py
93 re_taint_free = re.compile(r"^['/;\-\+\.~\s\w]+$")
94
95 # From process_unchecked.py
96 re_valid_version = re.compile(r"^([0-9]+:)?[0-9A-Za-z\.\-\+:~]+$")
97 re_valid_pkg_name = re.compile(r"^[\dA-Za-z][\dA-Za-z\+\-\.]+$")
98 re_changelog_versions = re.compile(r"^\w[-+0-9a-z.]+ \([^\(\) \t]+\)")
99 re_strip_revision = re.compile(r"-([^-]+)$")
100 re_strip_srcver = re.compile(r"\s+\(\S+\)$")
101 re_spacestrip = re.compile('(\s)')
102
103 # From dak/rm.py
104 re_strip_source_version = re.compile (r'\s+.*$')
105 re_build_dep_arch = re.compile(r"\[[^]]+\]")
106
107 # From dak/transitions.py
108 re_broken_package = re.compile(r"[a-zA-Z]\w+\s+\-.*")
109
110 # From dak/add_user.py
111 re_gpg_fingerprint_colon = re.compile(r"^fpr:+(.*):$", re.MULTILINE);
112 # The next one is dirty
113 re_user_address = re.compile(r"^pub:.*<(.*)@.*>.*$", re.MULTILINE);
114 re_user_mails = re.compile(r"^(pub|uid):[^rdin].*<(.*@.*)>.*$", re.MULTILINE);
115 re_user_name = re.compile(r"^pub:.*:(.*)<.*$", re.MULTILINE);
116 re_re_mark = re.compile(r'^RE:')
117
118 re_parse_lintian = re.compile(r"^(?P<level>W|E|O): (?P<package>.*?): (?P<tag>[^ ]*) ?(?P<description>.*)$")
119
120 # in process-upload
121 re_match_expired = re.compile(r"^The key used to sign .+ has expired on .+$")
122
123 # in generate-releases
124 re_gensubrelease = re.compile (r".*/(binary-[0-9a-z-]+|source)$")
125 re_includeinrelease = re.compile (r"(Translation-[a-zA-Z_]+\.(?:bz2|xz)|Contents-[0-9a-z-]+.gz|Index|Packages(.gz|.bz2|.xz)?|Sources(.gz|.bz2|.xz)?|MD5SUMS|SHA256SUMS|Release)$")
126
127 # in generate_index_diffs
128 re_includeinpdiff = re.compile(r"(Translation-[a-zA-Z_]+\.(?:bz2|xz))")
129
130
131 ######################################################################
132 # Patterns matching filenames                                        #
133 ######################################################################
134
135 # Match safe filenames
136 re_file_safe = re.compile(r'^[a-zA-Z0-9][a-zA-Z0-9_.:~+-]*$')
137
138 # Prefix of binary and source filenames
139 _re_file_prefix = r'^(?P<package>[a-z0-9][a-z0-9.+-]+)_(?P<version>[A-Za-z0-9.:~+-]+?)'
140
141 # Match binary packages
142 # Groups: package, version, architecture, type
143 re_file_binary = re.compile(_re_file_prefix + r'_(?P<architecture>[a-z0-9-]+)\.(?P<type>u?deb)$')
144
145 # Match changes files
146 # Groups: package, version, suffix
147 re_file_changes = re.compile(_re_file_prefix + r'_(?P<suffix>[a-zA-Z0-9+-]+)\.changes$')
148
149 # Match dsc files
150 # Groups: package, version
151 re_file_dsc = re.compile(_re_file_prefix + r'\.dsc$')
152
153 # Match other source files
154 # Groups: package, version
155 re_file_source = re.compile(_re_file_prefix + r'(?:(?:\.orig(?:-[a-zA-Z0-9-]+)?|\.debian)?\.tar\.(?:bz2|gz|xz)|\.diff\.gz)$')
156
157 # Match upstream tarball
158 # Groups: package, version
159 re_file_orig = re.compile(_re_file_prefix + r'\.orig(?:-[a-zA-Z0-9-]+)?\.tar\.(?:bz2|gz|xz)')
160
161 ######################################################################
162 # Patterns matching fields                                           #
163 ######################################################################
164
165 # Match package name
166 re_field_package = re.compile(r'^[a-z0-9][a-z0-9.+-]+$')
167
168 # Match version
169 # Groups: without-epoch
170 re_field_version = re.compile(r'^(?:[0-9]+:)?(?P<without_epoch>[A-Za-z0-9.:~+-]+)$')
171
172 # Extract upstream version
173 # Groups: upstream
174 re_field_version_upstream = re.compile(r'^(?:[0-9]+:)?(?P<upstream>.*)-[^-]*$')
175
176 # Match source field
177 # Groups: package, version
178 re_field_source = re.compile(r'^(?P<package>[a-z0-9][a-z0-9.+-]+)(?:\s*\((?P<version>[A-Za-z0-9.:~+-]+)\))?$')