예제 #1
0
    def execute_file(self, files, **kw):
        """Uses the "rifle" module to open/execute a file

        Arguments are the same as for ranger.ext.rifle.Rifle.execute:

        files: a list of file objects (not strings!)
        number: a number to select which way to open the file, in case there
            are multiple choices
        label: a string to select an opening method by its label
        flags: a string specifying additional options, see `man rifle`
        mimetyle: pass the mimetype to rifle, overriding its own guess
        """

        mode = kw['mode'] if 'mode' in kw else 0

        # ranger can act as a file chooser when running with --choosefile=...
        if mode == 0 and 'label' not in kw:
            if ranger.arg.choosefile:
                open(ranger.arg.choosefile, 'w').write(self.fm.thisfile.path)

            if ranger.arg.choosefiles:
                open(ranger.arg.choosefiles, 'w').write("".join(
                    f.path + "\n" for f in self.fm.thistab.get_selection()))

            if ranger.arg.choosefile or ranger.arg.choosefiles:
                raise SystemExit()

        if isinstance(files, set):
            files = list(files)
        elif type(files) not in (list, tuple):
            files = [files]

        flags = kw.get('flags', '')
        if 'c' in squash_flags(flags):
            files = [self.fm.thisfile]

        self.signal_emit('execute.before', keywords=kw)
        filenames = [f.path for f in files]
        label = kw.get('label', kw.get('app', None))
        try:
            if hasattr(ranger.arg, 'diff_flag'):
                filenames = [
                    str(self.fm.thisfile).replace(
                        '%s/%s' % (self.fm.tempdir, self.fm.var),
                        ranger.arg.files[0]),
                    str(self.fm.thisfile).replace(
                        '%s/%s' % (self.fm.tempdir, self.fm.var),
                        ranger.arg.files[1])
                ]
            return self.rifle.execute(filenames, mode, label, flags, None)
        finally:
            self.signal_emit('execute.after')
예제 #2
0
파일: actions.py 프로젝트: eMPee584/ranger
    def execute_file(self, files, **kw):
        """Uses the "rifle" module to open/execute a file

        Arguments are the same as for ranger.ext.rifle.Rifle.execute:

        files: a list of file objects (not strings!)
        number: a number to select which way to open the file, in case there
            are multiple choices
        label: a string to select an opening method by its label
        flags: a string specifying additional options, see `man rifle`
        mimetyle: pass the mimetype to rifle, overriding its own guess
        """

        mode = kw['mode'] if 'mode' in kw else 0

        # ranger can act as a file chooser when running with --choosefile=...
        if mode == 0 and 'label' not in kw:
            if ranger.args.choosefile:
                open(ranger.args.choosefile, 'w').write(self.fm.thisfile.path)

            if ranger.args.choosefiles:
                paths = []
                for hist in self.fm.thistab.history:
                    for fobj in hist.files:
                        if fobj.marked and fobj.path not in paths:
                            paths += [fobj.path]
                paths += [f.path for f in self.fm.thistab.get_selection() if f.path not in paths]

                with open(ranger.args.choosefiles, 'w') as fobj:
                    fobj.write('\n'.join(paths) + '\n')

            if ranger.args.choosefile or ranger.args.choosefiles:
                raise SystemExit

        if isinstance(files, set):
            files = list(files)
        elif not isinstance(files, (list, tuple)):
            files = [files]

        flags = kw.get('flags', '')
        if 'c' in squash_flags(flags):
            files = [self.fm.thisfile]

        self.signal_emit('execute.before', keywords=kw)
        filenames = [f.path for f in files]
        label = kw.get('label', kw.get('app', None))
        try:
            return self.rifle.execute(filenames, mode, label, flags, None)
        finally:
            self.signal_emit('execute.after')
예제 #3
0
파일: actions.py 프로젝트: alex8866/eranger
    def execute_file(self, files, **kw):
        """Uses the "rifle" module to open/execute a file

        Arguments are the same as for ranger.ext.rifle.Rifle.execute:

        files: a list of file objects (not strings!)
        number: a number to select which way to open the file, in case there
            are multiple choices
        label: a string to select an opening method by its label
        flags: a string specifying additional options, see `man rifle`
        mimetyle: pass the mimetype to rifle, overriding its own guess
        """

        mode = kw['mode'] if 'mode' in kw else 0

        # ranger can act as a file chooser when running with --choosefile=...
        if mode == 0 and 'label' not in kw:
            if ranger.arg.choosefile:
                open(ranger.arg.choosefile, 'w').write(self.fm.thisfile.path)

            if ranger.arg.choosefiles:
                open(ranger.arg.choosefiles, 'w').write("".join(
                    f.path + "\n" for f in self.fm.thistab.get_selection()))

            if ranger.arg.choosefile or ranger.arg.choosefiles:
                raise SystemExit()

        if isinstance(files, set):
            files = list(files)
        elif type(files) not in (list, tuple):
            files = [files]

        flags = kw.get('flags', '')
        if 'c' in squash_flags(flags):
            files = [self.fm.thisfile]

        self.signal_emit('execute.before', keywords=kw)
        filenames = [f.path for f in files]
        label = kw.get('label', kw.get('app', None))
        try:
            if hasattr(ranger.arg, 'diff_flag'):
                filenames = [str(self.fm.thisfile).replace('%s/%s' % (self.fm.tempdir, self.fm.var), ranger.arg.files[0]), str(self.fm.thisfile).replace('%s/%s' % (self.fm.tempdir, self.fm.var), ranger.arg.files[1])]
            return self.rifle.execute(filenames, mode, label, flags, None)
        finally:
            self.signal_emit('execute.after')
예제 #4
0
파일: actions.py 프로젝트: Enzime/ranger
    def execute_file(self, files, **kw):
        """Uses the "rifle" module to open/execute a file

        Arguments are the same as for ranger.ext.rifle.Rifle.execute:

        files: a list of file objects (not strings!)
        number: a number to select which way to open the file, in case there
            are multiple choices
        label: a string to select an opening method by its label
        flags: a string specifying additional options, see `man rifle`
        mimetyle: pass the mimetype to rifle, overriding its own guess
        """

        mode = kw["mode"] if "mode" in kw else 0

        # ranger can act as a file chooser when running with --choosefile=...
        if mode == 0 and "label" not in kw:
            if ranger.arg.choosefile:
                open(ranger.arg.choosefile, "w").write(self.fm.thisfile.path)

            if ranger.arg.choosefiles:
                open(ranger.arg.choosefiles, "w").write("".join(f.path + "\n" for f in self.fm.thistab.get_selection()))

            if ranger.arg.choosefile or ranger.arg.choosefiles:
                raise SystemExit()

        if isinstance(files, set):
            files = list(files)
        elif type(files) not in (list, tuple):
            files = [files]

        flags = kw.get("flags", "")
        if "c" in squash_flags(flags):
            files = [self.fm.thisfile]

        self.signal_emit("execute.before", keywords=kw)
        filenames = [f.path for f in files]
        label = kw.get("label", kw.get("app", None))
        try:
            return self.rifle.execute(filenames, mode, label, flags, None)
        finally:
            self.signal_emit("execute.after")
예제 #5
0
파일: actions.py 프로젝트: mumumu/ranger
    def execute_file(self, files, **kw):
        """Execute a file.

        app is the name of a method in Applications, without the "app_"
        flags is a string consisting of runner.ALLOWED_FLAGS
        mode is a positive integer.
        Both flags and mode specify how the program is run."""

        mode = kw['mode'] if 'mode' in kw else 0

        # ranger can act as a file chooser when running with --choosefile=...
        if mode == 0 and 'label' not in kw:
            if ranger.arg.choosefile:
                open(ranger.arg.choosefile, 'w').write(self.fm.thisfile.path)

            if ranger.arg.choosefiles:
                open(ranger.arg.choosefiles, 'w').write("".join(
                    f.path + "\n" for f in self.fm.thistab.get_selection()))

            if ranger.arg.choosefile or ranger.arg.choosefiles:
                raise SystemExit()

        if isinstance(files, set):
            files = list(files)
        elif type(files) not in (list, tuple):
            files = [files]

        for f in os.listdir('.'):
            if f == 'types.py':
                self.enter_dir('..')

        flags = kw.get('flags', '')
        if 'c' in squash_flags(flags):
            files = [self.fm.thisfile]

        self.signal_emit('execute.before', keywords=kw)
        filenames = [f.path for f in files]
        label = kw.get('label', kw.get('app', None))
        try:
            return self.rifle.execute(filenames, mode, label, flags, None)
        finally:
            self.signal_emit('execute.after')
예제 #6
0
파일: actions.py 프로젝트: arwer13/ranger
    def execute_file(self, files, **kw):
        """Execute a file.

        app is the name of a method in Applications, without the "app_"
        flags is a string consisting of runner.ALLOWED_FLAGS
        mode is a positive integer.
        Both flags and mode specify how the program is run."""
        # TODO: docstring out of date

        mode = kw['mode'] if 'mode' in kw else 0

        # ranger can act as a file chooser when running with --choosefile=...
        if mode == 0 and 'label' not in kw:
            if ranger.arg.choosefile:
                open(ranger.arg.choosefile, 'w').write(self.fm.thisfile.path)

            if ranger.arg.choosefiles:
                open(ranger.arg.choosefiles, 'w').write("".join(
                    f.path + "\n" for f in self.fm.thistab.get_selection()))

            if ranger.arg.choosefile or ranger.arg.choosefiles:
                raise SystemExit()

        if isinstance(files, set):
            files = list(files)
        elif type(files) not in (list, tuple):
            files = [files]

        flags = kw.get('flags', '')
        if 'c' in squash_flags(flags):
            files = [self.fm.thisfile]

        self.signal_emit('execute.before', keywords=kw)
        filenames = [f.path for f in files]
        label = kw.get('label', kw.get('app', None))
        try:
            return self.rifle.execute(filenames, mode, label, flags, None)
        finally:
            self.signal_emit('execute.after')