-
Notifications
You must be signed in to change notification settings - Fork 5
/
extract.py
88 lines (70 loc) · 2.7 KB
/
extract.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import os
import pathlib
from ranger.api.commands import Command
from ranger.core.loader import CommandLoader
from .archives_utils import parse_escape_args, get_decompression_command
class extract(Command):
def execute(self):
"""Extract copied files to current directory or directory
specified in a command line
"""
cwd = self.fm.thisdir
files = cwd.get_selection()
cwd = self.fm.thisdir
if not files:
return
def refresh(_):
_cwd = self.fm.get_directory(cwd.path)
_cwd.load_content()
dirname = " ".join(self.line.strip().split()[1:])
self.fm.copy_buffer.clear()
self.fm.cut_buffer = False
for file in files:
descr = f"Extracting: {os.path.basename(file.path)}"
command = get_decompression_command(file.path, [], dirname)
obj = CommandLoader(args=command, descr=descr, read=True)
obj.signal_bind('after', refresh)
self.fm.loader.add(obj)
class extract_raw(Command):
def execute(self):
"""Extract copied files to current directory or directory
specified in a command line
"""
cwd = self.fm.thisdir
files = cwd.get_selection()
cwd = self.fm.thisdir
if not files:
return
def refresh(_):
_cwd = self.fm.get_directory(cwd.path)
_cwd.load_content()
flags = parse_escape_args(self.line.strip())[1:]
self.fm.copy_buffer.clear()
self.fm.cut_buffer = False
for file in files:
descr = f"Extracting: {os.path.basename(file.path)}"
command = get_decompression_command(file.path, flags.copy())
obj = CommandLoader(args=command, descr=descr, read=True)
obj.signal_bind('after', refresh)
self.fm.loader.add(obj)
class extract_to_dirs(Command):
def execute(self):
"""Extract copied files to a subdirectories"""
cwd = self.fm.thisdir
files = cwd.get_selection()
cwd = self.fm.thisdir
if not files:
return
def refresh(_):
_cwd = self.fm.get_directory(cwd.path)
_cwd.load_content()
flags = parse_escape_args(self.line.strip())[1:]
self.fm.copy_buffer.clear()
self.fm.cut_buffer = False
for file in files:
descr = f"Extracting: {os.path.basename(file.path)}"
dirname = pathlib.Path(file.path).stem
command = get_decompression_command(file.path, flags.copy(), dirname)
obj = CommandLoader(args=command, descr=descr, read=True)
obj.signal_bind('after', refresh)
self.fm.loader.add(obj)