aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJauhien Piatlicki <jauhien@gentoo.org>2015-04-17 11:31:25 +0200
committerJauhien Piatlicki <jauhien@gentoo.org>2015-04-17 19:10:08 +0200
commit15e264af65e08505ec85d8cb0dd53170ac044985 (patch)
tree6a450ce09150205eeb63695bc7e0d312260d4b1a /g_sorcery
parent[g_sorcery] fix DB cleaning (diff)
downloadg-sorcery-15e264af65e08505ec85d8cb0dd53170ac044985.tar.gz
g-sorcery-15e264af65e08505ec85d8cb0dd53170ac044985.tar.bz2
g-sorcery-15e264af65e08505ec85d8cb0dd53170ac044985.zip
[g_sorcery/package_db] add category common data setter and getter to DB API
Diffstat (limited to 'g_sorcery')
-rw-r--r--g_sorcery/package_db.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/g_sorcery/package_db.py b/g_sorcery/package_db.py
index ec2d45f..5374ae5 100644
--- a/g_sorcery/package_db.py
+++ b/g_sorcery/package_db.py
@@ -105,6 +105,7 @@ class PackageDB(object):
self.pkg_name, self.pkg_data = next(self.pkgs_iter)
self.vers_iter = iter(self.pkg_data.items())
+ ebuild_data = dict(ebuild_data)
ebuild_data.update(self.cat_data['common_data'])
return (Package(self.cat_name, self.pkg_name, ver), ebuild_data)
@@ -129,6 +130,7 @@ class PackageDB(object):
self.pkg_name, self.pkg_data = next(self.pkgs_iter)
self.vers_iter = iter(self.pkg_data.items())
+ ebuild_data = dict(ebuild_data)
ebuild_data.update(self.cat_data['common_data'])
return (Package(self.cat_name, self.pkg_name, ver), ebuild_data)
@@ -275,6 +277,42 @@ class PackageDB(object):
self.categories[category] = description
+ def set_common_data(self, category, common_data):
+ """
+ Set common data for a category.
+
+ Args:
+ category: Category name.
+ common_data: Category common data.
+ """
+ if not category in self.categories:
+ raise InvalidKeyError('Non-existent category: ' + category)
+
+ if not category in self.database:
+ self.database[category] = {'common_data': common_data, 'packages': {}}
+ else:
+ self.database[category]['common_data'] = common_data
+
+
+ def get_common_data(self, category):
+ """
+ Get common data for a category.
+
+ Args:
+ category: Category name.
+
+ Returns:
+ Dictionary with category common data.
+ """
+ if not category in self.categories:
+ raise InvalidKeyError('Non-existent category: ' + category)
+
+ if not category in self.database:
+ return {}
+ else:
+ return self.database[category]['common_data']
+
+
def add_package(self, package, ebuild_data=None):
"""
Add a package.