-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
84 lines (66 loc) · 3.39 KB
/
main.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
import os
from ulauncher.api.client.Extension import Extension
from ulauncher.api.client.EventListener import EventListener
from ulauncher.api.shared.event import KeywordQueryEvent, ItemEnterEvent
from ulauncher.api.shared.item.ExtensionResultItem import ExtensionResultItem
from ulauncher.api.shared.action.RenderResultListAction import RenderResultListAction
from ulauncher.api.shared.action.RunScriptAction import RunScriptAction
from ulauncher.api.shared.action.CopyToClipboardAction import CopyToClipboardAction
class NettekimExtension(Extension):
def __init__(self):
super(NettekimExtension, self).__init__()
self.subscribe(KeywordQueryEvent, KeywordQueryEventListener())
class KeywordQueryEventListener(EventListener):
def on_event(self, event, extension):
query = event.get_argument() or str()
script = extension.preferences["script"]
getir = os.popen("lsof -i").read()
boluk = getir.split("\n")
baslk = boluk.pop(0).split()
liste = {}
for j,i in enumerate(boluk):
col = i.split()
if len(col) < 3: continue
col[-2] += col[-1]
col.remove(col[-1])
liste[str(j)] = {}
for t,k in enumerate(col):
liste[str(j)][baslk[t]] = k
# Seçili Stil'i bulur. Sorgu satırına yazılan kod, ayarlardaki koddan üstündür.
selected = extension.preferences["tips"]
for i in ["t0", "t1", "t2", "t3", "t4", "t5", "t6"] :
if i in query:
selected = i
query = query.replace(i,"").strip()
items = []
if selected == "t0":
# Aynı dosya isimleri başlıkta birleştirilmiş, bahlantı adresleri açıklamada
o = {}
for i in liste.keys():
if liste[i]["COMMAND"] in o:
o[liste[i]["COMMAND"]].append(liste[i]["NAME"])
elif "NAME" in liste[i]:
# I couldn't manage to make a merge. Sorry
# fixed: https://github.com/jasonsyoung/ulauncher-nettekim/
o[liste[i]["COMMAND"]] = [liste[i]["NAME"]]
query = query.replace("t0","").strip()
for i in o.keys():
if len(query) > 0 and query not in i:
continue
items.append(ExtensionResultItem(icon='images/icon.png',
name=i,
description="\n".join(o[i]),
on_enter=RunScriptAction(script)))
else:
desc_list = ["NAME", "USER", "PID", "TYPE", "NODE", "DEVICE"]
for i in liste.keys():
if len(query) > 0 and query not in liste[i]["COMMAND"]:
continue
items.append( ExtensionResultItem(icon='images/icon.png',
name=liste[i]["COMMAND"],
description="\n".join([desc_list[u] + " : " + liste[i][desc_list[u]] for u in range(int(selected[1]))]),
on_enter=RunScriptAction(script))
)
return RenderResultListAction(items)
if __name__ == '__main__':
NettekimExtension().run()