def edit_path(path_or_obj, start_text):
    f = path.path(path_or_obj)
    editor = os.getenv("VISUAL") or os.getenv("EDITOR")
    if not editor:
        if platform.system() == "Windows":
            editor = "Notepad.exe"
        else:
            editor = "vi"
    f.write_text(start_text)

    # If absolute, then use the path
    # as is (ticket:4246). Otherwise,
    # use which.py to find it.
    editor_obj = path.path(editor)
    if editor_obj.isabs():
        editor_path = editor
    else:
        from omero_ext.which import which
        editor_path = which(editor)

    pid = os.spawnl(os.P_WAIT, editor_path, editor_path, f)
    if pid:
        re = RuntimeError("Couldn't spawn editor: %s" % editor)
        re.pid = pid
        raise re
示例#2
0
def edit_path(path_or_obj, start_text):
    f = path.path(path_or_obj)
    editor = os.getenv("VISUAL") or os.getenv("EDITOR")
    if not editor:
        if platform.system() == "Windows":
            editor = "Notepad.exe"
        else:
            editor = "vi"

    if isinstance(start_text, str):
        start_text = start_text.encode("utf-8")
    f.write_text(start_text)

    # If absolute, then use the path
    # as is (ticket:4246). Otherwise,
    # use which.py to find it.
    editor_parts = shlex.split(editor)
    editor = editor_parts[0]
    editor_obj = path.path(editor)
    if editor_obj.isabs():
        editor_parts[0] = editor
    else:
        from omero_ext.which import which
        editor_parts[0] = which(editor)
    editor_parts.append(f)

    pid = os.spawnl(os.P_WAIT, editor_parts[0], *tuple(editor_parts))
    if pid:
        re = RuntimeError(
            "Couldn't spawn editor: %s" % editor_parts[0])
        re.pid = pid
        raise re
示例#3
0
def edit_path(path_or_obj, start_text):
    f = path.path(path_or_obj)
    editor = os.getenv("VISUAL") or os.getenv("EDITOR")
    if not editor:
        if platform.system() == "Windows":
            editor = "Notepad.exe"
        else:
            editor = "vi"
    f.write_text(start_text)

    # If absolute, then use the path
    # as is (ticket:4246). Otherwise,
    # use which.py to find it.
    editor_obj = path.path(editor)
    if editor_obj.isabs():
        editor_path = editor
    else:
        from omero_ext.which import which
        editor_path = which(editor)

    pid = os.spawnl(os.P_WAIT, editor_path, editor_path, f)
    if pid:
        re = RuntimeError("Couldn't spawn editor: %s" % editor)
        re.pid = pid
        raise re
示例#4
0
    def which(self, exe):
        from omero_ext import which
        try:
            rv = file = which.which(exe)
        except which.WhichError:
            rv = file = ""

        if file:
            if self.iswin32():
                import win32api
                try:
                    rv = win32api.GetShortPathName(file)
                    if not os.path.exists(rv):
                        rv = file
                except:
                    pass
        return rv
示例#5
0
    def which(self, exe):
        from omero_ext import which
        try:
            rv = file = which.which(exe)
        except which.WhichError:
            rv = file = ""

        if file:
            if self.iswin32():
                import win32api
                try:
                    rv = win32api.GetShortPathName(file)
                    if not os.path.exists(rv):
                        rv = file
                except:
                    pass
        return rv