Skip to content

Instantly share code, notes, and snippets.

@rafael-neri
Created May 28, 2014 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafael-neri/23a20880058441e60e74 to your computer and use it in GitHub Desktop.
Save rafael-neri/23a20880058441e60e74 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# -*- coding: utf-8 -*-
'''
Example: ./kinfoservices --imagesize=32 --fileout=file.txt
'''
import os, sys
from xdg.DesktopEntry import *
from xdg.IconTheme import *
import commands
# pega a lista de arquivos e o tema de icones
files = commands.getoutput("grep -l kcmshell4 /usr/share/kde4/services/*.desktop").splitlines()
current_theme = commands.getoutput("kreadconfig --group 'Icons' --key 'Theme'")
# tamanho da imagem e arquivo de saida
imagesize = 32
fileout = None
for arg in sys.argv:
if "--imagesize=" in arg:
imagesize = arg.split("=")[1]
elif "--fileout=" in arg:
fileout = arg.split("=")[1]
# saida
output = ""
# obtendo informações dos arquivos individualmente
for file in files:
entry = DesktopEntry()
# analisa o arquivo
try:
entry.parse(file)
except ParsingError, e:
continue
# pega os dados do arquivo
name = entry.getName()
comment = entry.getComment()
icon = str(getIconPath(entry.getIcon(), theme=current_theme, size=int(imagesize)))
filename = os.path.splitext(os.path.basename(file))[0]
output += '%s|%s|%s|%s\n'%(name,comment,icon,filename)
if fileout == None:
# mostra na tela
print str(output).encode('utf-8')
else:
# manda a saida para um arquivo
myFile = open(fileout, 'w')
myFile.write(output.encode('utf-8'))
myFile.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment