Fabric vs Invoke

Similar to Ruby’s Rake tool, Python has tools for running shell commands and defining/organizing tasks. My personal favorite of the bunch is Fabric, but for those using Python 3, you can consider using Invoke. These tools provide high level APIs for task execution.


from invoke import task, run

def count_files(ctx):
    """ Count files in project folder """
    ctx.run('sudo find . -print0 | xargs -0 -n 1 ls -id | cut -d" " -f1 | sort -u | wc -l')


from fabric.api import *

def count_files():
    with settings(warn_only=True):
        local('find . -print0 | xargs -0 -n 1 ls -id | cut -d" " -f1 | sort -u | wc -l')

Last modified .

Related Posts