Commits

sodas tsai committed 2889e15

Refine code

Comments (0)

Files changed (1)

 
 def main():
     command_name = os.path.split(os.path.splitext(__file__)[0])[-1]
-    # get fab file
+    # 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/__init__.py')
 
+    # 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(map(lambda x: '"{0}"'.format(x.replace('"', r'\"')), 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 '    {0} --list'.format(command_name)
         print ''
         with hide('running'):
-            local('fab -f {0} --list'.format(fab_file_path))
+            local('PYTHONPATH={python_path} fab -f {fab_file} --list'.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 ''
         sys.exit(1)
 
-    # 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])
-
     # Go!
-    tasks = ' '.join(map(lambda x: '"{0}"'.format(x.replace('"', r'\"')), sys.argv[1:]))  # Escaping '"'
     with settings(hide('running', 'warnings', 'status'), warn_only=True):
-        local('PYTHONPATH={python_path} fab --linewise -f {fab_file} -u beanstalk --hide=status {tasks}'.format(
-            python_path=python_path, fab_file=fab_file_path, tasks=tasks))
+        local('PYTHONPATH={python_path} fab -f {fab_file} {fab_arguments} {tasks}'.format(**exec_context))
 
 
 if __name__ == '__main__':