From 2c639c40c65966711c82d46a6f4ee8739e819aad Mon Sep 17 00:00:00 2001 From: Mark Hymers Date: Sat, 24 Jan 2009 18:27:22 +0000 Subject: [PATCH] Move regexes into a module so we can keep track Rather than scatter regexes all over the place (for things which should probably be functions hiding the implementation detail anyways such as "is this a valid package version"), move them into daklib.regexes. I'm not convinced this is an immediate win, but I think it's one step on a long road... Oh, and it's untested Signed-off-by: Mark Hymers --- dak/clean_proposed_updates.py | 5 +- dak/examine_package.py | 19 +------ dak/import_archive.py | 7 +-- dak/import_ldap_fingerprints.py | 4 +- dak/new_security_install.py | 6 +- dak/poolize.py | 3 +- dak/process_unchecked.py | 8 +-- dak/rm.py | 6 +- dak/show_deferred.py | 3 +- dak/transitions.py | 5 +- daklib/queue.py | 8 +-- daklib/regexes.py | 98 +++++++++++++++++++++++++++++++++ daklib/utils.py | 24 +------- 13 files changed, 116 insertions(+), 80 deletions(-) create mode 100644 daklib/regexes.py diff --git a/dak/clean_proposed_updates.py b/dak/clean_proposed_updates.py index 3dd6e6f3..76a2778c 100755 --- a/dak/clean_proposed_updates.py +++ b/dak/clean_proposed_updates.py @@ -19,10 +19,11 @@ ################################################################################ -import os, pg, re, sys +import os, pg, sys import apt_pkg from daklib import database from daklib import utils +from daklib.regexes import re_isdeb ################################################################################ @@ -31,8 +32,6 @@ projectB = None Options = None pu = {} -re_isdeb = re.compile (r"^(.+)_(.+?)_(.+?).u?deb$") - ################################################################################ def usage (exit_code=0): diff --git a/dak/examine_package.py b/dak/examine_package.py index 49d18dc6..b2366de7 100755 --- a/dak/examine_package.py +++ b/dak/examine_package.py @@ -36,24 +36,7 @@ import errno, os, pg, re, sys, md5 import apt_pkg, apt_inst from daklib import database from daklib import utils - -################################################################################ - -re_package = re.compile(r"^(.+?)_.*") -re_doc_directory = re.compile(r".*/doc/([^/]*).*") - -re_contrib = re.compile('^contrib/') -re_nonfree = re.compile('^non\-free/') - -re_arch = re.compile("Architecture: .*") -re_builddep = re.compile("Build-Depends: .*") -re_builddepind = re.compile("Build-Depends-Indep: .*") - -re_localhost = re.compile("localhost\.localdomain") -re_version = re.compile('^(.*)\((.*)\)') - -re_newlinespace = re.compile('\n') -re_spacestrip = re.compile('(\s)') +from daklib.regexes import * ################################################################################ diff --git a/dak/import_archive.py b/dak/import_archive.py index 53635e2a..8728158e 100755 --- a/dak/import_archive.py +++ b/dak/import_archive.py @@ -36,15 +36,12 @@ ############################################################################### -import commands, os, pg, re, sys, time +import commands, os, pg, sys, time import apt_pkg from daklib import database from daklib import utils from daklib.dak_exceptions import * - -############################################################################### - -re_arch_from_filename = re.compile(r"binary-[^/]+") +from daklib.regexes import re_arch_from_filename ############################################################################### diff --git a/dak/import_ldap_fingerprints.py b/dak/import_ldap_fingerprints.py index 4cc8aa01..610e4a82 100755 --- a/dak/import_ldap_fingerprints.py +++ b/dak/import_ldap_fingerprints.py @@ -48,15 +48,13 @@ import commands, ldap, pg, re, sys import apt_pkg from daklib import database from daklib import utils +from daklib.regexes import re_gpg_fingerprint, re_debian_address ################################################################################ Cnf = None projectB = None -re_gpg_fingerprint = re.compile(r"^\s+Key fingerprint = (.*)$", re.MULTILINE) -re_debian_address = re.compile(r"^.*<(.*)@debian\.org>$", re.MULTILINE) - ################################################################################ def usage(exit_code=0): diff --git a/dak/new_security_install.py b/dak/new_security_install.py index 856428e0..98951d41 100755 --- a/dak/new_security_install.py +++ b/dak/new_security_install.py @@ -20,13 +20,13 @@ ################################################################################ +import apt_pkg, os, sys, pwd, time, commands + from daklib import queue from daklib import logging from daklib import utils from daklib import database -import apt_pkg, os, sys, pwd, time, re, commands - -re_taint_free = re.compile(r"^['/;\-\+\.~\s\w]+$"); +from daklib.regexes import re_taint_free Cnf = None Options = None diff --git a/dak/poolize.py b/dak/poolize.py index 5b7ffbf6..6b4752e1 100644 --- a/dak/poolize.py +++ b/dak/poolize.py @@ -29,14 +29,13 @@ import os, pg, re, stat, sys import apt_pkg, apt_inst import daklib.database import daklib.utils +from daklib.regexes import re_isadeb ################################################################################ Cnf = None projectB = None -re_isadeb = re.compile (r"(.+?)_(.+?)(_(.+))?\.u?deb$") - ################################################################################ def usage (exit_code=0): diff --git a/dak/process_unchecked.py b/dak/process_unchecked.py index 737472af..faffd530 100755 --- a/dak/process_unchecked.py +++ b/dak/process_unchecked.py @@ -35,17 +35,13 @@ from daklib import logging from daklib import queue from daklib import utils from daklib.dak_exceptions import * +from daklib.regexes import re_valid_version, re_valid_pkg_name, re_changelog_versions, \ + re_strip_revision, re_strip_srcver, re_spacestrip from types import * ################################################################################ -re_valid_version = re.compile(r"^([0-9]+:)?[0-9A-Za-z\.\-\+:~]+$") -re_valid_pkg_name = re.compile(r"^[\dA-Za-z][\dA-Za-z\+\-\.]+$") -re_changelog_versions = re.compile(r"^\w[-+0-9a-z.]+ \([^\(\) \t]+\)") -re_strip_revision = re.compile(r"-([^-]+)$") -re_strip_srcver = re.compile(r"\s+\(\S+\)$") -re_spacestrip = re.compile('(\s)') ################################################################################ diff --git a/dak/rm.py b/dak/rm.py index c2c5fa48..9c761554 100755 --- a/dak/rm.py +++ b/dak/rm.py @@ -44,11 +44,7 @@ import apt_pkg, apt_inst from daklib import database from daklib import utils from daklib.dak_exceptions import * - -################################################################################ - -re_strip_source_version = re.compile (r'\s+.*$') -re_build_dep_arch = re.compile(r"\[[^]]+\]") +from daklib.regexes import re_strip_source_version, re_build_dep_arch ################################################################################ diff --git a/dak/show_deferred.py b/dak/show_deferred.py index 833cad28..6942efbd 100755 --- a/dak/show_deferred.py +++ b/dak/show_deferred.py @@ -27,6 +27,7 @@ from debian_bundle import deb822 from daklib import database from daklib import queue from daklib import utils +from daklib.regexes import re_htmlescaping, html_escaping ################################################################################ ### work around bug #487902 in debian-python 0.1.10 @@ -40,8 +41,6 @@ deb822.Changes._multivalued_fields = { row_number = 1 -html_escaping = {'"':'"', '&':'&', '<':'<', '>':'>'} -re_html_escaping = re.compile('|'.join(map(re.escape, html_escaping.keys()))) def html_escape(s): return re_html_escaping.sub(lambda x: html_escaping.get(x.group(0)), s) diff --git a/dak/transitions.py b/dak/transitions.py index b7e50651..7c47f880 100755 --- a/dak/transitions.py +++ b/dak/transitions.py @@ -23,11 +23,12 @@ ################################################################################ -import os, pg, sys, time, errno, fcntl, tempfile, pwd, re +import os, pg, sys, time, errno, fcntl, tempfile, pwd import apt_pkg from daklib import database from daklib import utils from daklib.dak_exceptions import TransitionsError +from daklib.regexes import re_broken_package import yaml # Globals @@ -35,8 +36,6 @@ Cnf = None Options = None projectB = None -re_broken_package = re.compile(r"[a-zA-Z]\w+\s+\-.*") - ################################################################################ ##################################### diff --git a/daklib/queue.py b/daklib/queue.py index 09831f4d..6d68af4f 100755 --- a/daklib/queue.py +++ b/daklib/queue.py @@ -24,18 +24,12 @@ import cPickle, errno, os, pg, re, stat, sys, time import apt_inst, apt_pkg import utils, database from dak_exceptions import * +from regexes import re_isanum, re_default_answer, re_fdnic, re_bin_only_nmu from types import * ############################################################################### -re_isanum = re.compile (r"^\d+$") -re_default_answer = re.compile(r"\[(.*)\]") -re_fdnic = re.compile(r"\n\n") -re_bin_only_nmu = re.compile(r"\+b\d+$") - -################################################################################ - # Determine what parts in a .changes are NEW def determine_new(changes, files, projectB, warn=1): diff --git a/daklib/regexes.py b/daklib/regexes.py new file mode 100644 index 00000000..3001c4be --- /dev/null +++ b/daklib/regexes.py @@ -0,0 +1,98 @@ +#!/usr/bin/env python +# vim:set et sw=4: + +# Queue utility functions for dak +# Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 James Troup +# Copyright (C) 2009 Mark Hymers + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +############################################################################### + +import re + +re_isanum = re.compile (r"^\d+$") +re_default_answer = re.compile(r"\[(.*)\]") +re_fdnic = re.compile(r"\n\n") +re_bin_only_nmu = re.compile(r"\+b\d+$") + +re_comments = re.compile(r"\#.*") +re_no_epoch = re.compile(r"^\d+\:") +re_no_revision = re.compile(r"-[^-]+$") +re_arch_from_filename = re.compile(r"/binary-[^/]+/") +re_extract_src_version = re.compile (r"(\S+)\s*\((.*)\)") +re_isadeb = re.compile (r"(.+?)_(.+?)_(.+)\.u?deb$") + +re_issource = re.compile (r"(.+)_(.+?)\.(orig\.tar\.gz|diff\.gz|tar\.gz|dsc)$") + +re_single_line_field = re.compile(r"^(\S*)\s*:\s*(.*)") +re_multi_line_field = re.compile(r"^\s(.*)") +re_taint_free = re.compile(r"^[-+~/\.\w]+$") + +re_parse_maintainer = re.compile(r"^\s*(\S.*\S)\s*\<([^\>]+)\>") +re_gpg_uid = re.compile('^uid.*<([^>]*)>') + +re_srchasver = re.compile(r"^(\S+)\s+\((\S+)\)$") +re_verwithext = re.compile(r"^(\d+)(?:\.(\d+))(?:\s+\((\S+)\))?$") + +re_srchasver = re.compile(r"^(\S+)\s+\((\S+)\)$") + +html_escaping = {'"':'"', '&':'&', '<':'<', '>':'>'} +re_html_escaping = re.compile('|'.join(map(re.escape, html_escaping.keys()))) + +# From clean_proposed_updates.py +re_isdeb = re.compile (r"^(.+)_(.+?)_(.+?).u?deb$") + +# From examine_package.py +re_package = re.compile(r"^(.+?)_.*") +re_doc_directory = re.compile(r".*/doc/([^/]*).*") + +re_contrib = re.compile('^contrib/') +re_nonfree = re.compile('^non\-free/') + +re_arch = re.compile("Architecture: .*") +re_builddep = re.compile("Build-Depends: .*") +re_builddepind = re.compile("Build-Depends-Indep: .*") + +re_localhost = re.compile("localhost\.localdomain") +re_version = re.compile('^(.*)\((.*)\)') + +re_newlinespace = re.compile('\n') +re_spacestrip = re.compile('(\s)') + +# From import_archive.py +re_arch_from_filename = re.compile(r"binary-[^/]+") + +# From import_ldap_fingerprints.py +re_gpg_fingerprint = re.compile(r"^\s+Key fingerprint = (.*)$", re.MULTILINE) +re_debian_address = re.compile(r"^.*<(.*)@debian\.org>$", re.MULTILINE) + +# From new_security_install.py +re_taint_free = re.compile(r"^['/;\-\+\.~\s\w]+$") + +# From process_unchecked.py +re_valid_version = re.compile(r"^([0-9]+:)?[0-9A-Za-z\.\-\+:~]+$") +re_valid_pkg_name = re.compile(r"^[\dA-Za-z][\dA-Za-z\+\-\.]+$") +re_changelog_versions = re.compile(r"^\w[-+0-9a-z.]+ \([^\(\) \t]+\)") +re_strip_revision = re.compile(r"-([^-]+)$") +re_strip_srcver = re.compile(r"\s+\(\S+\)$") +re_spacestrip = re.compile('(\s)') + +# From dak/rm.py +re_strip_source_version = re.compile (r'\s+.*$') +re_build_dep_arch = re.compile(r"\[[^]]+\]") + +# From dak/transitions.py +re_broken_package = re.compile(r"[a-zA-Z]\w+\s+\-.*") diff --git a/daklib/utils.py b/daklib/utils.py index 83079483..78ee197f 100755 --- a/daklib/utils.py +++ b/daklib/utils.py @@ -28,32 +28,10 @@ import apt_pkg import database import time from dak_exceptions import * +from regexes import * ################################################################################ -re_comments = re.compile(r"\#.*") -re_no_epoch = re.compile(r"^\d+\:") -re_no_revision = re.compile(r"-[^-]+$") -re_arch_from_filename = re.compile(r"/binary-[^/]+/") -re_extract_src_version = re.compile (r"(\S+)\s*\((.*)\)") -re_isadeb = re.compile (r"(.+?)_(.+?)_(.+)\.u?deb$") -re_issource = re.compile (r"(.+)_(.+?)\.(orig\.tar\.gz|diff\.gz|tar\.gz|dsc)$") - -re_single_line_field = re.compile(r"^(\S*)\s*:\s*(.*)") -re_multi_line_field = re.compile(r"^\s(.*)") -re_taint_free = re.compile(r"^[-+~/\.\w]+$") - -re_parse_maintainer = re.compile(r"^\s*(\S.*\S)\s*\<([^\>]+)\>") -re_gpg_uid = re.compile('^uid.*<([^>]*)>') - -re_srchasver = re.compile(r"^(\S+)\s+\((\S+)\)$") -re_verwithext = re.compile(r"^(\d+)(?:\.(\d+))(?:\s+\((\S+)\))?$") - -re_srchasver = re.compile(r"^(\S+)\s+\((\S+)\)$") - -html_escaping = {'"':'"', '&':'&', '<':'<', '>':'>'} -re_html_escaping = re.compile('|'.join(map(re.escape, html_escaping.keys()))) - default_config = "/etc/dak/dak.conf" default_apt_config = "/etc/dak/apt.conf" -- 2.39.5