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
|
#install dot bin
#Dr. Amr Osman
#dr3mro@gmail.com
#0.2
from gi.repository import Nautilus, GObject
import os
import subprocess
import urllib
class InstallBin(GObject.GObject, Nautilus.MenuProvider):
def __init__(self):
pass
def url2path(self,url):
fileuri= url.get_activation_uri()
arg_uri=fileuri[7:]
path=urllib.url2pathname(arg_uri)
return path
def install(self,menu,file):
file_path=self.url2path(file)
dirname=os.path.dirname(file_path)
script=os.path.basename(file_path)
os.chdir(dirname)
dotslash='./'+script
subprocess.Popen(['gnome-terminal','-x','sudo','sh',dotslash])
return
def check_mimes(self,file):
mime= file.get_mime_type()
allowedmimes=['application/octet-stream']
if mime in allowedmimes:
supported=True
else:
supported=False
return supported
def get_file_items(self, window, files):
filecount=len(files)
if filecount > 0 :
file=files[0]
supported=self.check_mimes(file)
else:
return
if filecount == 1 and supported:
InstallMenu = Nautilus.MenuItem(name='MenuItem::Install',
label='Install',
tip='install',
)
InstallMenu.connect('activate',self.install,file)
return [InstallMenu]
|