From 4bda8acf022c698d18edb07686d579d8a0e2cb4a Mon Sep 17 00:00:00 2001 From: "Jauhien Piatlicki (jauhien)" Date: Sat, 13 Jul 2013 17:07:12 +0200 Subject: g_sorcery/collections -> g_sorcery/g_collections --- g_elpa/elpa_db.py | 2 +- g_sorcery/backend.py | 2 +- g_sorcery/fileutils.py | 2 +- g_sorcery/g_collections.py | 47 ++++++++++++++++++++++++++++++++++++++++++++++ g_sorcery/package_db.py | 2 +- 5 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 g_sorcery/g_collections.py diff --git a/g_elpa/elpa_db.py b/g_elpa/elpa_db.py index 59f30a1..82f0a3a 100644 --- a/g_elpa/elpa_db.py +++ b/g_elpa/elpa_db.py @@ -22,7 +22,7 @@ if py2k: else: from urllib.parse import urljoin -from g_sorcery.collections import Package +from g_sorcery.g_collections import Package from g_sorcery.package_db import PackageDB from g_sorcery.fileutils import wget from g_sorcery.exceptions import SyncError diff --git a/g_sorcery/backend.py b/g_sorcery/backend.py index 65d7e90..d077d30 100644 --- a/g_sorcery/backend.py +++ b/g_sorcery/backend.py @@ -16,7 +16,7 @@ import glob import os import sys -from .collections import Package +from .g_collections import Package from .exceptions import DependencyError, DigestError class Backend(object): diff --git a/g_sorcery/fileutils.py b/g_sorcery/fileutils.py index 1db9dc9..478570d 100644 --- a/g_sorcery/fileutils.py +++ b/g_sorcery/fileutils.py @@ -14,7 +14,7 @@ import json, os, shutil from .exceptions import FileJSONError -from .collections import Package, elist +from .g_collections import Package, elist class FileJSON(object): """ 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") diff --git a/g_sorcery/package_db.py b/g_sorcery/package_db.py index 4e0b46a..f8155dc 100644 --- a/g_sorcery/package_db.py +++ b/g_sorcery/package_db.py @@ -26,7 +26,7 @@ from .exceptions import DBStructureError, IntegrityError, \ from .fileutils import FileJSON, FilePkgDesc, hash_file, copy_all, wget -from .collections import Package +from .g_collections import Package class PackageDB(object): """ -- cgit v1.2.3-65-gdbad