Пример #1
0
def prod_check(cmd):
    puts('****************************************')
    puts(red('         P R O D U C T I O N            '))
    puts('          woah there cowboy!            ')
    puts(red('               check                    '))
    puts('****************************************')
    puts('Command Called => %s\n' % cyan(cmd))
    proceed = prompt("Are you sure you want to do proceed?", default="no")

    if proceed.lower() != 'yes' and proceed.lower() != 'y':
        abort('change aborted!')
Пример #2
0
    def up(self):
        """
        Update a django environment with latest settings.

        This command does everything required to get a django project running.
        These are the steps that will be executed when the command is issued:

        1. pip install requirements
        2. syncdb
        3. migrate
        4. loaddata initial
        5. collectstatic
        6. assets build

        It has been designed with rerunning in mind and can be safely executed
        without any unwelcome side affects. For example, any pip packages that
        have already been installed will be skipped on rerun. Any database
        tables will be preserved (no dropping data), etc.

        Note that this must be run in a virtualenv. blt will detect if you are
        not using one and will barf with a helpful error.

        Usage:
            blt django.up
        """
        django_root = self.cfg['django']['DJANGO_ROOT']

        # install packages from pip's requirements.txt
        local('pip install -r requirements.txt')

        with cd(django_root):
            try:
                local('python manage.py syncdb')
                local('python manage.py migrate')
            except:
                msg = '\n'.join(["ERROR: Python couldn't find django.  Are you in a virtualenv?"
                                , "Try workon MY_SWEET_VIRTENV_HERE"])
                abort(msg)

        with cd(django_root):
            # Load dev data
            local('python manage.py loaddata initial')

            # collect static files
            local('python manage.py collectstatic --noinput')

            # Compile static asset bundles
            local('python manage.py assets build')
Пример #3
0
    def status(self, app=None):
        """
        Check the status of outstanding database migrations.

        Sadly, south gives us no easy api access to get status of what models
        have changed on an app. It only spits out the summary of changes to
        stderr and the actual Migration classes to stdout. The status command
        tries to encapsulate and parse this out to be helpful, but it is
        obviously brittle and should be tested whenever we upgrade the south
        library.

        Args:
            app: django app to check status for

        Usage:
            blt south.status (app)

        Examples:
            blt south.status invest - displays status for the invest app
        """
        if not app:
            msg = ("\nsouth status requires an *app* to check. for example:\n"
                    , "    blt south.status my_app\n"
                    , "To check which apps have had model changes run:\n"
                    , "    git status | grep models.py")
            abort("\n".join(msg))

        with cd(self.cfg['django']['DJANGO_ROOT']):
            puts("-- Model Check -----------------------------------------------------------")
            out = local('python manage.py schemamigration %s --auto --stdout 2>&1' % app,
                collect_output=True, abort_on_stderr=False)

            if out.strip() == 'Nothing seems to have changed.':
                puts("Model is in sync with migrations")
            else:
                puts("Model changes found:\n\n%s" % out)
                puts("\n==> Run `blt south.delta %s` to create a migration set." % app)

            puts("\n-- Unapplied Migrations --------------------------------------------------")
            out = local('python manage.py migrate %s --list | grep -v "*" 2>&1' % app,
                collect_output=True)

            if out.strip() == app:
                puts("All migrations have been applied to db")
            else:
                puts("Migrations need to be applied to db:\n%s" % out.strip())
                puts("\n==> Run `blt south.apply` to push to the database\n")
Пример #4
0
    def create(self):
        """
        Provisions a fully configured heroku app from scratch.

        Behind the scenes, you're getting the following:
        - heroku apps:create
        - git push heroku
        - heroku config
        - heroku addons
        - heroku domains
        - all post deploy hooks

        The command will handle creating a special git remote for the
        environment and can push from a non-master branch, things which are not
        easily accomplished with the heroku toolbelt. This is driven from the
        bltenv configuration.

        Usage:
            blt e:[env] heroku.create
        """
        print "******** Creating New Heroku App ********"
        print "App Name: " + green(self.cfg['heroku']['app'])
        print "Environment: " + green(self.cfg['blt_envtype'])
        print "Branch: " + green(self.cfg['heroku']['git_branch'])
        proceed = prompt("\nLook good? ==>", default='no')

        if proceed.lower() != 'yes' and proceed.lower() != 'y':
            abort('Aborting heroku creation.')

        local('heroku apps:create %s --remote %s' % (self.cfg['heroku']['app']
                                            , self.cfg['heroku']['git_remote']))
        self.config('set')
        self.push()
        self.addon('add')

        # if we have domains configured, add them
        if 'domains' in self.cfg['heroku']:
            self.domain('add')

        # handle post deploy steps
        self.run(*self.cfg['heroku']['post_deploy'])

        print '\nHeroku Deploy Complete!'
        url = '==> http://%s.herokuapp.com/' % self.cfg['heroku']['app']
        print url
Пример #5
0
    def delta(self, *apps):
        """
        Creates a new schema changeset for an app.

        Unfortunately, south doesn't allow project-wide schemamigrations, you
        have to provide a specific app name.

        Args:
            apps: a list of apps to create changesets for

        Usage:
            blt south.delta (apps)

        Examples:
            blt south.delta invest payment - creates deltas for invest and
                payment apps
        """
        if not apps:
            abort('\n\nPlease provide an app name, e.g. \n    blt south.delta my_app')

        with cd(self.cfg['django']['DJANGO_ROOT']):
            for app in apps:
                local('python manage.py schemamigration %s --auto' % app)
Пример #6
0
    def _precheck(self, env_type, command):
        if env_type == 'production':
            prod_check(command)

        if env_type not in self.config:
            abort('environment [%s] not defined in your beltenv file.'
                    % env_type)

        if not command:
            abort('you did not specify a command, try again.')

        if command not in self.commands:
            abort('command [%s] not found in your beltenv file.'
                    % command)