-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.py
executable file
·75 lines (70 loc) · 2.65 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
#! /usr/bin/env python3
# Configuration happens here
icontheme='gnome'
# End of Configuration
import os
import sys
import glob
import http.server
import socketserver
import logging
import cgi
from urllib.parse import urlparse
import xdg.DesktopEntry as entryhandler
import xdg.IconTheme as ic
workingdirectory=os.getcwd()
i = ic.IconTheme()
i.parse('/usr/share/icons/gnome/index.theme')
if not os.path.exists('system'):
os.symlink("/", "system")
apps = []
def init():
try:
os.remove('index.html')
except:
print("Old Menu file could not be removed")
menu = open('index.html', 'a')
menu.write("<head><script src='list.min.js'></script><link rel='stylesheet' type='text/css' href='style.css'><script language='javascript' type='text/javascript'>\n function closeWindow() { window.open('','_parent',''); window.close(); }</script><script language='javascript' type='text/javascript'>function startList() {var options = {valueNames: [ 'name']};var userList = new List('users', options);}</script></head><body onload='startList()'><div id='users'><input class='search' placeholder='Search' /><button class='sort' data-sort='name'>Sort by name</button><ul class='list'>")
os.chdir('/usr/share/applications')
id=0
for file in glob.glob("*.desktop"):
entry=entryhandler.DesktopEntry(filename=file)
apps.append({'Name': entry.getName(), 'Icon':'system' + str(ic.getIconPath(entry.getIcon())), 'Exec':'xiwi '+entry.getExec().split('%',1)[0], 'id':id})
id=id+1
for app in apps:
menu.write("<li><a class='name' href='index.html?id=" + str(app['id']) + "' onclick='closeWindow()'><img class='icon' height='48' width='48' src='" + app['Icon'] + "'>" +app['Name'] + '</a></li>')
menu.write('</div></body>')
menu.close()
def serve():
os.chdir(workingdirectory)
PORT = 8000
class ServerHandler(http.server.SimpleHTTPRequestHandler):
def do_GET(self):
parsed_path = urlparse(self.path)
try:
params = dict([p.split('=') for p in parsed_path[4].split('&')])
except:
params = {}
if params:
for app in apps:
if str(app['id']) == str(params['id']).strip("/"):
print(app['Name'], " EXEC : ",app['Exec'])
os.system(app['Exec']+'&')
http.server.SimpleHTTPRequestHandler.do_GET(self)
def do_POST(self):
logging.error(self.headers)
form = cgi.FieldStorage(
fp=self.rfile,
headers=self.headers,
environ={'REQUEST_METHOD':'POST',
'CONTENT_TYPE':self.headers['Content-Type'],
})
for item in form.list:
logging.error(item)
http.server.SimpleHTTPRequestHandler.do_GET(self)
Handler = ServerHandler
httpd = socketserver.TCPServer(("", PORT), Handler)
print("serving at port", PORT)
httpd.serve_forever()
init()
serve()