Source

django-fab-deploy-ext / fab_deploy_ext / file.py

Full commit
from fabric.api import run
from fabric.api import local
from fabric.api import sudo
from fabric.api import output
from fabric.api import settings
from fabric.api import hide

from fab_deploy_ext import utils


__all__ = ['file_list', 'file_read']


def file_list(dir):
    with settings(hide('running', 'stdout')):
        # -1 - list one file per line
        out = run('ls -1 %s' % dir)
    for file in utils.split_lines(out):
        yield dir + '/' + file


def file_read(path, use_sudo=False):
    cmd = sudo if use_sudo else run
    with settings(hide('running', 'stdout')):
        out = cmd('cat %s' % path)
    return out