From ba77095c326cc03fc5ab18423b874ff06e6fcdba Mon Sep 17 00:00:00 2001 From: Mark Hymers Date: Sat, 24 Jan 2009 19:09:51 +0000 Subject: [PATCH] Only import regexes we're using This is so that we have an idea of where we need what. Lots of these should be changed to be opaque functions, not exposing that they're internally regexes at all. Signed-off-by: Mark Hymers --- dak/check_archive.py | 3 ++- dak/check_proposed_updates.py | 3 ++- dak/clean_proposed_updates.py | 8 ++++---- dak/control_overrides.py | 3 ++- dak/cruft_report.py | 3 ++- dak/examine_package.py | 6 ++++-- dak/import_archive.py | 13 +++++++------ dak/make_maintainers.py | 3 ++- dak/poolize.py | 8 ++++---- dak/process_accepted.py | 7 ++++--- dak/process_new.py | 17 +++++++++-------- dak/process_unchecked.py | 34 ++++++++++++++++++---------------- dak/reject_proposed_updates.py | 5 +++-- dak/show_deferred.py | 2 +- daklib/queue.py | 2 +- daklib/utils.py | 4 +++- 16 files changed, 68 insertions(+), 53 deletions(-) diff --git a/dak/check_archive.py b/dak/check_archive.py index 33dc8481..26a85cb5 100755 --- a/dak/check_archive.py +++ b/dak/check_archive.py @@ -30,6 +30,7 @@ import commands, os, pg, stat, sys, time import apt_pkg, apt_inst from daklib import database from daklib import utils +from daklib.regexes import re_issource ################################################################################ @@ -287,7 +288,7 @@ def check_missing_tar_gz_in_dsc(): dsc_files = utils.build_file_list(dsc, is_a_dsc=1) has_tar = 0 for f in dsc_files.keys(): - m = utils.re_issource.match(f) + m = re_issource.match(f) if not m: utils.fubar("%s not recognised as source." % (f)) ftype = m.group(3) diff --git a/dak/check_proposed_updates.py b/dak/check_proposed_updates.py index afb0faae..05728ab8 100755 --- a/dak/check_proposed_updates.py +++ b/dak/check_proposed_updates.py @@ -32,6 +32,7 @@ import pg, sys, os import apt_pkg, apt_inst from daklib import database from daklib import utils +from daklib.regexes import re_no_epoch ################################################################################ @@ -91,7 +92,7 @@ def check_dep (depends, dep_type, check_archs, filename, files): unsat = 0 break # As part of the same .changes? - epochless_version = utils.re_no_epoch.sub('', version) + epochless_version = re_no_epoch.sub('', version) dep_filename = "%s_%s_%s.deb" % (dep, epochless_version, arch) if files.has_key(dep_filename): if Options["debug"]: diff --git a/dak/clean_proposed_updates.py b/dak/clean_proposed_updates.py index 76a2778c..b408184e 100755 --- a/dak/clean_proposed_updates.py +++ b/dak/clean_proposed_updates.py @@ -23,7 +23,7 @@ import os, pg, sys import apt_pkg from daklib import database from daklib import utils -from daklib.regexes import re_isdeb +from daklib.regexes import re_isdeb, re_isadeb, re_issource, re_no_epoch ################################################################################ @@ -55,7 +55,7 @@ def check_changes (filename): return num_files = len(files.keys()) for f in files.keys(): - if utils.re_isadeb.match(f): + if re_isadeb.match(f): m = re_isdeb.match(f) pkg = m.group(1) version = m.group(2) @@ -63,7 +63,7 @@ def check_changes (filename): if Options["debug"]: print "BINARY: %s ==> %s_%s_%s" % (f, pkg, version, arch) else: - m = utils.re_issource.match(f) + m = re_issource.match(f) if m: pkg = m.group(1) version = m.group(2) @@ -85,7 +85,7 @@ def check_changes (filename): # FIXME utils.warn("%s doesn't seem to exist for %s in %s?? (from %s [%s])" % (pkg, arch, Options["suite"], f, filename)) continue - pu_version = utils.re_no_epoch.sub('', pu[pkg][arch]) + pu_version = re_no_epoch.sub('', pu[pkg][arch]) if pu_version == version: if Options["verbose"]: print "%s: ok" % (f) diff --git a/dak/control_overrides.py b/dak/control_overrides.py index 0af5c48b..78ae68d4 100644 --- a/dak/control_overrides.py +++ b/dak/control_overrides.py @@ -54,6 +54,7 @@ import apt_pkg from daklib import utils from daklib import database from daklib import logging +from daklib.regexes import re_comments ################################################################################ @@ -118,7 +119,7 @@ def process_file (file, suite, component, type, action): start_time = time.time() projectB.query("BEGIN WORK") for line in file.readlines(): - line = utils.re_comments.sub('', line).strip() + line = re_comments.sub('', line).strip() if line == "": continue diff --git a/dak/cruft_report.py b/dak/cruft_report.py index 0f1125f8..f8695df7 100755 --- a/dak/cruft_report.py +++ b/dak/cruft_report.py @@ -31,6 +31,7 @@ import commands, pg, os, sys, time, re import apt_pkg from daklib import database from daklib import utils +from daklib.regexes import re_extract_src_version ################################################################################ @@ -456,7 +457,7 @@ def main (): bin2source[package]["version"] = version bin2source[package]["source"] = source if source.find("(") != -1: - m = utils.re_extract_src_version.match(source) + m = re_extract_src_version.match(source) source = m.group(1) version = m.group(2) if not bin_pkgs.has_key(package): diff --git a/dak/examine_package.py b/dak/examine_package.py index b2366de7..347eb52f 100755 --- a/dak/examine_package.py +++ b/dak/examine_package.py @@ -36,7 +36,9 @@ import errno, os, pg, re, sys, md5 import apt_pkg, apt_inst from daklib import database from daklib import utils -from daklib.regexes import * +from daklib.regexes import html_escaping, re_html_escaping, re_version, re_spacestrip, \ + re_contrib, re_nonfree, re_localhost, re_newlinespace, \ + re_package, re_doc_directory ################################################################################ @@ -71,7 +73,7 @@ PACKAGE can be a .changes, .dsc, .deb or .udeb filename.""" def escape_if_needed(s): if use_html: - return utils.re_html_escaping.sub(lambda x: utils.html_escaping.get(x.group(0)), s) + return re_html_escaping.sub(lambda x: html_escaping.get(x.group(0)), s) else: return s diff --git a/dak/import_archive.py b/dak/import_archive.py index 8728158e..00b5d1b6 100755 --- a/dak/import_archive.py +++ b/dak/import_archive.py @@ -41,7 +41,8 @@ import apt_pkg from daklib import database from daklib import utils from daklib.dak_exceptions import * -from daklib.regexes import re_arch_from_filename +from daklib.regexes import re_arch_from_filename, re_taint_free, re_no_epoch, \ + re_extract_src_version ############################################################################### @@ -91,7 +92,7 @@ def reject (str, prefix="Rejected: "): ############################################################################### def check_signature (filename): - if not utils.re_taint_free.match(os.path.basename(filename)): + if not re_taint_free.match(os.path.basename(filename)): reject("!!WARNING!! tainted filename: '%s'." % (filename)) return None @@ -329,12 +330,12 @@ def process_sources (filename, suite, component, archive): package = Scanner.Section["package"] version = Scanner.Section["version"] directory = Scanner.Section["directory"] - dsc_file = os.path.join(Cnf["Dir::Root"], directory, "%s_%s.dsc" % (package, utils.re_no_epoch.sub('', version))) + dsc_file = os.path.join(Cnf["Dir::Root"], directory, "%s_%s.dsc" % (package, re_no_epoch.sub('', version))) # Sometimes the Directory path is a lie; check in the pool if not os.path.exists(dsc_file): if directory.split('/')[0] == "dists": directory = Cnf["Dir::PoolRoot"] + utils.poolify(package, component) - dsc_file = os.path.join(Cnf["Dir::Root"], directory, "%s_%s.dsc" % (package, utils.re_no_epoch.sub('', version))) + dsc_file = os.path.join(Cnf["Dir::Root"], directory, "%s_%s.dsc" % (package, re_no_epoch.sub('', version))) if not os.path.exists(dsc_file): utils.fubar("%s not found." % (dsc_file)) install_date = time.strftime("%Y-%m-%d", time.localtime(os.path.getmtime(dsc_file))) @@ -352,7 +353,7 @@ def process_sources (filename, suite, component, archive): directory = poolify (directory, location) if directory != "" and not directory.endswith("/"): directory += '/' - no_epoch_version = utils.re_no_epoch.sub('', version) + no_epoch_version = re_no_epoch.sub('', version) # Add all files referenced by the .dsc to the files table ids = [] for line in Scanner.Section["files"].split('\n'): @@ -424,7 +425,7 @@ def process_packages (filename, suite, component, archive): source = Scanner.Section["source"] source_version = "" if source.find("(") != -1: - m = utils.re_extract_src_version.match(source) + m = re_extract_src_version.match(source) source = m.group(1) source_version = m.group(2) if not source_version: diff --git a/dak/make_maintainers.py b/dak/make_maintainers.py index 090b8d43..3f6fd4c5 100755 --- a/dak/make_maintainers.py +++ b/dak/make_maintainers.py @@ -29,6 +29,7 @@ import pg, sys import apt_pkg from daklib import database from daklib import utils +from daklib.regexes import re_comments ################################################################################ @@ -132,7 +133,7 @@ def main(): for filename in extra_files: file = utils.open_file(filename) for line in file.readlines(): - line = utils.re_comments.sub('', line).strip() + line = re_comments.sub('', line).strip() if line == "": continue split = line.split() diff --git a/dak/poolize.py b/dak/poolize.py index 6b4752e1..cefdcae9 100644 --- a/dak/poolize.py +++ b/dak/poolize.py @@ -29,7 +29,7 @@ import os, pg, re, stat, sys import apt_pkg, apt_inst import daklib.database import daklib.utils -from daklib.regexes import re_isadeb +from daklib.regexes import re_isadeb, re_extract_src_version, re_no_epoch, re_issource ################################################################################ @@ -83,17 +83,17 @@ def poolize (q, limit, verbose, no_action): package = control.Find("Package", "") source = control.Find("Source", package) if source.find("(") != -1: - m = daklib.utils.re_extract_src_version.match(source) + m = re_extract_src_version.match(source) source = m.group(1) # If it's a binary, we need to also rename the file to include the architecture version = control.Find("Version", "") architecture = control.Find("Architecture", "") if package == "" or version == "" or architecture == "": daklib.utils.fubar("%s: couldn't determine required information to rename .deb file." % (legacy_filename)) - version = daklib.utils.re_no_epoch.sub('', version) + version = re_no_epoch.sub('', version) destination_filename = "%s_%s_%s.deb" % (package, version, architecture) else: - m = daklib.utils.re_issource.match(base_filename) + m = re_issource.match(base_filename) if m: source = m.group(1) else: diff --git a/dak/process_accepted.py b/dak/process_accepted.py index ea238ef7..f066614f 100755 --- a/dak/process_accepted.py +++ b/dak/process_accepted.py @@ -36,6 +36,7 @@ from daklib import logging from daklib import queue from daklib import utils from daklib.dak_exceptions import * +from daklib.regexes import re_default_answer, re_issource, re_fdnic ############################################################################### @@ -220,7 +221,7 @@ def action (): while prompt.find(answer) == -1: answer = utils.our_raw_input(prompt) - m = queue.re_default_answer.match(prompt) + m = re_default_answer.match(prompt) if answer == "": answer = m.group(1) answer = answer[:1].upper() @@ -538,11 +539,11 @@ def stable_install (summary, short_summary): for file in files.keys(): if files[file]["type"] == "deb": new_changelog.write("stable/%s/binary-%s/%s\n" % (files[file]["component"], files[file]["architecture"], file)) - elif utils.re_issource.match(file): + elif re_issource.match(file): new_changelog.write("stable/%s/source/%s\n" % (files[file]["component"], file)) else: new_changelog.write("%s\n" % (file)) - chop_changes = queue.re_fdnic.sub("\n", changes["changes"]) + chop_changes = re_fdnic.sub("\n", changes["changes"]) new_changelog.write(chop_changes + '\n\n') if os.access(changelog_filename, os.R_OK) != 0: changelog = utils.open_file(changelog_filename) diff --git a/dak/process_new.py b/dak/process_new.py index 8a43f127..462a2e63 100755 --- a/dak/process_new.py +++ b/dak/process_new.py @@ -44,6 +44,7 @@ from daklib import database from daklib import logging from daklib import queue from daklib import utils +from daklib.regexes import re_no_epoch, re_default_answer, re_isanum # Globals Cnf = None @@ -82,7 +83,7 @@ def recheck(): source_package = files[f]["source package"] if not Upload.pkg.changes["architecture"].has_key("source") \ and not Upload.source_exists(source_package, source_version, Upload.pkg.changes["distribution"].keys()): - source_epochless_version = utils.re_no_epoch.sub('', source_version) + source_epochless_version = re_no_epoch.sub('', source_version) dsc_filename = "%s_%s.dsc" % (source_package, source_epochless_version) found = 0 for q in ["Accepted", "Embargoed", "Unembargoed"]: @@ -110,7 +111,7 @@ def recheck(): while prompt.find(answer) == -1: answer = utils.our_raw_input(prompt) - m = queue.re_default_answer.match(prompt) + m = re_default_answer.match(prompt) if answer == "": answer = m.group(1) answer = answer[:1].upper() @@ -365,7 +366,7 @@ def edit_index (new, index): while prompt.find(answer) == -1: answer = utils.our_raw_input(prompt) - m = queue.re_default_answer.match(prompt) + m = re_default_answer.match(prompt) if answer == "": answer = m.group(1) answer = answer[:1].upper() @@ -435,7 +436,7 @@ def edit_overrides (new): answer = answer[:1].upper() if answer == "E" or answer == "D": got_answer = 1 - elif queue.re_isanum.match (answer): + elif re_isanum.match (answer): answer = int(answer) if (answer < 1) or (answer > index): print "%s is not a valid index (%s). Please retry." % (answer, index_range(index)) @@ -472,7 +473,7 @@ def edit_note(note): answer = "XXX" while prompt.find(answer) == -1: answer = utils.our_raw_input(prompt) - m = queue.re_default_answer.search(prompt) + m = re_default_answer.search(prompt) if answer == "": answer = m.group(1) answer = answer[:1].upper() @@ -575,7 +576,7 @@ def prod_maintainer (): answer = "XXX" while prompt.find(answer) == -1: answer = utils.our_raw_input(prompt) - m = queue.re_default_answer.search(prompt) + m = re_default_answer.search(prompt) if answer == "": answer = m.group(1) answer = answer[:1].upper() @@ -662,7 +663,7 @@ def do_new(): while prompt.find(answer) == -1: answer = utils.our_raw_input(prompt) - m = queue.re_default_answer.search(prompt) + m = re_default_answer.search(prompt) if answer == "": answer = m.group(1) answer = answer[:1].upper() @@ -771,7 +772,7 @@ def do_byhand(): while prompt.find(answer) == -1: answer = utils.our_raw_input(prompt) - m = queue.re_default_answer.search(prompt) + m = re_default_answer.search(prompt) if answer == "": answer = m.group(1) answer = answer[:1].upper() diff --git a/dak/process_unchecked.py b/dak/process_unchecked.py index faffd530..28583c05 100755 --- a/dak/process_unchecked.py +++ b/dak/process_unchecked.py @@ -36,7 +36,9 @@ 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 + re_strip_revision, re_strip_srcver, re_spacestrip, \ + re_isanum, re_noepoch, re_norevision, re_taint_free, \ + re_isadeb, re_extract_src_version, re_issource from types import * @@ -242,13 +244,13 @@ def check_changes(): # Ensure all the values in Closes: are numbers if changes.has_key("closes"): for i in changes["closes"].keys(): - if queue.re_isanum.match (i) == None: + if re_isanum.match (i) == None: reject("%s: `%s' from Closes field isn't a number." % (filename, i)) # chopversion = no epoch; chopversion2 = no epoch and no revision (e.g. for .orig.tar.gz comparison) - changes["chopversion"] = utils.re_no_epoch.sub('', changes["version"]) - changes["chopversion2"] = utils.re_no_revision.sub('', changes["chopversion"]) + changes["chopversion"] = re_no_epoch.sub('', changes["version"]) + changes["chopversion2"] = re_no_revision.sub('', changes["chopversion"]) # Check there isn't already a changes file of the same name in one # of the queue directories. @@ -389,7 +391,7 @@ def check_files(): if not Cnf.has_key("Dir::Queue::%s" % (d)): continue if os.path.exists(Cnf["Dir::Queue::%s" % (d) ] + '/' + f): reject("%s file already exists in the %s directory." % (f, d)) - if not utils.re_taint_free.match(f): + if not re_taint_free.match(f): reject("!!WARNING!! tainted filename: '%s'." % (f)) # Check the file is readable if os.access(f, os.R_OK) == 0: @@ -407,7 +409,7 @@ def check_files(): files[f]["byhand"] = 1 files[f]["type"] = "byhand" # Checks for a binary package... - elif utils.re_isadeb.match(f): + elif re_isadeb.match(f): has_binaries = 1 files[f]["type"] = "deb" @@ -493,7 +495,7 @@ def check_files(): source = files[f]["source"] source_version = "" if source.find("(") != -1: - m = utils.re_extract_src_version.match(source) + m = re_extract_src_version.match(source) source = m.group(1) source_version = m.group(2) if not source_version: @@ -502,12 +504,12 @@ def check_files(): files[f]["source version"] = source_version # Ensure the filename matches the contents of the .deb - m = utils.re_isadeb.match(f) + m = re_isadeb.match(f) # package name file_package = m.group(1) if files[f]["package"] != file_package: reject("%s: package part of filename (%s) does not match package name in the %s (%s)." % (f, file_package, files[f]["dbtype"], files[f]["package"])) - epochless_version = utils.re_no_epoch.sub('', control.Find("Version")) + epochless_version = re_no_epoch.sub('', control.Find("Version")) # version file_version = m.group(2) if epochless_version != file_version: @@ -527,7 +529,7 @@ def check_files(): # Check in the SQL database if not Upload.source_exists(source_package, source_version, changes["distribution"].keys()): # Check in one of the other directories - source_epochless_version = utils.re_no_epoch.sub('', source_version) + source_epochless_version = re_no_epoch.sub('', source_version) dsc_filename = "%s_%s.dsc" % (source_package, source_epochless_version) if os.path.exists(Cnf["Dir::Queue::Byhand"] + '/' + dsc_filename): files[f]["byhand"] = 1 @@ -549,7 +551,7 @@ def check_files(): # Checks for a source package... else: - m = utils.re_issource.match(f) + m = re_issource.match(f) if m: has_source = 1 files[f]["package"] = m.group(1) @@ -744,7 +746,7 @@ def check_dsc(): pass # Ensure the version number in the .dsc matches the version number in the .changes - epochless_dsc_version = utils.re_no_epoch.sub('', dsc["version"]) + epochless_dsc_version = re_no_epoch.sub('', dsc["version"]) changes_version = files[dsc_filename]["version"] if epochless_dsc_version != files[dsc_filename]["version"]: reject("version ('%s') in .dsc does not match version ('%s') in .changes." % (epochless_dsc_version, changes_version)) @@ -752,7 +754,7 @@ def check_dsc(): # Ensure there is a .tar.gz in the .dsc file has_tar = 0 for f in dsc_files.keys(): - m = utils.re_issource.match(f) + m = re_issource.match(f) if not m: reject("%s: %s in Files field not recognised as source." % (dsc_filename, f)) continue @@ -802,7 +804,7 @@ def get_changelog_versions(source_dir): # Create a symlink mirror of the source files in our temporary directory for f in files.keys(): - m = utils.re_issource.match(f) + m = re_issource.match(f) if m: src = os.path.join(source_dir, f) # If a file is missing for whatever reason, give up. @@ -832,7 +834,7 @@ def get_changelog_versions(source_dir): return # Get the upstream version - upstr_version = utils.re_no_epoch.sub('', dsc["version"]) + upstr_version = re_no_epoch.sub('', dsc["version"]) if re_strip_revision.search(upstr_version): upstr_version = re_strip_revision.sub('', upstr_version) @@ -1170,7 +1172,7 @@ def action (): while prompt.find(answer) == -1: answer = utils.our_raw_input(prompt) - m = queue.re_default_answer.match(prompt) + m = re_default_answer.match(prompt) if answer == "": answer = m.group(1) answer = answer[:1].upper() diff --git a/dak/reject_proposed_updates.py b/dak/reject_proposed_updates.py index 4510ee0e..c3345017 100755 --- a/dak/reject_proposed_updates.py +++ b/dak/reject_proposed_updates.py @@ -25,6 +25,7 @@ from daklib import database from daklib import logging from daklib import queue from daklib import utils +from daklib.regexes import re_default_answer ################################################################################ @@ -97,7 +98,7 @@ def main(): while prompt.find(answer) == -1: answer = utils.our_raw_input(prompt) - m = queue.re_default_answer.search(prompt) + m = re_default_answer.search(prompt) if answer == "": answer = m.group(1) answer = answer[:1].upper() @@ -137,7 +138,7 @@ def reject (reject_message = ""): answer = "XXX" while prompt.find(answer) == -1: answer = utils.our_raw_input(prompt) - m = queue.re_default_answer.search(prompt) + m = re_default_answer.search(prompt) if answer == "": answer = m.group(1) answer = answer[:1].upper() diff --git a/dak/show_deferred.py b/dak/show_deferred.py index 6942efbd..8c13d677 100755 --- a/dak/show_deferred.py +++ b/dak/show_deferred.py @@ -27,7 +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 +from daklib.regexes import re_html_escaping, html_escaping ################################################################################ ### work around bug #487902 in debian-python 0.1.10 diff --git a/daklib/queue.py b/daklib/queue.py index 6d68af4f..4061c05d 100755 --- a/daklib/queue.py +++ b/daklib/queue.py @@ -24,7 +24,7 @@ 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 regexes import re_default_answer, re_fdnic, re_bin_only_nmu from types import * diff --git a/daklib/utils.py b/daklib/utils.py index 78ee197f..4531b273 100755 --- a/daklib/utils.py +++ b/daklib/utils.py @@ -28,7 +28,9 @@ import apt_pkg import database import time from dak_exceptions import * -from regexes import * +from regexes import re_html_escaping, html_escaping, re_single_line_field, \ + re_multi_line_field, re_srchasver, re_verwithext, \ + re_parse_maintainer, re_taint_free, re_gpg_uid ################################################################################ -- 2.39.2