from fabric.api import sudo, settings, hide


def directory(d, user=None, group=None, mode=None):
    """
    Ensure a directory exists and has given user and/or mode
    """
    sudo("mkdir -p %s" % d)
    if user is not None:
        group = group or user
        sudo("chown %s:%s %s" % (user, group, d))
    if mode is not None:
        sudo("chmod %s %s" % (mode, d))


def exists(path):
    """
    Return True if given path exists on the current remote host.
    """
    cmd = 'test -e "$(echo %s)"' % path
    with settings(hide('everything'), warn_only=True):
        return sudo(cmd).succeeded

@@ -16,20 +16,19 @@
  import 
-sudo
+run
 , settin
@@ -87,16 +87,28 @@
 ode=None
+, runner=run
 ):%0A    %22
@@ -183,20 +183,22 @@
 %22%22%22%0A    
-sudo
+runner
 (%22mkdir 
@@ -268,28 +268,30 @@
 ser%0A        
-sudo
+runner
 (%22chown %25s:%25
@@ -349,20 +349,22 @@
         
-sudo
+runner
 (%22chmod 
@@ -400,16 +400,28 @@
 sts(path
+, runner=run
 ):%0A    %22
@@ -610,12 +610,14 @@
 urn 
-sudo
+runner
 (cmd

Switch patchwork.files to allow runner override