From 857cae2e96aa0d23b0702d5ad9db572787f657a9 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Wed, 16 Feb 2011 18:22:14 -0600 Subject: reporead: refactor multivalued attribute creation This will come in more handy with our new models, but we can adapt groups and licenses to use it first. Signed-off-by: Dan McGee --- devel/management/commands/reporead.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/devel/management/commands/reporead.py b/devel/management/commands/reporead.py index 231cad0..0c83555 100644 --- a/devel/management/commands/reporead.py +++ b/devel/management/commands/reporead.py @@ -188,6 +188,17 @@ def create_depend(package, dep_str, optional=False): depend.save(force_insert=True) return depend +def create_multivalued(dbpkg, repopkg, db_attr, repo_attr): + '''Populate the simplest of multivalued attributes. These are those that + only deal with a 'name' attribute, such as licenses, groups, etc. The input + and output objects and attribute names are specified, and everything is + done via hasattr()/getattr().''' + collection = getattr(dbpkg, db_attr) + collection.all().delete() + if hasattr(repopkg, repo_attr): + for name in getattr(repopkg, repo_attr): + collection.create(name=name) + def populate_pkg(dbpkg, repopkg, force=False, timestamp=None): if repopkg.base: dbpkg.pkgbase = repopkg.base @@ -229,15 +240,8 @@ def populate_pkg(dbpkg, repopkg, force=False, timestamp=None): for y in repopkg.optdepends: dep = create_depend(dbpkg, y, True) - dbpkg.groups.all().delete() - if hasattr(repopkg, 'groups'): - for y in repopkg.groups: - dbpkg.groups.create(name=y) - - dbpkg.licenses.all().delete() - if hasattr(repopkg, 'license'): - for y in repopkg.license: - dbpkg.licenses.create(name=y) + create_multivalued(dbpkg, repopkg, 'groups', 'groups') + create_multivalued(dbpkg, repopkg, 'licenses', 'license') def populate_files(dbpkg, repopkg, force=False): -- cgit v1.2.3-24-g4f1b