aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJauhien Piatlicki (jauhien) <piatlicki@gmail.com>2013-07-13 17:07:12 +0200
committerJauhien Piatlicki (jauhien) <piatlicki@gmail.com>2013-07-13 17:07:12 +0200
commit4bda8acf022c698d18edb07686d579d8a0e2cb4a (patch)
tree2318a8618336fcc06dcd2762b5f47881af845a9b /g_sorcery/g_collections.py
parentget_pkgpath modified as suggested by Brian Dolbec (diff)
downloadg-sorcery-4bda8acf022c698d18edb07686d579d8a0e2cb4a.tar.gz
g-sorcery-4bda8acf022c698d18edb07686d579d8a0e2cb4a.tar.bz2
g-sorcery-4bda8acf022c698d18edb07686d579d8a0e2cb4a.zip
g_sorcery/collections -> g_sorcery/g_collections
Diffstat (limited to 'g_sorcery/g_collections.py')
-rw-r--r--g_sorcery/g_collections.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/g_sorcery/g_collections.py b/g_sorcery/g_collections.py
new file mode 100644
index 0000000..3ecc373
--- /dev/null
+++ b/g_sorcery/g_collections.py
@@ -0,0 +1,47 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+ g_collections.py
+ ~~~~~~~~~~~~~~~~
+
+ Customized classes of standard python data types
+ for use withing g-sorcery for custom formatted string output
+ substitution in our ebuild templates.
+
+ :copyright: (c) 2013 by Brian Dolbec
+ :copyright: (c) 2013 by Jauhien Piatlicki
+ :license: GPL-2, see LICENSE for more details.
+"""
+
+import collections
+
+class elist(list):
+ '''Custom list type which adds a customized __str__()
+ and takes an optional separator argument
+
+ elist() -> new empty elist
+ elist(iterable) -> new elist initialized from iterable's items
+ elist(separator='\\n\\t') -> new empty elist with
+ newline & tab indented str(x) output
+ elist(iterable, ' ') -> new elist initialized from iterable's items
+ with space separated str(x) output
+ '''
+
+ __slots__ = ('_sep_')
+
+ def __init__(self, iterable=None, separator=' '):
+ '''
+ iterable: initialize from iterable's items
+ separator: string used to join list members with for __str__()
+ '''
+ list.__init__(self, iterable or [])
+ self._sep_ = separator
+
+ def __str__(self):
+ '''Custom output function
+ 'x.__str__() <==> str(separator.join(x))'
+ '''
+ return self._sep_.join(self)
+
+Package = collections.namedtuple("Package", "category name version")