From 3c14e39afe707f650e3aae38f70c0b91dbd14573 Mon Sep 17 00:00:00 2001 From: Torsten Werner Date: Sun, 24 Jul 2011 14:45:00 +0200 Subject: [PATCH] Factor Uploaders splitting into its own function. + Add a test for it. Signed-off-by: Torsten Werner --- daklib/dbconn.py | 11 +++++++++-- tests/test_split_uploaders.py | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100755 tests/test_split_uploaders.py diff --git a/daklib/dbconn.py b/daklib/dbconn.py index 48dfd0d8..f314b3f7 100755 --- a/daklib/dbconn.py +++ b/daklib/dbconn.py @@ -2635,6 +2635,14 @@ __all__.append('import_metadata_into_db') ################################################################################ +def split_uploaders(uploaders_list): + ''' + Split the Uploaders field into the individual uploaders and yield each of + them. Beware: email addresses might contain commas. + ''' + for uploader in uploaders_list.replace(">, ", ">\t").split("\t"): + yield uploader.strip() + @session_wrapper def add_dsc_to_db(u, filename, session=None): entry = u.pkg.files[filename] @@ -2725,8 +2733,7 @@ def add_dsc_to_db(u, filename, session=None): session.refresh(source) source.uploaders = [source.maintainer] if u.pkg.dsc.has_key("uploaders"): - for up in u.pkg.dsc["uploaders"].replace(">, ", ">\t").split("\t"): - up = up.strip() + for up in split_uploaders(u.pkg.dsc["uploaders"]): source.uploaders.append(get_or_set_maintainer(up, session)) session.flush() diff --git a/tests/test_split_uploaders.py b/tests/test_split_uploaders.py new file mode 100755 index 00000000..062fd357 --- /dev/null +++ b/tests/test_split_uploaders.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python + +from base_test import DakTestCase + +from daklib.dbconn import split_uploaders + +import unittest + +class SplitUploadersTestCase(DakTestCase): + def test_main(self): + expected = ['"A, B" ', 'D E '] + l = list(split_uploaders('"A, B" , D E ')) + self.assertEqual(expected, l) + +if __name__ == '__main__': + unittest.main() -- 2.39.5