view buttercup/buttercup.py @ 48:c99fbe84c3c2

STUB: buttercup/buttercup.py
author Jeff Hammel <k0scist@gmail.com>
date Sat, 25 Jan 2014 17:17:26 -0800
parents cee8bf9cc5a2
children e3770a2530ff
line wrap: on
line source

"""
the flower blooming to k0s.org
"""

import os
import source
from subprocess import check_call as call


__all__ = ['Buttercup', 'SetupError']


class SetupError(Exception):
    """error during setup"""

    def __init__(self, message, directory, uri=None):
        self.directory = os.path.abspath(directory)
        self.uri = uri
        _message = "Error setting up '{}'".format(directory)
        if uri:
            _message += " (from {})".format(uri)
        _message += "\n  {}".format(message)
        Exception.__init__(self, _message)


class Buttercup(object):

    # k0sware software
    # TODO: make this a `package` (or more likely `python-package`)
    # subtype
    HG='http://k0s.org/hg'
    PACKAGES=['bitsyapps',
              'bitsyauth',
              'bitsyblog',
              'bitsytweet',
              'buttercup',
              'clwapp',
              'commentator',
              'contenttransformer',
              'cropresize',
              'decoupage',
              'emaildispatcher',
              'genshi_view',
              'hgpaste',
              'lxmlmiddleware',
              'martINI',
              'montage',
              'pyloader',
              'redirector',
              'relocator',
              'svgsitemap',
              'uploader',
              'webob_view',
              'wordstream',
              'wsgintegrate']

    def __init__(self, srcdir):
        self.srcdir = srcdir

        # TODO: this should all go in a `pip` requirements file

        # base webapps and dependencies
        self.sources = {'hg': ['%s/%s' % (self.HG, package)
                               for package in self.PACKAGES ]}
        self.sources['git'] = ['git://github.com/mozilla/toolbox.git']


    def install(self):
        """install all software needed for this flower"""
        source_objs = source.sources(self.sources, srcdir=self.srcdir)
        for source_obj in source_objs:
            source_obj() # clone/update the software

    def setup(self, source_objs=None):
        """setup python packages for development"""
        if source_objs is None:
            source_objs = source.sources(self.sources, srcdir=self.srcdir)
        for source_obj in source_objs:
            if os.path.exists(os.path.join(source_obj.directory(), 'setup.py')):
                try:
                    call(['python', 'setup.py', 'develop'], cwd=source_obj.directory())
                except Exception as e:
                    import pdb; pdb.set_trace()
                    raise SetupError(str(e))

    def deploy(self):
        self.install()
        self.setup()

    __call__ = deploy