Esempio n. 1
0
    def _run(
        self,
        args,
        path=None,  # pylint: disable=too-many-arguments
        catchout=True,
        retbytes=False,
        rstrip_newline=True,
    ):
        """Run a command"""
        if self.repotype == "hg":
            # use "chg", a faster built-in client
            cmd = ["chg"] + args
        else:
            cmd = [self.repotype] + args
        if path is None:
            path = self.path

        try:
            if catchout:
                output = spawn.check_output(cmd, cwd=path, decode=not retbytes)
                if not retbytes and rstrip_newline and output.endswith("\n"):
                    return output[:-1]
                return output
            else:
                with open(os.devnull, mode="w") as fd_devnull:
                    subprocess.check_call(cmd, cwd=path, stdout=fd_devnull, stderr=fd_devnull)
                return None
        except (subprocess.CalledProcessError, OSError):
            raise VcsError("{0:s}: {1:s}".format(str(cmd), path))
Esempio n. 2
0
    def infostring(self, fobj, metadata):
        if not fobj.is_directory:
            from subprocess import CalledProcessError

            try:
                fileinfo = spawn.check_output(["file", "-Lb",
                                               fobj.path]).strip()
            except CalledProcessError:
                return "unknown"
            return fileinfo
        else:
            raise NotImplementedError
Esempio n. 3
0
    def restore_multiplexer_name(self):
        if self._multiplexer_title:
            try:
                if _in_tmux():
                    if self._tmux_automatic_rename:
                        check_output([
                            "tmux",
                            "set-window-option",
                            "automatic-rename",
                            self._tmux_automatic_rename,
                        ])
                    else:
                        check_output([
                            "tmux", "set-window-option", "-u",
                            "automatic-rename"
                        ])
            except CalledProcessError:
                self.fm.notify("Could not restore multiplexer window name!",
                               bad=True)

            sys.stdout.write("\033k{0}\033\\".format(self._multiplexer_title))
            sys.stdout.flush()
Esempio n. 4
0
    def handle_multiplexer(self):
        if self.settings.update_tmux_title and not self._multiplexer_title:
            try:
                if _in_tmux():
                    # Stores the automatic-rename setting
                    # prints out a warning if allow-rename isn't set in tmux
                    try:
                        tmux_allow_rename = check_output([
                            "tmux", "show-window-options", "-v", "allow-rename"
                        ]).strip()
                    except CalledProcessError:
                        tmux_allow_rename = "off"
                    if tmux_allow_rename == "off":
                        self.fm.notify(
                            "Warning: allow-rename not set in Tmux!", bad=True)
                    else:
                        self._multiplexer_title = check_output(
                            ["tmux", "display-message", "-p", "#W"]).strip()
                        self._tmux_automatic_rename = check_output([
                            "tmux", "show-window-options", "-v",
                            "automatic-rename"
                        ]).strip()
                        if self._tmux_automatic_rename == "on":
                            check_output([
                                "tmux", "set-window-option",
                                "automatic-rename", "off"
                            ])
                elif _in_screen():
                    # Stores the screen window name before renaming it
                    # gives out a warning if $TERM is not "screen"
                    self._multiplexer_title = check_output(
                        ["screen", "-Q", "title"]).strip()
            except CalledProcessError:
                self.fm.notify(
                    "Couldn't access previous multiplexer window"
                    " name, won't be able to restore.",
                    bad=False,
                )
            if not self._multiplexer_title:
                self._multiplexer_title = os.path.basename(
                    os.environ.get("SHELL", "shell"))

            sys.stdout.write("\033kranger-async\033\\")
            sys.stdout.flush()
Esempio n. 5
0
 def filetype(self):
     try:
         return spawn.check_output(["file", "-Lb", "--mime-type", self.path])
     except OSError:
         return ""
Esempio n. 6
0
 def fasd_add():
     for fobj in fm.thistab.get_selection():
         try:
             check_output(['fasd', '--add', fobj.path])
         except subprocess.CalledProcessError:
             pass