user@linuxtrack:~ $ python -c 'print("Soyez les bienvenus !")'

Vous n'êtes pas identifié(e).

#1 27-01-2013 20:30:41

Casoum
Membre

Générer la liste des applications pour awesome WM

Générer la liste des applications pour awesome WM

Petit script Python pour crée une liste des applications (a partir des fichiers dans /usr/share/applications/) par catégories pour awesome WM.
Testé sur une Archlinux avec awesome 3.5

[== Indéfini ==]
#!/usr/bin/env python2

from os import listdir
from os.path import isfile, join

path = "/usr/share/applications/"
files = [ f for f in listdir(path) if isfile(join(path,f)) ]

Network = []
Multimedia = []
Graphics = []
Other = []

for filename in files:
	f = open(path + filename, 'r')
	name = ""
	command = ""
	categories = ""
	for line in f:
		if line[:5] == "Exec=" and command == "":
			command = line[5:-1]
			#print("cmd: "+command)
		elif line[:5] == "Name=" and name == "":
			name = line[5:-1]
			#print("name: "+name)
		elif line[:11] == "Categories=" and categories == "":
			categories = line[11:-1].split(';')
			
	if name != "" and command != "" and categories != "":
		name = name.replace("\"","\\\"")
		command = command.replace("\"","\\\"")
		if categories.count("Network") > 0:
			Network.append("{\""+name +"\", \""+ command+"\"}")
		elif  categories.count("AudioVideo") > 0:
			Multimedia.append("{\""+name +"\", \""+ command+"\"}")
		elif  categories.count("Graphics") > 0:
			Graphics.append("{\""+name +"\", \""+ command+"\"}")
		else:
			Other.append("{\""+name +"\", \""+ command+"\"}")
print("networkappmenu = {")
for i,app in enumerate(Network):
	if i < len(Network)-1:
		print("    "+ app +",")
	else:
		print("    "+ app)
		
print("}")
print("multimediaappmenu = {")
for i,app in enumerate(Multimedia):
	if i < len(Multimedia)-1:
		print("    "+ app +",")
	else:
		print("    "+ app)
print("}")
print("graphappmenu = {")
for i,app in enumerate(Graphics):
	if i < len(Graphics)-1:
		print("    "+ app +",")
	else:
		print("    "+ app)
print("}")
print("otherappmenu = {")
for i,app in enumerate(Other):
	if i < len(Other)-1:
		print("    "+ app +",")
	else:
		print("    "+ app)
print("}")
print("mymainmenu = awful.menu({ items = { { \"awesome\", myawesomemenu, beautiful.awesome_icon },")
print("                                    { \"network\", networkappmenu},")
print("                                    { \"graphics\", graphappmenu},")
print("                                    { \"multimedia\", multimediaappmenu},")
print("                                    { \"other\", otherappmenu},")
print("                                    { \"open terminal\", terminal },")
print("                                    { \"reboot\", \"gksudo shutdown -r now\" },")
print("                                    { \"shutdown\", \"gksudo shutdown -Ph now\" }")
print("                                  }")
print("                        })")

L'exécution affichera le code lua à rajouter a votre rc.lua

Le code est facilement adaptable pour d'autre WM.

Hors ligne

Pied de page des forums