Ranger:Commands.pyで選択したファイルを抽出するには?

Ranger:Commands.pyで選択したファイルを抽出するには?

私はアーチウィキからこの作品をコピーしました。ただし、選択したファイルを抽出するのではなく、インポートしたファイルを抽出します。だから私は知りたい一つこれら2つ:

  1. 抽出されたファイルの代わりに選択したファイルでextract_hereを作成する方法は?

  2. Commands.pyで選択したファイルを自動的に抽出するには?

    class extract_here(Command):
    def execute(self):
        """ Extract yanked files to current directory.
            HOW TO USE: press yy to yank, then call the method
                        with a shortcut or the command itself."""
        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,
                            read=True)
    
        obj.signal_bind('after', refresh)
        self.fm.loader.add(obj)
        ```
    

ベストアンサー1

解決策:

class extract_here(Command):
def execute(self):
    """ Extract selected files to current directory."""
    import os
    from ranger.core.loader import CommandLoader
    cwd = self.fm.thisdir
    copied_files = tuple(cwd.get_selection())

    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,
                        read=True)

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

アーチウィキで編集、誰もこの問題に直面しないことを願っています。

おすすめ記事