# Path: ci/utils.py
# class BuildFailed(Exception):
#     pass


import os
import shutil
import tempfile
import traceback
from subprocess import Popen, PIPE
from ci.utils import BuildFailed
        commit = self.build.commit
        if commit.vcs_id is None:
            changeset = self.repo.workdir.get_changeset()
            commit.vcs_id = changeset.raw_id
            commit.short_message = changeset.message.splitlines()[0]
            commit.save()

    def teardown_build(self):
        shutil.rmtree(self.repo_path)

    def format_exception(self):
        return '\n\n' + '\n\n'.join([
            '=' * 79,
            "Exception in django-ci/builder",
            traceback.format_exc()
        ])

    def run(self):
        raise NotImplementedError


class CommandBasedBuilder(Builder):
    def run(self):
        cmd = self.get_cmd()
        # XXX directly pipe into files
        proc = Popen(cmd, cwd=self.repo_path, stdout=PIPE, stderr=PIPE)
        stdout, stderr = proc.communicate()
        self.build.stderr.save_named(stderr, save=False)
        self.build.stdout.save_named(stdout, save=False)
        if proc.returncode:

# Path: ci/utils.py
# class BuildFailed(Exception):
#     pass


# Path: ci/plugins/base.py
import os
import shutil
import tempfile
import traceback
from subprocess import Popen, PIPE
from ci.utils import BuildFailed

        commit = self.build.commit
        if commit.vcs_id is None:
            changeset = self.repo.workdir.get_changeset()
            commit.vcs_id = changeset.raw_id
            commit.short_message = changeset.message.splitlines()[0]
            commit.save()

    def teardown_build(self):
        shutil.rmtree(self.repo_path)

    def format_exception(self):
        return '\n\n' + '\n\n'.join([
            '=' * 79,
            "Exception in django-ci/builder",
            traceback.format_exc()
        ])

    def run(self):
        raise NotImplementedError


class CommandBasedBuilder(Builder):
    def run(self):
        cmd = self.get_cmd()
        # XXX directly pipe into files
        proc = Popen(cmd, cwd=self.repo_path, stdout=PIPE, stderr=PIPE)
        stdout, stderr = proc.communicate()
        self.build.stderr.save_named(stderr, save=False)
        self.build.stdout.save_named(stdout, save=False)
        if proc.returncode:

            raise BuildFailed("Command %s returned with code %d" % (cmd, proc.returncode))