Example #1
0
def check_call(*args, **kwargs):
    """Return whether call was successful."""
    try:
        _check_call(*args, **kwargs)
    except CalledProcessError, error:
        log.warn(error)
        return False
Example #2
0
def _resolve_conflict_via_command(a, b, command, a_name, b_name,
                                  _check_call=None):
    import tempfile
    import shutil

    if _check_call is None:
        from subprocess import check_call as _check_call

    from ..vobject import Item

    dir = tempfile.mkdtemp(prefix='vdirsyncer-conflict.')
    try:
        a_tmp = os.path.join(dir, a_name)
        b_tmp = os.path.join(dir, b_name)

        with open(a_tmp, 'w') as f:
            f.write(a.raw)
        with open(b_tmp, 'w') as f:
            f.write(b.raw)

        command[0] = expand_path(command[0])
        _check_call(command + [a_tmp, b_tmp])

        with open(a_tmp) as f:
            new_a = f.read()
        with open(b_tmp) as f:
            new_b = f.read()

        if new_a != new_b:
            raise exceptions.UserError('The two files are not completely '
                                       'equal.')
        return Item(new_a)
    finally:
        shutil.rmtree(dir)
Example #3
0
def check_call(cmd: List[str], *args: Any, **kwargs: Any) -> None:
    shlexed = " ".join([shlex.quote(x) for x in cmd])
    logging.trace("Running '%s'", shlexed)
    _QCMD_LOGGER.info(shlexed)
    try:
        _check_call(cmd, *args, **kwargs)
    except Exception as e:
        logging.error("'%s' failed: %s", shlexed, str(e))
        _QCMD_LOGGER.error(">> %s", str(e))
        raise
Example #4
0
File: util.py Project: haje01/wdfwd
def _cap_call(cmd, retry, _raise, _test=False):
    out = tempfile.TemporaryFile()
    err = tempfile.TemporaryFile()
    res = True
    try:
        logging.info('_cap_call: %s', str(cmd))
        _check_call(cmd, shell=True, stdout=out, stderr=err)
    except CalledProcessError, e:
        logging.error(str(e))
        res = False
        if _raise:
            raise
Example #5
0
def _cap_call(cmd, retry, _raise, _test=False):
    out = tempfile.TemporaryFile()
    err = tempfile.TemporaryFile()
    res = True
    try:
        logging.info('_cap_call: %s', str(cmd))
        _check_call(cmd, shell=True, stdout=out, stderr=err)
    except CalledProcessError, e:
        logging.error(str(e))
        res = False
        if _raise:
            raise
Example #6
0
def check_call(args,
               stdin=None,
               stdout=None,
               stderr=None,
               shell=False,
               cwd=None,
               env=None,
               *popenargs,
               **popenkw):
    cmd = _pre_call(args)

    try:
        return _check_call(args,
                           stdin=stdin,
                           stdout=stdout,
                           stderr=stderr,
                           shell=shell,
                           cwd=cwd,
                           env=env,
                           *popenargs,
                           **popenkw)
    except CalledProcessError as e:
        get_logger().debug("Command %s returned exit code %s." %
                           (cmd, e.returncode))
        raise
Example #7
0
def check_call(args, stdin=None, stdout=None, stderr=None, shell=False, cwd=None, env=None, *popenargs, **popenkw):
    cmd = _pre_call(args)

    try:
        return _check_call(
            args, stdin=stdin, stdout=stdout, stderr=stderr, shell=shell, cwd=cwd, env=env, *popenargs, **popenkw
        )
    except CalledProcessError, e:
        get_logger().debug("Command %s returned exit code %s." % (cmd, e.returncode))
        raise
Example #8
0
def check_call(cmd, **kwargs):
    print 'check_call:'
    print ' '.join(cmd) if isinstance(cmd, list) else cmd
    print

    return _check_call(cmd, **kwargs)
Example #9
0
def check_call(cmd, *args, **kwargs):
    cmdstr = cmd if isinstance(cmd, basestring) else ' '.join(cmd)
    print_log(cmdstr)
    return _check_call(cmd, *args, **kwargs)
Example #10
0
def check_call(cmd_args, *args, **kwargs):
    rc = _check_call(cmd_args, *args, **kwargs)
    print("", COLOR.BOLD, " ".join(args), COLOR.ENDC)
    return rc
Example #11
0
def check_call(cmd, *args, **kwargs):
    cmdstr = cmd if isinstance(cmd, string_types) else ' '.join(cmd)
    print_log(cmdstr)
    return _check_call(cmd, *args, **kwargs)
Example #12
0
def check_call(*args, **kwargs):
    try:
        _check_call(*args, **kwargs)
    except CalledProcessError as e:
        raise UserFacingError(e)
Example #13
0
def check_call(cmd, *args, **kwargs):
    log.info("$ %s" % " ".join(cmd))
    return _check_call(cmd, *args, **kwargs)