diff options
author | 2010-06-09 18:06:10 +0300 | |
---|---|---|
committer | 2010-06-09 18:06:10 +0300 | |
commit | ad81c1db4d7c3e99501736a092740e04a202d977 (patch) | |
tree | af2f251bc1df041b3e354bc7dd0ed69f8cd386f8 /utils | |
parent | Added gsoc reports and proposal (diff) | |
download | gsoc2010-grumpy-ad81c1db4d7c3e99501736a092740e04a202d977.tar.gz gsoc2010-grumpy-ad81c1db4d7c3e99501736a092740e04a202d977.tar.bz2 gsoc2010-grumpy-ad81c1db4d7c3e99501736a092740e04a202d977.zip |
Added utility for initial portage->database sync
Diffstat (limited to 'utils')
-rw-r--r-- | utils/db_init.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/utils/db_init.py b/utils/db_init.py new file mode 100644 index 0000000..c5d6e74 --- /dev/null +++ b/utils/db_init.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python +import sys + +from pkgcore.config import load_config +from pkgcore.ebuild import repository + +from pymongo import Connection + +def main(path): + # Set up a link to our MongoDB collection + db = Connection('localhost', 27017)['grumpy'] + + # pkgcore part to fetch all the ebuild information + conf = load_config() + # NB! No cache is used, so this is ssslllooowwww.. + eclass_cache = conf.eclass_cache['eclass stack'] + overlay_repo = repository.UnconfiguredTree(path, eclass_cache=eclass_cache) + + for pkg in overlay_repo: + _id = "%s/%s" % (pkg.package, pkg.category) + # Load package info from database... + ebuild = db.ebuilds.find_one(dict(_id=_id)) + if not ebuild: + # ...or create data if pkg not in db + ebuild = dict( + # Internal schema version + schema_ver = 0, + _id = "%s/%s" % (pkg.package, pkg.category), + cat = pkg.category, + pkg = pkg.package, + desc = pkg.description, + ldesc = pkg.longdescription, + homepage = pkg.homepage, + herds = list(pkg.herds) if pkg.herds else [], + maintainers = [m.email for m in pkg.maintainers] \ + if pkg.maintainers else [], + ebuilds = list() + ) + # Load version information + version_data = dict( + version = pkg.version, + slot = pkg.slot, + eapi = pkg.eapi, + keywords = list(pkg.keywords) if pkg.keywords else [], + # TODO, need to figure out a proper queryable structure for these +# license = pkg.license, +# depends = pkg.depends, +# rdepends = pkg.rdepends + ) + ebuild['ebuilds'].append(version_data) + print "Adding: ", db.ebuilds.save(ebuild) + +if __name__ == '__main__': + if len(sys.argv) != 1: + print "Please provide path to portage directory as argument" + sys.exit() + main(sys.argv[1]) |