diff options
author | 2010-07-03 08:21:58 +0300 | |
---|---|---|
committer | 2010-07-03 08:21:58 +0300 | |
commit | bda6df4c939f0fbac7648af8b532c6e4b3c28261 (patch) | |
tree | a7f1d70b7e9c1893cb6b23d89990a38423f96e1b /utils | |
parent | Move Package and Ebuild rename into models (diff) | |
download | gsoc2010-grumpy-bda6df4c939f0fbac7648af8b532c6e4b3c28261.tar.gz gsoc2010-grumpy-bda6df4c939f0fbac7648af8b532c6e4b3c28261.tar.bz2 gsoc2010-grumpy-bda6df4c939f0fbac7648af8b532c6e4b3c28261.zip |
Add category list sync code
Diffstat (limited to 'utils')
-rwxr-xr-x | utils/grumpy_sync.py | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/utils/grumpy_sync.py b/utils/grumpy_sync.py index 3ffdbb4..9b1e745 100755 --- a/utils/grumpy_sync.py +++ b/utils/grumpy_sync.py @@ -213,14 +213,21 @@ def main(path): session.commit() # Compare list of categories in portage vs database - cat_sql = [c.cat for c in Category.query.all()] + old = [c.cat for c in Category.query.all()] cats = repo.categories.keys() - # Store for later - cat_diff = list(set(cat_sql) | set(cats)) - - # TODO - # save/del categories from database + # Remove old categories + for cat in [item for item in old if item not in cats]: + c = Category.query.filter_by(cat=cat).one() + if Package.query.filter_by(cat=cat).count() > 0: + # We shouldn't have anything with this category in db + raise RuntimeError + session.delete(c) + # Add new categories + for cat in cats: + if cat not in old: + session.add(Category(cat)) + session.commit() # Traverse portage for cat in cats: |