# HG changeset patch # User Jeff Hammel # Date 1306788013 25200 # Node ID 151862a0a711ad3fc4d64e15602d0bce6c19d471 # Parent 8b4c21b853e917aaba23dc2423f1be167f91abc7 begin restructuring to something more modular and extensible diff -r 8b4c21b853e9 -r 151862a0a711 buttercup/buttercup.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/buttercup/buttercup.py Mon May 30 13:40:13 2011 -0700 @@ -0,0 +1,33 @@ +""" +the flower blooming to k0s.org +""" + +class Buttercup(object): + + # k0sware software + HG='http://k0s.org/hg' + PACKAGES=['bitsyapps', + 'bitsyauth', + 'bitsyblog', + 'bitsytweet', + 'buttercup', + 'clwapp', + 'commentator', + 'contenttransformer', + 'cropresize', + 'decoupage', + 'emaildispatcher', + 'genshi_view', + 'hgpaste', + 'lxmlmiddleware', + 'martINI', + 'montage', + 'pyloader', + 'webob_view', + 'wordstream'] + + def __init__(self): + sources = {'hg': ['%s/%s' % (self.HG, package) + for package in self.PACKAGES ]} + sources['git'] = ['git://github.com/mozilla/toolbox.git'] + diff -r 8b4c21b853e9 -r 151862a0a711 buttercup/checkout.py --- a/buttercup/checkout.py Tue Dec 28 16:52:26 2010 -0800 +++ b/buttercup/checkout.py Mon May 30 13:40:13 2011 -0700 @@ -60,13 +60,13 @@ sys.exit(0) # setup the src directory in a virtualenv - assert 'VIRTUAL_ENV' in os.environ + assert 'VIRTUAL_ENV' in os.environ, "You must have a virtualenv activated" src = os.path.join(os.environ['VIRTUAL_ENV'], 'src') if not os.path.exists(src): os.mkdir(src) os.chdir(src) - # clone othe sources + # clone the sources for source in sources: if os.path.exists(source[0]): if options.update: diff -r 8b4c21b853e9 -r 151862a0a711 buttercup/source.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/buttercup/source.py Mon May 30 13:40:13 2011 -0700 @@ -0,0 +1,37 @@ +import os +import subprocess + +class Source(object): + """abstract base class for VCS source""" + def __init__(self, uri, srcdir=None): + self.uri = uri + self.srcdir = srcdir or os.getcwd() + + @classmethod + def directory_name(cls, uri): + """return relative directory name from self.uri""" + return uri.rstrip('/').split('/')[-1] + + def directory(self): + return os.path.join(self.srcdir, self.directory_name(self.uri)) + +class HgSource(Source): + """mercurial source""" + + def update(self): + """updates a checkout or does one if it does not exist""" + +class GitSource(Source): + + @classmethod + def directory_name(cls, uri): + ext = '.git' + if uri.endswith(uri): + uri = uri[:-len(ext)] + return Source.directory_name(uri) + +if __name__ == '__main__': + source = HgSource('http://k0s.org/hg/pyloader') + print source.directory() + source = GitSource('git://github.com/mozilla/toolbox.git') + print source.directory() diff -r 8b4c21b853e9 -r 151862a0a711 tests/doctest.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/doctest.txt Mon May 30 13:40:13 2011 -0700 @@ -0,0 +1,17 @@ +Test Buttercup +============== + +The obligatory imports:: + + >>> import os + >>> from buttercup import source + >>> cwd = os.getcwd() + +Test source resolution:: + + >>> hgsource = source.HgSource('http://k0s.org/hg/pyloader') + >>> hgsource.directory() == os.path.join(cwd, 'pyloader') + True + >>> gitsource = source.GitSource('git://github.com/mozilla/toolbox.git') + >>> gitsource.directory() == os.path.join(cwd, 'toolbox') + True diff -r 8b4c21b853e9 -r 151862a0a711 tests/test.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test.py Mon May 30 13:40:13 2011 -0700 @@ -0,0 +1,59 @@ +#!/usr/bin/env python + +""" +doctest runner +""" + +import doctest +import os +import sys +from optparse import OptionParser + + +def run_tests(raise_on_error=False, report_first=False): + + # add results here + results = {} + + # doctest arguments + directory = os.path.dirname(os.path.abspath(__file__)) + extraglobs = {'here': directory} + doctest_args = dict(extraglobs=extraglobs, raise_on_error=raise_on_error) + if report_first: + doctest_args['optionflags'] = doctest.REPORT_ONLY_FIRST_FAILURE + + # gather tests + tests = [ test for test in os.listdir(directory) + if test.endswith('.txt') ] + + # run the tests + for test in tests: + try: + results[test] = doctest.testfile(test, **doctest_args) + except doctest.DocTestFailure, failure: + raise + except doctest.UnexpectedException, failure: + raise failure.exc_info[0], failure.exc_info[1], failure.exc_info[2] + + return results + +def main(args=sys.argv[1:]): + + # parse command line args + parser = OptionParser(description=__doc__) + parser.add_option('--raise', dest='raise_on_error', + default=False, action='store_true', + help="raise on first error") + parser.add_option('--report-first', dest='report_first', + default=False, action='store_true', + help="report the first error only (all tests will still run)") + options, args = parser.parse_args(args) + + # run the tests + results = run_tests(**options.__dict__) + if sum([i.failed for i in results.values()]): + sys.exit(1) # error + + +if __name__ == '__main__': + main()