Пример #1
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)
Пример #2
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)
Пример #3
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)
Пример #4
0
    def execute(self):

        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)

        descr = "git status in: " + original_path
        obj = CommandLoader(("git", "status"), descr=descr)

        #obj.signal_bind( 'after', refresh )

        self.fm.loader.add(obj)
Пример #5
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)
Пример #6
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)
Пример #7
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)
Пример #8
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)
Пример #9
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)
Пример #10
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)
Пример #11
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)
Пример #12
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)
Пример #13
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,
            read=True)

        obj.signal_bind('after', refresh)
        self.fm.loader.add(obj)
Пример #14
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)
Пример #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

        # 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)
Пример #16
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)
Пример #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)
Пример #18
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)
Пример #19
0
 def execute(self):
     import subprocess
     import os.path
     filename = self.arg(1)
     if not filename.endswith(".md"):
         filename += ".md"
     if not os.path.exists(filename):
         open(filename, 'a').close()
     descr = "editing"
     obj = CommandLoader(args=['x-open', filename], descr=descr, read=True)
     self.fm.loader.add(obj)
Пример #20
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)
Пример #21
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)
Пример #22
0
    def execute(self):

        if self.arg(1):

            commit_msg = self.rest(1)

        else:
            self.fm.notify("You have to provide commit message")
            return

        obj = CommandLoader(args=['git', 'commit', "-m", commit_msg],
                            descr="committing latest changes")

        self.fm.loader.add(obj)
Пример #23
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)
Пример #24
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)
Пример #25
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)
Пример #26
0
 def draw_image(self):
     if self.image and self.need_redraw_image:
         self.source = None
         self.need_redraw_image = False
         try:
             cmd = CommandLoader([img_display.W3MIMGDISPLAY_PATH] +
                                 img_display.W3MIMGDISPLAY_OPTIONS,
                                 input=img_display.generate_w3m_input(
                                     self.image, self.x, self.y, self.wid,
                                     self.hei),
                                 descr="loading preview image",
                                 silent=True,
                                 kill_on_pause=True)
             self.fm.loader.add(cmd)
             self.image_drawn = True
         except img_display.ImgDisplayUnsupportedException:
             self.fm.settings.preview_images = False
         except Exception as e:
             self.fm.notify(e, bad=True)
Пример #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)

            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
                ]
Пример #28
0
 def execute(self):
     """ play all files in current dir """
     thisfile = self.fm.thisfile
     if thisfile.filetype.startswith('inode/directory'):
         files = [
             file.path for file in thisfile.files
             if file.filetype.startswith('video')
         ]
     else:
         files = [thisfile.path]
     descr = "mediacut open"
     obj = CommandLoader(
         args=[
             'mpv', '--no-resume-playback', '--start=0', '--osd-fractions',
             '--osd-level=3'
         ] + files,
         descr=descr,
         read=False,
     )
     self.fm.loader.add(obj)
Пример #29
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)
Пример #30
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)