Exemplo n.º 1
0
    def execute(self):
        """
        :extract

        Extract marked files to the current directory
        """
        from os.path import basename
        from ranger.core.loader import CommandLoader

        cwd = self.fm.thisdir
        marked_files = cwd.get_selection()

        if not marked_files:
            return

        def refresh(_):
            cwd = self.fm.env.get_directory(original_path)
            cwd.load_content()

        one_file = marked_files[0]
        original_path = cwd.path
        au_flags = ['-x']
        au_flags += self.line.split()[1:]
        au_flags += ['-e']
        au_flags += ['-D']

        if len(marked_files) == 1:
            descr = "extracting: " + basename(one_file.path)
        else:
            descr = "extracting files from: " + basename(one_file.dirname)
        obj = CommandLoader(args=['aunpack'] + au_flags \
                + [f.path for f in marked_files], descr=descr)

        obj.signal_bind('after', refresh)
        self.fm.loader.add(obj)
Exemplo n.º 2
0
    def execute(self):
        cwd = self.fm.thisdir
        marked_files = cwd.get_selection()

        if not marked_files:
            return

        def refresh(args):
            res = args["process"].communicate()[0].decode("utf-8")
            if res:
                self.fm.cd(res.split(" ")[3].split(".")[0])
            self.fm.notify(" ".join(msg))
            cwd = self.fm.get_directory(original_path)
            cwd.load_content()

        original_path = cwd.path
        au_flags = ["mount", "-b"]

        descr = "mounting ..."
        msg = ["Mounted"]
        for file in marked_files:
            obj = CommandLoader(
                args=["udisksctl"] + au_flags + [file.path], descr=descr
            )
            self.fm.loader.add(obj)
            msg.append('"' + file.path + '"')

        obj.signal_bind("after", refresh)
Exemplo n.º 3
0
    def execute(self):
        """ Extract copied files to current directory """
        copied_files = tuple(self.fm.copy_buffer)

        if not copied_files:
            return

        def refresh(_):
            cwd = self.fm.get_directory(original_path)
            cwd.load_content()

        one_file = copied_files[0]
        cwd = self.fm.thisdir
        original_path = cwd.path
        au_flags = ['-X', cwd.path]
        au_flags += self.line.split()[1:]
        au_flags += ['-e']

        self.fm.copy_buffer.clear()
        self.fm.cut_buffer = False
        if len(copied_files) == 1:
            descr = "extracting: " + os.path.basename(one_file.path)
        else:
            descr = "extracting files from: " + os.path.basename(one_file.dirname)
        obj = CommandLoader(args=['aunpack'] + au_flags \
                + [f.path for f in copied_files], descr=descr)

        obj.signal_bind('after', refresh)
        self.fm.loader.add(obj)
Exemplo n.º 4
0
    def execute(self):
        import os

        cwd = self.fm.thisdir
        cf = self.fm.thisfile
        if not cwd or not cf:
            self.fm.notify("Error: no file selected !", bad=True)
            return
        
        original_path = cwd.path
        files = self.fm.thistab.get_selection()
        languages = self.args[1:]
        if not languages:
            languages = ['en']

        commandLine = ['subliminal', '-l']
        commandLine += languages
        commandLine += ['--']
        commandLine += [f.basename for f in files]
        descr = "Downloading {} subtitle(s)...".format(len(files))

        obj = CommandLoader(args=commandLine , descr=descr)

        def refresh(_):
            cwd = self.fm.env.get_directory(original_path)
            cwd.load_content()
            self.fm.notify("Downloaded {} subtitle(s)".format(len(files)))

        obj.signal_bind('after', refresh)

        self.fm.loader.add(obj) 
Exemplo n.º 5
0
    def execute(self):
        """ Extract copied files to current directory """
        cwd = self.fm.thisdir
        marked_files = cwd.get_selection()

        if not marked_files:
            return

        def refresh(_):
            cwd = self.fm.get_directory(original_path)
            cwd.load_content()

        one_file = marked_files[0]
        original_path = cwd.path
        au_flags = ['-X', cwd.path]
        au_flags += self.line.split()[1:]
        au_flags += ['-e']

        for item in marked_files:
            cwd.toggle_mark(item)

        if len(marked_files) == 1:
            descr = "extracting: " + os.path.basename(one_file.path)
        else:
            descr = "extracting files from: " + os.path.basename(
                one_file.dirname)
        obj = CommandLoader(args=['aunpack'] + au_flags \
                + [f.path for f in marked_files], descr=descr, read=True)

        obj.signal_bind('after', refresh)
        self.fm.loader.add(obj)
Exemplo n.º 6
0
    def execute(self):
        """ extract selected files to current directory."""
        cwd = self.fm.thisdir
        marked_files = tuple(cwd.get_selection())

        def refresh(_):
            cwd = self.fm.get_directory(original_path)
            cwd.load_content()

        one_file = marked_files[0]
        cwd = self.fm.thisdir
        original_path = cwd.path
        au_flags = ['-x', cwd.path]
        au_flags += self.line.split()[1:]
        au_flags += ['-e']

        self.fm.copy_buffer.clear()
        self.fm.cut_buffer = False
        if len(marked_files) == 1:
            descr = "extracting: " + os.path.basename(one_file.path)
        else:
            descr = "extracting files from: " + os.path.basename(
                one_file.dirname)
        obj = CommandLoader(args=['aunpack'] + au_flags
                            + [f.path for f in marked_files], descr=descr,
                            read=True)

        obj.signal_bind('after', refresh)
        self.fm.loader.add(obj)
Exemplo n.º 7
0
    def execute(self):
        cwd = self.fm.thisdir
        marked_files = cwd.get_selection()

        if not marked_files:
            return

        def refresh(args):
            self.fm.notify(" ".join(msg))
            cwd = self.fm.get_directory(original_path)
            cwd.load_content()

        original_path = cwd.path
        au_flags = ["unmount", "-b"]

        descr = "Unmounting ..."
        msg = ["Unmounted"]
        for file in marked_files:
            obj = CommandLoader(
                args=["udisksctl"] + au_flags + [self.checkMountList(file.path)],
                descr=descr,
            )
            self.fm.loader.add(obj)
            msg.append('"' + file.path + '"')

        obj.signal_bind("after", refresh)
Exemplo n.º 8
0
    def execute(self):
        import os
        from ranger.core.loader import CommandLoader
        cwd = self.fm.thisdir
        marked_files = cwd.get_selection()

        if not marked_files:
            return

        def refresh(_):
            cwd = self.fm.get_directory(original_path)
            cwd.load_content()

        original_path = cwd.path

        # Parsing arguments line
        parts = self.line.strip().split()
        if len(parts) > 1:
            au_flags = [' '.join(parts[1:])]
        else:
            au_flags = [os.path.basename(self.fm.thisdir.path) + '.zip']

        # Making description line
        files_num = len(marked_files)
        files_num_str = str(files_num) + ' objects' if files_num > 1 else '1 object'
        descr = "Compressing " + files_num_str + " -> " + os.path.basename(au_flags[0])

        # Creating archive
        obj = CommandLoader(args=['apack'] + au_flags + \
                [os.path.relpath(f.path, cwd.path) for f in marked_files], descr=descr, read=True)

        obj.signal_bind('after', refresh)
        self.fm.loader.add(obj)
Exemplo n.º 9
0
    def execute(self):
        """ Extract copied files to current directory """
        copied_files = tuple(self.fm.copy_buffer)

        if not copied_files:
            return

        def refresh(_):
            cwd = self.fm.get_directory(original_path)
            cwd.load_content()

        one_file = copied_files[0]
        cwd = self.fm.thisdir
        original_path = cwd.path
        au_flags = ['-X', cwd.path]
        au_flags += self.line.split()[1:]
        au_flags += ['-e']

        self.fm.copy_buffer.clear()
        self.fm.cut_buffer = False
        if len(copied_files) == 1:
            descr = "extracting: " + os.path.basename(one_file.path)
        else:
            descr = "extracting files from: " + os.path.basename(
                one_file.dirname)
        obj = CommandLoader(args=['aunpack'] + au_flags \
                + [f.path for f in copied_files], descr=descr)

        obj.signal_bind('after', refresh)
        self.fm.loader.add(obj)
Exemplo n.º 10
0
    def execute(self):
        cwd = self.fm.thisdir
        extract_files = tuple(self.fm.copy_buffer) or cwd.get_selection()

        if not extract_files:
            return

        def refresh(_):
            cwd = self.fm.get_directory(original_path)
            cwd.load_content()

        original_path = cwd.path
        parts = self.line.split()
        au_flags = parts[1:]

        self.fm.copy_buffer.clear()
        self.fm.cut_buffer = False

        descr = "compressing files in: " + Path(parts[1]).name
        obj = CommandLoader(
            args=["apack"]
            + au_flags
            + [Path(f.path).relative_to(cwd.path) for f in extract_files],
            descr=descr,
        )

        obj.signal_bind("after", refresh)
        self.fm.loader.add(obj)
Exemplo n.º 11
0
    def extract(self, files, cleaner=None):
        if not files:
            return

        def refresh(_):
            cwd = self.fm.get_directory(original_path)
            cwd.load_content()

        one_file = files[0]
        cwd = self.fm.thisdir
        original_path = cwd.path
        au_flags = ['-X', cwd.path]
        au_flags += self.line.split()[1:]
        au_flags += ['-e']

        if cleaner:
            cleaner(self)

        if len(files) == 1:
            descr = "extracting: " + os.path.basename(one_file.path)
        else:
            descr = "extracting files from: " + os.path.basename(one_file.dirname)

        obj = CommandLoader(args=['aunpack'] + au_flags \
                + [f.path for f in files], descr=descr)

        obj.signal_bind('after', refresh)
        self.fm.loader.add(obj)
Exemplo n.º 12
0
    def execute(self):
        ''' Compress copied files to current directory '''
        copied_files = tuple(self.fm.copy_buffer)

        if not copied_files:
            return

        def refresh(_):
            cwd = self.fm.get_directory(original_path)
            cwd.load_content()

        one_file = copied_files[0]
        cwd = self.fm.thisdir
        original_path = cwd.path
        parts = self.line.split()
        au_flags = parts[1:]

        descr = 'compressing files in: ' + os.path.basename(parts[1])
        obj = CommandLoader(args=['apack'] + au_flags + \
            [os.path.relpath(f.path, cwd.path) for f in copied_files], descr=descr)

        self.fm.copy_buffer.clear()
        self.fm.do_cut = False

        obj.signal_bind('after', refresh)
        self.fm.loader.add(obj)
Exemplo n.º 13
0
    def execute(self):
        """ Extract copied files to current directory """
        cwd = self.fm.env.cwd
        marked_files = tuple(cwd.get_selection())
        #old version was wih copy instead of mark
        #copied_files = tuple(self.fm.env.copy)

        if not marked_files:
            return

        def refresh(_):
            cwd = self.fm.env.get_directory(original_path)
            cwd.load_content()

        one_file = marked_files[0]
        cwd = self.fm.env.cwd
        original_path = cwd.path
        au_flags = ['-X', cwd.path]
        au_flags += self.line.split()[1:]
        au_flags += ['-e']

        self.fm.env.copy.clear()
        self.fm.env.cut = False
        if len(marked_files) == 1:
            descr = "extracting: " + os.path.basename(one_file.path)
        else:
            descr = "extracting files from: " + os.path.basename(one_file.dirname)
        obj = CommandLoader(args=['aunpack'] + au_flags \
                            + [f.path for f in marked_files], descr=descr)

        obj.signal_bind('after', refresh)
        self.fm.loader.add(obj)
Exemplo n.º 14
0
    def execute(self):
        """ Compress marked files to current directory """
        cwd = self.fm.env.cwd
        marked_files = cwd.get_selection()

        if not marked_files:
            return

        def refresh(_):
            cwd = self.fm.env.get_directory(original_path)
            cwd.load_content()

        original_path = cwd.path
        parts = self.line.split()
        au_flags = parts[1:]

        descr = "compressing files in: " + os.path.basename(parts[1])
        obj = CommandLoader(args=['apack'] + au_flags + \
                            [os.path.relpath(f.path, cwd.path) for f in marked_files], descr=descr)

        obj.signal_bind('after', refresh)
        self.fm.loader.add(obj)

        for f in marked_files:
            cwd.mark_item(f, val=False)
Exemplo n.º 15
0
    def execute(self):
        """ Compress marked files to current directory """
        cwd = self.fm.thisdir
        marked_files = cwd.get_selection()

        if not marked_files:
            return

        def refresh(_):
            cwd = self.fm.get_directory(original_path)
            cwd.load_content()

        original_path = cwd.path
        parts = self.line.split()
        if len(parts) == 1:
            self.fm.notify("usage: apack [flags]", bad=True)
            return
        au_flags = parts[1:]

        descr = "compressing files in: " + os.path.basename(parts[1])
        obj = CommandLoader(args=['apack'] + au_flags + \
                [os.path.relpath(f.path, cwd.path) for f in marked_files], descr=descr)

        obj.signal_bind('after', refresh)
        self.fm.loader.add(obj)
Exemplo n.º 16
0
    def execute(self):
        cwd = self.fm.thisdir
        extract_files = tuple(self.fm.copy_buffer) or cwd.get_selection()

        if not extract_files:
            return

        def refresh(_):
            cwd = self.fm.get_directory(original_path)
            cwd.load_content()

        one_file = extract_files[0]
        cwd = self.fm.thisdir
        original_path = cwd.path
        au_flags = ["-x", "--subdir"]
        au_flags += self.line.split()[1:]
        au_flags += ["-e"]

        self.fm.copy_buffer.clear()
        self.fm.cut_buffer = False

        if len(extract_files) == 1:
            descr = "extracting: " + Path(one_file.path).name
        else:
            descr = "extracting files from: " + Path(one_file.dirname).name
        obj = CommandLoader(
            args=["aunpack"] + au_flags + [f.path for f in extract_files], descr=descr
        )

        obj.signal_bind("after", refresh)
        self.fm.loader.add(obj)
Exemplo n.º 17
0
    def execute(self):
        """
        :compress

        Compress marked files to the current directory
        """
        from ranger.core.loader import CommandLoader

        cwd = self.fm.thisdir
        marked_files = cwd.get_selection()

        if not marked_files:
            return

        original_wd = cwd

        def refresh(_):
            original_wd.load_content(schedule=False)

        parts = self.line.split()
        au_flags = parts[1:]

        descr = "compressing files in: " + os.path.basename(parts[1])
        obj = CommandLoader(args=['apack'] + au_flags + \
                [os.path.relpath(f.path, cwd.path) for f in marked_files], descr=descr)

        obj.signal_bind('after', refresh)
        self.fm.loader.add(obj)
Exemplo n.º 18
0
    def execute(self):
        """ Compress marked files to current directory """
        cwd = self.fm.thisdir
        marked_files = cwd.get_selection()

        if not marked_files:
            return

        def refresh(_):
            cwd = self.fm.get_directory(original_path)
            cwd.load_content()

        original_path = cwd.path
        parts = self.line.split()
        au_flags = parts[1:]

        descr = "compressing files in: " + os.path.basename(parts[1])
        obj = CommandLoader(
            args=["apack"] + au_flags +
            [os.path.relpath(f.path, cwd.path) for f in marked_files],
            descr=descr,
        )

        obj.signal_bind("after", refresh)
        self.fm.loader.add(obj)
Exemplo n.º 19
0
    def execute(self):
        """ Extract copied files to a subdirectories """

        cwd = self.fm.thisdir
        original_path = cwd.path
        copied_files = cwd.get_selection()

        if not copied_files:
            return

        def refresh(_):
            cwd = self.fm.get_directory(original_path)
            cwd.load_content()

        def make_flags(fn):
            flags = ['-D']
            return flags

        one_file = copied_files[0]
        self.fm.copy_buffer.clear()
        self.fm.cut_buffer = False

        # Making description line
        if len(copied_files) == 1:
            descr = "Extracting: " + os.path.basename(one_file.path)
        else:
            descr = "Extracting files from: " + os.path.basename(one_file.dirname)

        # Extracting files
        for f in copied_files:        
            obj = CommandLoader(args=['aunpack'] + make_flags(f.path) + [f.path], descr=descr, read=True)
            obj.signal_bind('after', refresh)
            self.fm.loader.add(obj)
Exemplo n.º 20
0
    def execute(self):
        """ Concatenate video inside cursor folder """
        thisfile = self.fm.thisfile
        if not thisfile.filetype.startswith('inode/directory'):
            return

        marked_files = [
            file.path for file in thisfile.files
            if file.filetype.startswith('video')
        ]

        if not marked_files:
            return

        def refresh(_):
            cwd = self.fm.get_directory(original_path)
            cwd.load_content()

        tmppath = '/tmp/concate-recording'
        with open(tmppath, 'w') as f:
            f.writelines("file {}".format(v) + '\n' for v in marked_files)

        original_path = self.fm.thisdir

        descr = "concatenating"
        obj = CommandLoader(args=[
            'ffmpeg', '-f', 'concat', '-safe', '0', '-i', tmppath, '-c',
            'copy', self.args[1]
        ],
                            descr=descr,
                            read=True)

        obj.signal_bind('after', refresh)
        self.fm.loader.add(obj)
Exemplo n.º 21
0
    def execute(self):
        if not self.arg(1):
            self.fm.notify("Usage: :archive <archive-name>")
            return

        archive_name = self.arg(1)

        if archive_name[:-4] != ".zip":
            archive_name += ".zip"
        
        archive_name = datetime.now().strftime("%Y-%m-%d-") + archive_name
        
        cwd = self.fm.thisdir
        marked_files = cwd.get_selection()

        if not marked_files:
            return

        def refresh(_):
            cwd = self.fm.get_directory(original_path)
            cwd.load_content()
       
        descr = "archiving files..."
        obj = CommandLoader(args=['apack'] + [archive_name] + [os.path.relpath(f.path, cwd.path) for f in marked_files], descr=descr, read=True)
        obj.signal_bind('after', refresh)
        self.fm.loader.add(obj)
Exemplo n.º 22
0
    def execute(self):
        """ Compress copied files to current directory """
        copied_files = tuple(self.fm.copy_buffer)

        if not copied_files:
            return

        def refresh(_):
            cwd = self.fm.get_directory(original_path)
            cwd.load_content()

        one_file = copied_files[0]
        cwd = self.fm.thisdir
        original_path = cwd.path
        parts = self.line.split()
        au_flags = parts[1:]

        descr = "compressing files in: " + os.path.basename(parts[1])
        obj = CommandLoader(args=['apack'] + au_flags + \
            [os.path.relpath(f.path, cwd.path) for f in copied_files], descr=descr)

        self.fm.copy_buffer.clear()
        self.fm.do_cut = False

        obj.signal_bind('after', refresh)
        self.fm.loader.add(obj)
Exemplo n.º 23
0
    def execute(self):
        """ Create tar gz archive of selected files """
        selected_files = self.fm.thistab.get_selection()
        if not selected_files:
            return

        output = "out.tar.gz"
        args = self.line.split()[1:]
        if len(args) > 0:
            output = args[0]

        original_path = self.fm.thisdir.path
        def refresh(_):
            cwd = self.fm.get_directory(original_path)
            cwd.load_content()

        self.fm.mark_files(all=True, val=False)

        tar_flags = ['-czvf', output]
        tar_flags += ['--xform', 's,%s/,,' % original_path[1:]]

        descr = "Creating archive"
        obj = CommandLoader(args=['tar'] + tar_flags + [f.path for f in selected_files], descr=descr)

        obj.signal_bind('after', refresh)
        self.fm.loader.add(obj)
Exemplo n.º 24
0
def annex_call(fm, cmds, fname):
    # git annex fails with absolute paths ...
    thisdir = fm.thisdir
    fname = os.path.basename(fname)
    loader = CommandLoader(['git', 'annex'] + cmds + [fname],
                           'annex:{}'.format(' '.join(cmds)))

    def reload_dir():
        thisdir.unload()
        thisdir.load_content()

    loader.signal_bind('after', reload_dir)
    fm.loader.add(loader)
Exemplo n.º 25
0
def annex_call(fm, cmds, fname):
    # git annex fails with absolute paths ...
    thisdir = fm.thisdir
    fname = os.path.basename(fname)
    loader = CommandLoader(['git', 'annex'] + cmds + [fname],
                           'annex:{}'.format(' '.join(cmds)))

    def reload_dir():
        thisdir.unload()
        thisdir.load_content()

    loader.signal_bind('after', reload_dir)
    fm.loader.add(loader)
Exemplo n.º 26
0
    def _extract(self, files, destination=None):
        args = ['aunpack', '-e']
        if destination is None:
            args.extend((shell_escape(f.path) for f in files))
            command = tmux_command(args)
        else:
            au_flags += ['-X', destination]
            obj = CommandLoader(args=['aunpack'] + au_flags \
                + [f.path for f in files], descr=descr)

            obj.signal_bind('after', refresh)
            self.fm.loader.add(obj)
        self.fm.execute_command(command)
Exemplo n.º 27
0
        def refresh(_):
            cwd = self.fm.get_directory(original_path)
            cwd.load_content()

            original_path = cwd.path
            parts = self.line.split()
            au_flags = parts[1:]

            descr = "Compressing files in: " + os.path.basename(parts[1])
            obj = CommandLoader(args=['apack'] + au_flags + \
                [os.path.relpath(f.path, cwd.path) for f in marked_files], descr=descr)

            obj.signal_bind('after', refresh)
            self.fm.loader.add(obj)
Exemplo n.º 28
0
	def paste(self, overwrite=False):
		"""Paste the selected items into the current directory"""
		copied_files = tuple(self.env.copy)

		if not copied_files:
			return

		def refresh(_):
			cwd = self.env.get_directory(original_path)
			cwd.load_content()

		cwd = self.env.cwd
		original_path = cwd.path
		one_file = copied_files[0]
		if overwrite:
			cp_flags = ['-af', '--']
			mv_flags = ['-f', '--']
		else:
			cp_flags = ['--backup=numbered', '-a', '--']
			mv_flags = ['--backup=numbered', '--']

		if self.env.cut:
			self.env.copy.clear()
			self.env.cut = False
			if len(copied_files) == 1:
				descr = "moving: " + one_file.path
			else:
				descr = "moving files from: " + one_file.dirname
			obj = CommandLoader(args=['mv'] + mv_flags \
					+ [f.path for f in copied_files] \
					+ [cwd.path], descr=descr)
		else:
			if len(copied_files) == 1:
				descr = "copying: " + one_file.path
			else:
				descr = "copying files from: " + one_file.dirname
			if not overwrite and len(copied_files) == 1 \
					and one_file.dirname == cwd.path:
				# Special case: yypp
				# copying a file onto itself -> create a backup
				obj = CommandLoader(args=['cp', '-f'] + cp_flags \
						+ [one_file.path, one_file.path], descr=descr)
			else:
				obj = CommandLoader(args=['cp'] + cp_flags \
						+ [f.path for f in copied_files] \
						+ [cwd.path], descr=descr)

		obj.signal_bind('after', refresh)
		self.loader.add(obj)
Exemplo n.º 29
0
    def paste(self, overwrite=False):
        """Paste the selected items into the current directory"""
        copied_files = tuple(self.env.copy)

        if not copied_files:
            return

        def refresh(_):
            cwd = self.env.get_directory(original_path)
            cwd.load_content()

        cwd = self.env.cwd
        original_path = cwd.path
        one_file = copied_files[0]
        if overwrite:
            cp_flags = ['-af', '--']
            mv_flags = ['-f', '--']
        else:
            cp_flags = ['--backup=numbered', '-a', '--']
            mv_flags = ['--backup=numbered', '--']

        if self.env.cut:
            self.env.copy.clear()
            self.env.cut = False
            if len(copied_files) == 1:
                descr = "moving: " + one_file.path
            else:
                descr = "moving files from: " + one_file.dirname
            obj = CommandLoader(args=['mv'] + mv_flags \
              + [f.path for f in copied_files] \
              + [cwd.path], descr=descr)
        else:
            if len(copied_files) == 1:
                descr = "copying: " + one_file.path
            else:
                descr = "copying files from: " + one_file.dirname
            if not overwrite and len(copied_files) == 1 \
              and one_file.dirname == cwd.path:
                # Special case: yypp
                # copying a file onto itself -> create a backup
                obj = CommandLoader(args=['cp', '-f'] + cp_flags \
                  + [one_file.path, one_file.path], descr=descr)
            else:
                obj = CommandLoader(args=['cp'] + cp_flags \
                  + [f.path for f in copied_files] \
                  + [cwd.path], descr=descr)

        obj.signal_bind('after', refresh)
        self.loader.add(obj)
Exemplo n.º 30
0
 def refresh(_):
     cwd = self.fm.get_directory(original_path)
     cwd.load_content()
     original_path = cwd.path
     parts = self.line.split()
     au_flags = parts[1:]
     descr = "compressing files in: " + os.path.basename(parts[1])
     obj = CommandLoader(args=['apack'] + au_flags + \
             [os.path.relpath(f.path, cwd.path) for f in marked_files], descr=descr)
     obj.signal_bind('after', refresh)
     self.fm.loader.add(obj)
     def tab(self):
         """ Complete with current folder name """
         extension = ['.zip', '.tar.gz', '.rar', '.7z']
         return ['compress ' + os.path.basename(self.fm.thisdir.path) + ext for ext in extension]
Exemplo n.º 31
0
    def execute(self):
        """ Extract current file to current directory with 7z """

        archive = self.fm.thisfile
        cwd = self.fm.thisdir
        original_path = cwd.path

        def refresh(_):
            cwd = self.fm.get_directory(original_path)
            cwd.load_content()

        flags = ['x', archive.path]
        descr = "Extracting: " + archive.basename
        obj = CommandLoader(args=['7z'] + flags, descr=descr, read=True)
        call(["notify-send", descr, "-i", "package-x-generic"])
        obj.signal_bind('after', refresh)
        self.fm.loader.add(obj)
Exemplo n.º 32
0
    def execute(self):
        """Extract copied files to current directory or directory
        specified in a command line
        """

        cwd = self.fm.thisdir
        copied_files = cwd.get_selection()

        if not copied_files:
            return

        def refresh(_):
            cwd = self.fm.get_directory(original_path)
            cwd.load_content()

        one_file = copied_files[0]
        cwd = self.fm.thisdir
        original_path = cwd.path

        line_args = self.line.split()[1:]
        if line_args:
            extraction_dir = os.path.join(cwd.path, "".join(line_args))
            os.makedirs(extraction_dir, exist_ok=True)
            flags = ['-X', extraction_dir]
            flags += ['-e']
        else:
            flags = ['-X', cwd.path]
            flags += ['-e']

        self.fm.copy_buffer.clear()
        self.fm.cut_buffer = False

        if len(copied_files) == 1:
            descr = "Extracting: " + os.path.basename(one_file.path)
        else:
            descr = "Extracting files from: " + \
                os.path.basename(one_file.dirname)
        obj = CommandLoader(args=['aunpack'] + flags +
                            [f.path for f in copied_files],
                            descr=descr,
                            read=True)

        obj.signal_bind('after', refresh)
        self.fm.loader.add(obj)
Exemplo n.º 33
0
        def refresh(_):
            cwd = self.fm.get_directory(original_path)
            cwd.load_content()
            original_path = cwd.path
            parts = self.line.split()
            au_flags = parts[1:]
            descr = "compressing files in: " + os.path.basename(parts[1])
            obj = CommandLoader(args=['apack'] + au_flags + \
                    [os.path.relpath(f.path, cwd.path) for f in marked_files], descr=descr)
            obj.signal_bind('after', refresh)
            self.fm.loader.add(obj)

            def tab(self):
                """ Complete with current folder name """
                extension = ['.zip', '.tar.gz', '.rar', '.7z']
                return [
                    'compress ' + os.path.basename(self.fm.thisdir.path) + ext
                    for ext in extension
                ]
Exemplo n.º 34
0
    def execute(self):
        """
        :extract

        Extract all files in the currently selected archive to a subdirectory (depends on atool)
        """
        import os

        current_archive = self.fm.thisfile

        def refresh(_):
            self.fm.thisdir.load_content()

        descr = "extracting: " + os.path.basename(current_archive.path)
        obj = CommandLoader(args=['aunpack'] + [current_archive.path],
                            descr=descr)

        obj.signal_bind('after', refresh)
        self.fm.loader.add(obj)
Exemplo n.º 35
0
    def execute(self):
        copied_files = tuple(self.fm.copy_buffer)

        if not copied_files:
            return

        cwd = self.fm.thisdir
        new_name = self.rest(1)

        if not new_name:
            return
        # shell cp/mv %c 

        def refresh(_):
            cwd = self.fm.get_directory(original_path)
            cwd.load_content()

        original_path = cwd.path
        one_file = copied_files[0]

        cp_flags = ['--backup=numbered', '-a', '--']
        mv_flags = ['--backup=numbered', '--']

        if self.fm.do_cut:
            self.fm.copy_buffer.clear()
            self.fm.do_cut = False
            if len(copied_files) == 1:
                descr = "moving: " + one_file.path
            else:
                descr = "moving files from: " + one_file.dirname
            obj = CommandLoader(args=['mv'] + mv_flags \
                    + [f.path for f in copied_files] \
                    + [new_name], descr=descr)
        else:
            descr = "copying files from: " + one_file.dirname
            obj = CommandLoader(args=['cp'] + cp_flags \
                    + [f.path for f in copied_files] \
                    + [new_name], descr=descr)

        obj.signal_bind('after', refresh)
        self.fm.loader.add(obj)
Exemplo n.º 36
0
    def execute(self):
        ''' Compress marked files to current directory '''
        cwd = self.fm.thisdir
        marked_files = cwd.get_selection()

        if not marked_files:
            return

        def refresh(_):
            cwd = self.fm.get_directory(original_path)
            cwd.load_content()

        original_path = cwd.path
        dest = self.line[self.line.index(' ') + 1:]

        descr = 'compressing files in: ' + os.path.basename(dest)
        obj = CommandLoader(args=['apack', dest] + \
            [os.path.relpath(f.path, cwd.path) for f in marked_files], descr=descr)

        obj.signal_bind('after', refresh)
        self.fm.loader.add(obj)
Exemplo n.º 37
0
    def execute(self):
        """ Compress marked files to current directory """
        cwd = self.fm.thisdir
        marked_files = cwd.get_selection()

        if not marked_files:
            return

        def refresh(_):
            cwd = self.fm.get_directory(original_path)
            cwd.load_content()

        original_path = cwd.path
        dest = self.line[self.line.index(' ')+1:]

        descr = "compressing files in: " + os.path.basename(dest)
        obj = CommandLoader(args=['apack', dest] + \
            [os.path.relpath(f.path, cwd.path) for f in marked_files], descr=descr)

        obj.signal_bind('after', refresh)
        self.fm.loader.add(obj)
Exemplo n.º 38
0
    def execute(self):
        cwd = self.fm.thisdir
        marked_files = cwd.get_selection()

        if not marked_files:
            return

        def refresh(args):
            self.fm.notify(" ".join(msg))
            cwd = self.fm.get_directory(original_path)
            cwd.load_content()

        original_path = cwd.path
        au_flags = ["-resize"]

        # check 600x1200 or 60(%)
        size = self.line.split()[1]
        if "x" not in size:
            size = size + "%"
        au_flags += [size]

        resize_dirname = f"resize_{size}"
        Path(original_path, resize_dirname).mkdir(parents=True, exist_ok=True)

        src_paths = [file.path for file in marked_files]
        dest_paths = [
            Path(Path(path).parent, resize_dirname, Path(path).name)
            for path in src_paths
        ]

        descr = "Resizing ..."
        msg = ["Resized"]
        for s_path, d_path in zip(src_paths, dest_paths):
            obj = CommandLoader(
                args=["convert"] + au_flags + [s_path] + [d_path], descr=descr
            )

            self.fm.loader.add(obj)
        obj.signal_bind("after", refresh)
Exemplo n.º 39
0
    def execute(self):

        cwd = self.fm.thisdir

        def refresh(_):
            cwd = self.fm.get_directory(original_path)
            cwd.load_content()

        original_path = cwd.path

        if self.arg(1):

            target_filenames = self.rest(1)

        else:

            target_filenames = cwd.get_selection()

        for tf in target_filenames:

            if not os.path.exists(tf.path):
                self.fm.notify("The given file does not exist! " +
                               os.path.relpath(tf.path, cwd.path),
                               bad=True)
                return

        rel_filenames = [
            os.path.relpath(f.path, cwd.path) for f in target_filenames
        ]

        descr = "Adding file(s) " + " ".join(rel_filenames) + " to git"

        self.fm.notify(descr)

        obj = CommandLoader(args=['git', 'add'] + rel_filenames, descr=descr)

        obj.signal_bind('after', refresh)
        self.fm.loader.add(obj)
Exemplo n.º 40
0
    def execute(self):
        """ Extract marked files to current directory """
        cwd = self.fm.thisdir
        marked_files = cwd.get_selection()

        if not marked_files or len(marked_files) > 1:
            self.fm.notify("mark a single file", bad=True)
            return

        def refresh(_):
            cwd = self.fm.get_directory(original_path)
            cwd.load_content()

        original_path = cwd.path
        parts = self.line.split()
        au_flags = parts[1:] + ['-f']

        descr = "extracting files"
        obj = CommandLoader(args=['aunpack'] + au_flags + \
                [os.path.relpath(f.path, cwd.path) for f in marked_files], descr=descr)

        obj.signal_bind('after', refresh)
        self.fm.loader.add(obj)
Exemplo n.º 41
0
    def execute(self):

        obj = None

        if not self.arg(1):
            self.fm.notify('Syntax: j <pathname>')
            return

        def handle_results(_):
            lines = obj.stdout_buffer.split('\n')
            path = None

            for line in lines:
                splits = line.split(' ', 1)

                if len(splits) < 2:
                    break

                count, path = splits
                count = count.strip()
                path = path.strip()

                if count == 'common:':
                    break

            if path:
                self.fm.cd(path)
            else:
                self.fm.notify('Nothing matched.')

        z_path = os.path.expanduser('~/Tools/z/z.sh')
        cmd = 'source {} && _z -l {} 2>&1'.format(z_path, self.arg(1))
        obj = CommandLoader(args=['/usr/bin/zsh', '-c', cmd],
                            descr='Running z',
                            read=True)
        obj.signal_bind('after', handle_results)
        self.fm.loader.add(obj)
Exemplo n.º 42
0
    def execute(self):
        """
        :extract

        Extract marked files to the current directory
        """
        from os.path import basename
        from ranger.core.loader import CommandLoader

        cwd = self.fm.thisdir
        marked_files = cwd.get_selection()

        if not marked_files:
            return

        one_file = marked_files[0]

        original_wd = cwd

        def refresh(_):
            self.fm.thisdir.load_content(schedule=False)

        au_flags = ['-x']
        au_flags += self.line.split()[1:]
        au_flags += ['-e']
        au_flags += ['-D']

        if len(marked_files) == 1:
            descr = "extracting: " + basename(one_file.path)
        else:
            descr = "extracting files from: " + basename(one_file.dirname)
        obj = CommandLoader(args=['aunpack'] + au_flags \
                + [f.path for f in marked_files], descr=descr)

        obj.signal_bind('after', refresh)
        self.fm.loader.add(obj)
Exemplo n.º 43
0
    def get_preview(self, file, width, height):
        pager = self.ui.get_pager()
        path = file.realpath

        if not path or not os.path.exists(path):
            return None

        if self.settings.preview_script and self.settings.use_preview_script:
            # self.previews is a 2 dimensional dict:
            # self.previews['/tmp/foo.jpg'][(80, 24)] = "the content..."
            # self.previews['/tmp/foo.jpg']['loading'] = False
            # A -1 in tuples means "any"; (80, -1) = wid. of 80 and any hei.
            # The key 'foundpreview' is added later. Values in (True, False)
            # XXX: Previews can break when collapse_preview is on and the
            # preview column is popping out as you move the cursor on e.g. a
            # PDF file.
            try:
                data = self.previews[path]
            except:
                data = self.previews[path] = {'loading': False}
            else:
                if data['loading']:
                    return None


            found = data.get((-1, -1), data.get((width, -1),
                data.get((-1, height), data.get((width, height), False))))
            if found == False:
                try:
                    stat_ = os.stat(self.settings.preview_script)
                except:
                    self.fm.notify("Preview Script `%s' doesn't exist!" %
                            self.settings.preview_script, bad=True)
                    return None

                if not stat_.st_mode & S_IEXEC:
                    self.fm.notify("Preview Script `%s' is not executable!" %
                            self.settings.preview_script, bad=True)
                    return None

                data['loading'] = True

                if 'directimagepreview' in data:
                    data['foundpreview'] = True
                    data['imagepreview'] = True
                    pager.set_image(path)
                    data['loading'] = False
                    return path

                cacheimg = os.path.join(ranger.arg.cachedir, self.sha1_encode(path))
                if (os.path.isfile(cacheimg) and os.path.getmtime(cacheimg) > os.path.getmtime(path)):
                    data['foundpreview'] = True
                    data['imagepreview'] = True
                    pager.set_image(cacheimg)
                    data['loading'] = False
                    return cacheimg

                loadable = CommandLoader(args=[self.settings.preview_script,
                    path, str(width), str(height), cacheimg,
                    str(self.settings.preview_images)], read=True,
                    silent=True, descr="Getting preview of %s" % path)
                def on_after(signal):
                    exit = signal.process.poll()
                    content = signal.loader.stdout_buffer
                    data['foundpreview'] = True
                    if exit == 0:
                        data[(width, height)] = content
                    elif exit == 3:
                        data[(-1, height)] = content
                    elif exit == 4:
                        data[(width, -1)] = content
                    elif exit == 5:
                        data[(-1, -1)] = content
                    elif exit == 6:
                        data['imagepreview'] = True
                    elif exit == 7:
                        data['directimagepreview'] = True
                    elif exit == 1:
                        data[(-1, -1)] = None
                        data['foundpreview'] = False
                    elif exit == 2:
                        f = codecs.open(path, 'r', errors='ignore')
                        try:
                            data[(-1, -1)] = f.read(1024 * 32)
                        except UnicodeDecodeError:
                            f.close()
                            f = codecs.open(path, 'r', encoding='latin-1',
                                    errors='ignore')
                            data[(-1, -1)] = f.read(1024 * 32)
                        f.close()
                    else:
                        data[(-1, -1)] = None
                    if self.thisfile and self.thisfile.realpath == path:
                        self.ui.browser.need_redraw = True
                    data['loading'] = False
                    pager = self.ui.get_pager()
                    if self.thisfile and self.thisfile.is_file:
                        if 'imagepreview' in data:
                            pager.set_image(cacheimg)
                            return cacheimg
                        elif 'directimagepreview' in data:
                            pager.set_image(path)
                            return path
                        else:
                            pager.set_source(self.thisfile.get_preview_source(
                                pager.wid, pager.hei))
                def on_destroy(signal):
                    try:
                        del self.previews[path]
                    except:
                        pass
                loadable.signal_bind('after', on_after)
                loadable.signal_bind('destroy', on_destroy)
                self.loader.add(loadable)
                return None
            else:
                return found
        else:
            try:
                return codecs.open(path, 'r', errors='ignore')
            except:
                return None
Exemplo n.º 44
0
	def get_preview(self, path, width, height):
		if self.settings.preview_script and self.settings.use_preview_script:
			# self.previews is a 2 dimensional dict:
			# self.previews['/tmp/foo.jpg'][(80, 24)] = "the content..."
			# self.previews['/tmp/foo.jpg']['loading'] = False
			# A -1 in tuples means "any"; (80, -1) = wid. of 80 and any hei.
			# The key 'foundpreview' is added later. Values in (True, False)
			try:
				data = self.previews[path]
			except:
				data = self.previews[path] = {'loading': False}
			else:
				if data['loading']:
					return None

			found = data.get((-1, -1), data.get((width, -1),
				data.get((-1, height), data.get((width, height), False))))
			if found == False:
				data['loading'] = True
				loadable = CommandLoader(args=[self.settings.preview_script,
					path, str(width), str(height)], read=True,
					silent=True, descr="Getting preview of %s" % path)
				def on_after(signal):
					exit = signal.process.poll()
					content = signal.loader.stdout_buffer
					data['foundpreview'] = True
					if exit == 0:
						data[(width, height)] = content
					elif exit == 3:
						data[(-1, height)] = content
					elif exit == 4:
						data[(width, -1)] = content
					elif exit == 5:
						data[(-1, -1)] = content
					elif exit == 1:
						data[(-1, -1)] = None
						data['foundpreview'] = False
					elif exit == 2:
						data[(-1, -1)] = open(path, 'r').read(1024 * 32)
					else:
						data[(-1, -1)] = None
					if self.env.cf.realpath == path:
						self.ui.browser.need_redraw = True
					data['loading'] = False
					pager = self.ui.browser.pager
					if self.env.cf and self.env.cf.is_file:
						pager.set_source(self.env.cf.get_preview_source(
							pager.wid, pager.hei))
				def on_destroy(signal):
					try:
						del self.previews[path]
					except:
						pass
				loadable.signal_bind('after', on_after)
				loadable.signal_bind('destroy', on_destroy)
				self.loader.add(loadable)
				return None
			else:
				return found
		else:
			try:
				return open(path, 'r')
			except:
				return None
Exemplo n.º 45
0
	def get_preview(self, path, width, height):
		if self.settings.preview_script and self.settings.use_preview_script:
			# self.previews is a 2 dimensional dict:
			# self.previews['/tmp/foo.jpg'][(80, 24)] = "the content..."
			# self.previews['/tmp/foo.jpg']['loading'] = False
			# A -1 in tuples means "any"; (80, -1) = wid. of 80 and any hei.
			# The key 'foundpreview' is added later. Values in (True, False)
			# XXX: Previews can break when collapse_preview is on and the
			# preview column is popping out as you move the cursor on e.g. a
			# PDF file.
			try:
				data = self.previews[path]
			except:
				data = self.previews[path] = {'loading': False}
			else:
				if data['loading']:
					return None

			found = data.get((-1, -1), data.get((width, -1),
				data.get((-1, height), data.get((width, height), False))))
			if found == False:
				data['loading'] = True
				loadable = CommandLoader(args=[self.settings.preview_script,
					path, str(width), str(height)], read=True,
					silent=True, descr="Getting preview of %s" % path)
				def on_after(signal):
					exit = signal.process.poll()
					content = signal.loader.stdout_buffer
					data['foundpreview'] = True
					if exit == 0:
						data[(width, height)] = content
					elif exit == 3:
						data[(-1, height)] = content
					elif exit == 4:
						data[(width, -1)] = content
					elif exit == 5:
						data[(-1, -1)] = content
					elif exit == 1:
						data[(-1, -1)] = None
						data['foundpreview'] = False
					elif exit == 2:
						f = codecs.open(path, 'r', errors='ignore')
						try:
							data[(-1, -1)] = f.read(1024 * 32)
						except UnicodeDecodeError:
							f.close()
							f = codecs.open(path, 'r', encoding='latin-1',
									errors='ignore')
							data[(-1, -1)] = f.read(1024 * 32)
						f.close()
					else:
						data[(-1, -1)] = None
					if self.thisfile.realpath == path:
						self.ui.browser.need_redraw = True
					data['loading'] = False
					pager = self.ui.browser.pager
					if self.thisfile and self.thisfile.is_file:
						pager.set_source(self.thisfile.get_preview_source(
							pager.wid, pager.hei))
				def on_destroy(signal):
					try:
						del self.previews[path]
					except:
						pass
				loadable.signal_bind('after', on_after)
				loadable.signal_bind('destroy', on_destroy)
				self.loader.add(loadable)
				return None
			else:
				return found
		else:
			try:
				return codecs.open(path, 'r', errors='ignore')
			except:
				return None