From daaee3bcc68b5702b5cea8f14dfa6c10cf304ff0 Mon Sep 17 00:00:00 2001 From: James Troup Date: Sun, 10 Jun 2001 16:35:03 +0000 Subject: [PATCH] Fix extract_component_from_section and add a test suite. --- TODO | 2 + test/004/test.py | 113 +++++++++++++++++++++++++++++++++++++++++++++++ utils.py | 31 ++++++++++--- 3 files changed, 140 insertions(+), 6 deletions(-) create mode 100755 test/004/test.py diff --git a/TODO b/TODO index 927c44ab..aa4df5da 100644 --- a/TODO +++ b/TODO @@ -57,6 +57,8 @@ Urgent Less Urgent ----------- + o main/utils -> main/utils, main rather than utils, main + o doogie's binary -> source index o ANIAS should be done in katie ? diff --git a/test/004/test.py b/test/004/test.py new file mode 100755 index 00000000..e0a02d60 --- /dev/null +++ b/test/004/test.py @@ -0,0 +1,113 @@ +#!/usr/bin/env python + +# Check utils.extract_component_from_section() +# Copyright (C) 2000 James Troup +# $Id: test.py,v 1.1 2001-06-10 16:35:04 troup Exp $ + +# 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 os, string, sys + +sys.path.append(os.path.abspath('../../')); + +import utils + +################################################################################ + +def fail(message): + sys.stderr.write("%s\n" % (message)); + sys.exit(1); + +################################################################################ + +# prefix: non-US +# component: main, contrib, non-free +# section: games, admin, libs, [...] + +# [1] Order is as above. +# [2] Prefix is optional for the default archive, but mandatory when +# uploads are going anywhere else. +# [3] Default component is main and may be omitted. +# [4] Section is optional. +# [5] Prefix is case insensitive +# [6] Everything else is case sensitive. + +def test(input, output): + result = utils.extract_component_from_section(input); + if result != output: + fail ("%s -> %s [should have been %s]" % (input, repr(result), repr(output))); + +def main (): + # Err, whoops? should probably be "utils", "main"... + input = "main/utils"; output = ("main/utils", "main"); + test (input, output); + + + # Validate #3 + input = "utils"; output = ("utils", "main"); + test (input, output); + + input = "non-free/libs"; output = ("non-free/libs", "non-free"); + test (input, output); + + input = "contrib/net"; output = ("contrib/net", "contrib"); + test (input, output); + + + # Validate #3 with a prefix + input = "non-US"; output = ("non-US", "non-US/main"); + test (input, output); + + + # Validate #4 + input = "main"; output = ("main", "main"); + test (input, output); + + input = "contrib"; output = ("contrib", "contrib"); + test (input, output); + + input = "non-free"; output = ("non-free", "non-free"); + test (input, output); + + + # Validate #4 with a prefix + input = "non-US/main"; output = ("non-US/main", "non-US/main"); + test (input, output); + + input = "non-US/contrib"; output = ("non-US/contrib", "non-US/contrib"); + test (input, output); + + input = "non-US/non-free"; output = ("non-US/non-free", "non-US/non-free"); + test (input, output); + + + # Validate #5 + input = "non-us"; output = ("non-us", "non-US/main"); + test (input, output); + + input = "non-us/contrib"; output = ("non-us/contrib", "non-US/contrib"); + test (input, output); + + + # Validate #6 (section) + input = "utIls"; output = ("utIls", "main"); + test (input, output); + +################################################################################ + +if __name__ == '__main__': + main() diff --git a/utils.py b/utils.py index 71b44fc3..1c00a1cb 100644 --- a/utils.py +++ b/utils.py @@ -1,6 +1,6 @@ # Utility functions # Copyright (C) 2000 James Troup -# $Id: utils.py,v 1.25 2001-06-01 00:17:45 troup Exp $ +# $Id: utils.py,v 1.26 2001-06-10 16:35:03 troup Exp $ # 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 @@ -46,6 +46,15 @@ file_exists_exc = "Destination file exists"; send_mail_invalid_args_exc = "Both arguments are non-null."; sendmail_failed_exc = "Sendmail invocation failed"; +# Valid components; used by extract_component_from_section() because +# it doesn't know about Conf from it's caller. FIXME + +valid_components = { + "main": "", + "contrib": "", + "non-free": "" + }; + ###################################################################################### def open_file(filename, mode): @@ -77,7 +86,9 @@ def str_isnum (s): ###################################################################################### -# What a mess. FIXME +# Prefix and components hardcoded into this like a good'un; need to unhardcod at some +# stage. [FIXME] + def extract_component_from_section(section): component = ""; @@ -85,15 +96,23 @@ def extract_component_from_section(section): component = string.split(section, '/')[0]; if string.lower(component) == "non-us" and string.count(section, '/') > 0: s = string.split(section, '/')[1]; - if s == "main" or s == "non-free" or s == "contrib": # Avoid e.g. non-US/libs + if valid_components.has_key(s): # Avoid e.g. non-US/libs component = string.split(section, '/')[0]+ '/' + string.split(section, '/')[1]; if string.lower(section) == "non-us": component = "non-US/main"; - + + # non-US prefix is case insensitive + if string.lower(component)[:6] == "non-us": + component = "non-US"+component[6:]; + + # Expand default component if component == "": - component = "main"; - elif string.lower(component) == "non-us": + if valid_components.has_key(section): + component = section; + else: + component = "main"; + elif component == "non-US": component = "non-US/main"; return (section, component); -- 2.39.2