--- /dev/null
+#!/usr/bin/env python
+
+# Check utils.extract_component_from_section()
+# Copyright (C) 2000 James Troup <james@nocrew.org>
+# $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()
# Utility functions
# Copyright (C) 2000 James Troup <james@nocrew.org>
-# $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
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):
######################################################################################
-# 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 = "";
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);