summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-02-17 01:22:14 +0100
committerDan McGee <dan@archlinux.org>2011-03-23 21:44:41 +0100
commit857cae2e96aa0d23b0702d5ad9db572787f657a9 (patch)
tree9e4f56b3fd6b8edae286828e0fefd09cd39dce28
parent97437d27b7b3d01bfd2e2ae628e6612c149324b4 (diff)
downloadarchweb-857cae2e96aa0d23b0702d5ad9db572787f657a9.tar.gz
archweb-857cae2e96aa0d23b0702d5ad9db572787f657a9.tar.xz
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 <dan@archlinux.org>
-rw-r--r--devel/management/commands/reporead.py22
1 files 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):