-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnautilus-archiveextractor.py
More file actions
59 lines (51 loc) · 1.84 KB
/
Copy pathnautilus-archiveextractor.py
File metadata and controls
59 lines (51 loc) · 1.84 KB
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
from gi.repository import Nautilus, GObject
import os, shlex
extention_2_command = {
".tar.bz2": "tar xjf",
".tar.gz": "tar xzf",
".tar.xz": "tar xf",
".tar.zst": "tar axf",
".xz": "xz -kd",
".bz2": "bunzip2",
".gz": "gunzip",
".tar": "tar xf",
".tbz2": "tar xjf",
".tgz": "tar xzf",
".lzma": "xz -kd",
".rar": "unrar x",
".zip": "unzip",
".z": "uncompress",
".7z": "7z x",
".exe": "cabextract",
".deb": "ar x",
".jar": "jar xf",
}
class ArchiveExtacterMenuProvider(GObject.GObject, Nautilus.MenuProvider):
def get_file_items(self, *args):
files = args[-1]
for file in files:
command = self.suitable_command(file.get_name())
if command:
menu_entry = Nautilus.MenuItem(
name="ArchiveExtracterMenuProvider::extract", label="Extract"
)
menu_entry.connect("activate", self.extract, command, file)
return [menu_entry]
def suitable_command(self, file):
for extendtion, command in extention_2_command.items():
if file.lower().endswith(extendtion):
return command
return None
def extract(self, shit, command, file):
_, fullpath = shlex.quote(file.get_uri()).split("://", maxsplit=1)
_, parent = shlex.quote(file.get_parent_uri()).split("://", maxsplit=1)
os.system(
f"nohup sh -c '"
f"cd {parent} && "
f"{command} {fullpath}; "
"RESULT=$?; "
"ICON=$([ $RESULT -gt 0 ] && echo 'dialog-error' || echo 'dialog-information'); "
"MESSAGE=$([ $RESULT -gt 0 ] && echo 'ERROR' || echo 'EXTRACTED'); "
f"notify-send -i $ICON $MESSAGE -a extractor '{file.get_name()}'"
"' >/dev/null 2>&1 &"
)