gorilla / lib / gorilla / guts /

Full commit
import os, sys
from gorilla.guts import util

sys.path.insert(0, util.GORILLA_PATH)

class Card(object):
    """A useful wrapper around a card module."""
    class DoesNotExist(Exception):
        def __init__(self, name):
   = name
            super(Card.DoesNotExist, self).__init__()
    def __init__(self, name):
        super(Card, self).__init__()
        name = name.lower()
        module_name = name.replace('-', '_')
            self.module = __import__('catalog.%s' % module_name, fromlist=[module_name])
        except ImportError:
            raise Card.DoesNotExist(name)
    def name(self):
        return self.module.__dict__.get('name', '')
    def homepage(self):
        return self.module.__dict__.get('homepage', '')
    def description(self):
        return self.module.__doc__
    def packages(self):
        return self.module.__dict__.get('packages', [])
    def scripts(self):
        return self.module.__dict__.get('scripts', [])
    def sources(self):
        return self.module.__dict__.get('sources', [])
    def build_commands(self):
        return self.module.__dict__.get('build_commands', [])
    def tests(self):
        return self.module.__dict__.get('tests', {})

def all_cards():
    """Return a generator for all Cards in the catalog."""
    catalog_path = os.path.join(util.GORILLA_PATH, 'catalog')
    filenames = os.listdir(catalog_path)
    card_files = filter(
        lambda f: not f.startswith('_') and f.endswith('.py'),
    card_module_names = [f[:-3] for f in card_files]
    return (Card(c) for c in card_module_names)