Exemplo n.º 1
0
def launch_external_diff(file_a, file_b):
    extdiff = options.get("diff", "extdiff")
    if not extdiff:
        return CmdResult.warning(_("No external diff viewer is defined.\n"))
    try:
        runext.run_cmd_in_bgnd([extdiff, file_a, file_b])
    except OSError as edata:
        return CmdResult.error(
            stderr=_("Error launching external viewer \"{0}\": {1}\n").format(
                extdiff, edata.strerror))
    return CmdResult.ok()
Exemplo n.º 2
0
def os_create_file(file_path):
    """Attempt to create a file with the given file_path and report the outcome as
    a CmdResult tuple.
    1. If console is not None print report of successful creation on it.
    2. If a file with same file_path already exists fail and report a warning.
    3. If file creation fails for other reasons report an error.
    """
    _CONSOLE_LOG.start_cmd("create \"{0}\"".format(file_path))
    if not os.path.exists(file_path):
        try:
            open(file_path, 'w').close()
            enotify.notify_events(E_FILE_ADDED)
            result = CmdResult.ok()
        except (IOError, OSError) as msg:
            result = CmdResult.error(stderr="\"{0}\": {1}".format(file_path, msg))
    else:
        result = CmdResult.warning(stderr=_("\"{0}\": file already exists").format(file_path))
    _CONSOLE_LOG.end_cmd(result)
    return result