beanstalk-stack / beanstalk / bsjack

#!/usr/bin/env python

import os
import sys
from fabric.api import local, hide, settings
from fabric.colors import magenta, green
import beanstalk

def main():
    command_name = os.path.split(os.path.splitext(__file__)[0])[-1]
    # Get fab file
    beanstalk_install_path = os.path.split(os.path.split(beanstalk.__file__)[0])[0]
    beanstalk_package_path = os.path.join(beanstalk_install_path, 'beanstalk')
    fab_file_path = os.path.join(beanstalk_package_path, 'tasks/')

    # Paths
    current_dir = os.getcwd()
    current_container = os.path.abspath(os.path.join(current_dir, '..'))
    original_python_path = os.environ.get('PYTHONPATH', '')
    if original_python_path:
        original_python_path += ':'
    python_path = original_python_path + ':'.join([current_dir, current_container])

    # Task
    # Escaping '"'
    tasks = ' '.join(
        [(component if component.startswith('-') else '"%s"' % component.replace('"', r'\"'))
         for component in sys.argv[1:]])

    # Prepare for the command
    exec_context = {
        'python_path': python_path,
        'fab_file': fab_file_path,
        'fab_arguments': '--linewise -u beanstalk --hide=status',
        'tasks': tasks,

    # Show usage
    if len(sys.argv) < 2:
        print magenta('Beanstalk-Stack man: {0}'.format(command_name), bold=True)
        print 'Hello, I\'m Jack who plant the beanstalk.'
        print 'Beanstalk-Stack version: {0}'.format(beanstalk.__version__)
        print ''
        print 'Usage: '
        print ''
        print '    {0} [options] <command>[:arg1,arg2=val2,host=foo,hosts=\'h1;h2\',...] ...'.format(command_name)
        print '    {0} --list'.format(command_name)
        print ''
        with hide('running'):
            local('PYTHONPATH={python_path} fab -f {fab_file} -l -F nested'.format(**exec_context))
        print ''
        print 'Beanstalk-Stack is built with ' + green('Python-Fabric') + '.'
        print 'So you can pass all arguments for fabric to {0}.'.format(command_name)
        print ''

    # Go!
    with settings(hide('running', 'warnings', 'status'), warn_only=True):
        local('PYTHONPATH={python_path} fab -f {fab_file} {fab_arguments} {tasks}'.format(**exec_context))

if __name__ == '__main__':
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.