Example #1
0
def rsyncFrom(host, src, dst, files=None, options=None, user=None, log=False):
    """
    Copies `files` from `host` in location `src` to the local `dst`.  If `files`
    is None then `src` is assumed to be the actual path to copy.
    """
    cmd = ['rsync']
    if files:
        cmd.append('--files-from=-')
        initialText = '\n'.join(files)
    else:
        initialText = None
        
    if options:
        cmd.append(options)

    if user:
        host = user + '@' + host

    cmd.extend([host + ':' + src, dst])

    return commands.runProcess(commands.shell(str(' '.join(cmd))),
                               expected=[0, 23],
                               stderrf=python.log.err,
                               initialText=str(initialText),
                               log=log)    
Example #2
0
def rsyncTo(host, src, dst, files=None, options=None, user=None, log=False):
    """
    Transfers `files` from `host` in directory `src` to directory `dst`.  If
    `files` is None then it is assumed `src` is the complete path to be copied
    otherwise it is believed to be a list of files in `src`.
    """
    cmd = ['rsync']
    if files:
        cmd.append('--files-from=-')
        initialText = '\n'.join(files)
    else:
        initialText = None
        
    if options:
        cmd.append(options)

    if user:
        host = user + '@' + host

    cmd.extend([src, host + ':' + dst])

    return commands.runProcess(commands.shell(str(' '.join(cmd))),
                               expected=[0, 23],
                               stderrf=python.log.err,
                               initialText=str(initialText),
                               log=log)
Example #3
0
def rsyncTo(host, src, dst, files=None, options=None, user=None, log=False):
    """
    Transfers `files` from `host` in directory `src` to directory `dst`.  If
    `files` is None then it is assumed `src` is the complete path to be copied
    otherwise it is believed to be a list of files in `src`.
    """
    cmd = ['rsync']
    if files:
        cmd.append('--files-from=-')
        initialText = '\n'.join(files)
    else:
        initialText = None

    if options:
        cmd.append(options)

    if user:
        host = user + '@' + host

    cmd.extend([src, host + ':' + dst])

    return commands.runProcess(commands.shell(str(' '.join(cmd))),
                               expected=[0, 23],
                               stderrf=python.log.err,
                               initialText=str(initialText),
                               log=log)
Example #4
0
def _runCommand(_ctype, _baseDir, command, _phantomConfig):
    def _reraise(stderr):
        raise RunCommandError(''.join(stderr))
    stderr = []
    return commands.runProcess(commands.shell(command),
                               stderrf=stderr.append,
                               log=True).addErrback(lambda _ : _reraise(stderr))
Example #5
0
def rsyncFrom(host, src, dst, files=None, options=None, user=None, log=False):
    """
    Copies `files` from `host` in location `src` to the local `dst`.  If `files`
    is None then `src` is assumed to be the actual path to copy.
    """
    cmd = ['rsync']
    if files:
        cmd.append('--files-from=-')
        initialText = '\n'.join(files)
    else:
        initialText = None

    if options:
        cmd.append(options)

    if user:
        host = user + '@' + host

    cmd.extend([host + ':' + src, dst])

    return commands.runProcess(commands.shell(str(' '.join(cmd))),
                               expected=[0, 23],
                               stderrf=python.log.err,
                               initialText=str(initialText),
                               log=log)
Example #6
0
def _unzipFile(fname):
    stdout = StringIO.StringIO()
    yield commands.runProcess(commands.shell('mkdir -p %s && unzip -o -d %s %s' % (os.path.splitext(fname)[0],
                                                                                   os.path.splitext(fname)[0],
                                                                                   fname)),
                              stdoutf=stdout.write,
                              stderrf=log.err)
    log.msg(stdout.getvalue())
    defer.returnValue([str(i.strip().replace('extracting: ', '').replace('inflating: ', '')) for i in stdout.getvalue().split('\n') if ('extracting' in i or 'inflating' in i)])
Example #7
0
def _bunzip2File(fname):
    stdout = StringIO.StringIO()
    yield commands.runProcess(commands.shell('bzcat %s | tar -C %s -xv' %
                                             (fname, os.path.dirname(fname))),
                              stdoutf=stdout.write,
                              stderrf=log.err)
    defer.returnValue([
        str(os.path.join(os.path.dirname(fname), i.strip()))
        for i in stdout.getvalue().split('\n')
    ])
Example #8
0
def _unzipFile(fname):
    stdout = StringIO.StringIO()
    yield commands.runProcess(commands.shell(
        'mkdir -p %s && unzip -o -d %s %s' %
        (os.path.splitext(fname)[0], os.path.splitext(fname)[0], fname)),
                              stdoutf=stdout.write,
                              stderrf=log.err)
    log.msg(stdout.getvalue())
    defer.returnValue([
        str(i.strip().replace('extracting: ', '').replace('inflating: ', ''))
        for i in stdout.getvalue().split('\n')
        if ('extracting' in i or 'inflating' in i)
    ])
Example #9
0
File: ssh.py Project: carze/vappio
def getOutput(host, cmd, sshUser=None, sshFlags=None, initialText=None, log=False, **kwargs):
    command = ['ssh']
    if sshUser:
        host = sshUser + '@' + host

    if sshFlags:
        command.append(sshFlags)

    command.append(host)

    command.append(core.quoteEscape(cmd))

    command = ' '.join(command)

    return commands.getOutput(commands.shell(str(command)),
                              initialText=str(initialText),
                              log=log,
                               **kwargs)
Example #10
0
File: ssh.py Project: carze/vappio
def runProcessSSH(host, cmd, stdoutf, stderrf, sshUser=None, sshFlags=None, initialText=None, log=False, **kwargs):
    command = ['ssh']
    if sshUser:
        host = sshUser + '@' + host

    if sshFlags:
        command.append(sshFlags)

    command.append(host)

    command.append(core.quoteEscape(cmd))

    command = ' '.join(command)

    return commands.runProcess(commands.shell(str(command)),
                               stdoutf=stdoutf,
                               stderrf=stderrf,
                               initialText=str(initialText),
                               log=log,
                               **kwargs)
Example #11
0
def _ungzFile(fname):
    yield commands.runProcess(commands.shell('gzip -dc %s > %s' %
                                             (fname, fname[:-3])),
                              stderrf=log.err)
    defer.returnValue(str(fname[:-3]))
Example #12
0
def _ungzFile(fname):
    yield commands.runProcess(commands.shell('gzip -dc %s > %s' % (fname, fname[:-3])),
                              stderrf=log.err)
    defer.returnValue(str(fname[:-3]))
Example #13
0
def _bunzip2File(fname):
    stdout = StringIO.StringIO()
    yield commands.runProcess(commands.shell('bzcat %s | tar -C %s -xv' % (fname, os.path.dirname(fname))),
                              stdoutf=stdout.write,
                              stderrf=log.err)
    defer.returnValue([str(os.path.join(os.path.dirname(fname), i.strip())) for i in stdout.getvalue().split('\n')])