aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJauhien Piatlicki (jauhien) <piatlicki@gmail.com>2013-07-18 14:13:49 +0200
committerJauhien Piatlicki (jauhien) <piatlicki@gmail.com>2013-07-18 14:13:49 +0200
commit57688167eacd34f03b4ae04b820c7c032ef9aefd (patch)
treecd036992e8694e01246fc93c64e96d4782f9f9f5 /g_sorcery/g_collections.py
parentg_sorcery/compatibility: basestring fix (diff)
downloadg-sorcery-57688167eacd34f03b4ae04b820c7c032ef9aefd.tar.gz
g-sorcery-57688167eacd34f03b4ae04b820c7c032ef9aefd.tar.bz2
g-sorcery-57688167eacd34f03b4ae04b820c7c032ef9aefd.zip
g_sorcery/g_collections: Dependency class added (uses portage.dep.Atom)
Diffstat (limited to 'g_sorcery/g_collections.py')
-rw-r--r--g_sorcery/g_collections.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/g_sorcery/g_collections.py b/g_sorcery/g_collections.py
index 3ecc373..e9655a9 100644
--- a/g_sorcery/g_collections.py
+++ b/g_sorcery/g_collections.py
@@ -16,6 +16,8 @@
import collections
+import portage
+
class elist(list):
'''Custom list type which adds a customized __str__()
and takes an optional separator argument
@@ -45,3 +47,25 @@ class elist(list):
return self._sep_.join(self)
Package = collections.namedtuple("Package", "category name version")
+
+
+class Dependency(object):
+
+ __slots__ = ('atom', 'category', 'package', 'version', 'operator')
+
+ def __init__(self, category, package, version="", operator=""):
+ atom_str = operator + category + "/" + package
+ if version:
+ atom_str += "-" + str(version)
+ object.__setattr__(self, "atom", portage.dep.Atom(atom_str))
+ object.__setattr__(self, "category", category)
+ object.__setattr__(self, "package", package)
+ object.__setattr__(self, "version", version)
+ object.__setattr__(self, "operator", operator)
+
+ def __setattr__(self, name, value):
+ raise AttributeError("Dependency instances are immutable",
+ self.__class__, name, value)
+
+ def __str__(self):
+ return str(self.atom)