PDA

Visualizza la versione completa : Modifica scripit python


lion1810
29-05-2009, 10:21
Ragassuoli ho bisogno di voi :D

Dovrei/dovremo/dovete modificare questo programmino/scriptino in modo che vada a leggere le informazioni sia in

/usr/share/applications

ma anche in

/usr/share/applications/kde

anzi sarebbe meglio anche in tutte le sottodirecoty di applications

... č possibile?


#! /usr/bin/python
#-*-coding:utf-8-*-
#- btekbas@gmail.com (btekbas_at_gmail_dot_com) - GPL licence
#- Based on gnome2fluxmenu
#- converts the Gnome menu (/usr/share/applications/*.desktop) into a icewm menu
#- usage: python icemenuyap.py > icemenu.txt
#- or: python icemenuyap.py > ~/.icewm/menu (please backup 'menu' document before)
#- note: results may need some small adjustments, like apps turned on/off with Alacarte
import gconf,os,sys,random,mimetypes
gnmp_st="/usr/share/applications"
catacce_sl=[""]*512;catutil_sl=[""]*512;catgame_sl=[""]*512;catgrap_sl=[""]*512
catnetw_sl=[""]*512;catoffi_sl=[""]*512;catothe_sl=[""]*512;catdeve_sl=[""]*512
catauvd_sl=[""]*512;catsyst_sl=[""]*512;catsysp_sl=[""]*512;catsysa_sl=[""]*512
cntacce=0;cntutil=0;cntgame=0;cntgrap=0;cntnetw=0; cntoffi=0
cntothe=0;cntdeve=0;cntauvd=0;cntsyst=0;cntsysp=0; cntsysa=0
diritems_sl=os.listdir(gnmp_st)
for item in diritems_sl:
finp_st=os.path.join(gnmp_st,item)
if finp_st.endswith(".desktop"):
finp_fl=open(finp_st,"r")
cate_st="";name_st="";exec_st="";catswc=0
while True:
text_st=finp_fl.readline()
if len(text_st)==0:break
text_st=text_st.replace("\n","")
if text_st.startswith("Categories="):
cate_st=text_st
if cate_st.find("Accessibility")>0:catswc+= 1
if cate_st.find("Utility")>0: catswc+= 2
if cate_st.find("Game")>0: catswc+= 4
if cate_st.find("Graphics")>0: catswc+= 8
if cate_st.find("Network")>0: catswc+= 16
if cate_st.find("Office")>0: catswc+= 32
if cate_st.find("Development")>0: catswc+= 64
if cate_st.find("AudioVideo")>0: catswc+= 128
if cate_st.find("System")>0: catswc+= 256
if cate_st.find("Settings")>0: catswc+= 512
if cate_st.find("Core")>0: catswc+=1024
if text_st.startswith("Name="):
name_st=text_st[5:];name_st=name_st.replace(")","\\)")
if text_st.startswith("Icon="):
icon_st=text_st[5:]
if text_st.startswith("Exec="):
exec_st=text_st[5:]
icepr_st="prog "+"\""+name_st+"\""+" "+"\""+icon_st+"\""+" "+exec_st
if (catswc& 1)== 1:
catacce_sl[cntacce]=icepr_st;cntacce+=1
if (catswc& 2)== 2:
catutil_sl[cntutil]=icepr_st;cntutil+=1
if (catswc& 4)== 4:
catgame_sl[cntgame]=icepr_st;cntgame+=1
if (catswc& 8)== 8:
catgrap_sl[cntgrap]=icepr_st;cntgrap+=1
if (catswc& 16)== 16:
catnetw_sl[cntnetw]=icepr_st;cntnetw+=1
if (catswc& 32)== 32:
catoffi_sl[cntoffi]=icepr_st;cntoffi+=1
if (catswc&1023)== 0:
catothe_sl[cntothe]=icepr_st;cntothe+=1
if (catswc& 64)== 64:
catdeve_sl[cntdeve]=icepr_st;cntdeve+=1
if (catswc& 128)==128:
catauvd_sl[cntauvd]=icepr_st;cntauvd+=1
if (catswc& 768)==256:
catsyst_sl[cntsyst]=icepr_st;cntsyst+=1
if (catswc& 768)==512:
catsysp_sl[cntsysp]=icepr_st;cntsysp+=1
if (catswc& 768)==768:
catsysa_sl[cntsysa]=icepr_st;cntsysa+=1
finp_fl.close()
print" menu \"Accessories\" applications-accessories {"
for i in range(0,cntutil-1,1):print" "+catutil_sl[i]
for i in range(0,cntacce-1,1):print" "+catacce_sl[i]
print" }";print" menu \"Games\" applications-games {"
for i in range(0,cntgame-1,1):print" "+catgame_sl[i]
print" }";print" menu \"Graphics\" applications-graphics {"
for i in range(0,cntgrap-1,1):print" "+catgrap_sl[i]
print" }";print" menu \"Internet\" applications-internet {"
for i in range(0,cntnetw-1,1):print" "+catnetw_sl[i]
print" }";print" menu \"Office\" applications-office {"
for i in range(0,cntoffi-1,1):print" "+catoffi_sl[i]
print" }";print" menu \"Other\" applications-other {"
for i in range(0,cntothe-1,1):print" "+catothe_sl[i]
print" }";print" menu \"Programming\" applications-development {"
for i in range(0,cntdeve-1,1):print" "+catdeve_sl[i]
print" }";print" menu \"Sound & Video\" applications-multimedia {"
for i in range(0,cntauvd-1,1):print" "+catauvd_sl[i]
print" }";print" menu \"System Tools\" applications-system {"
for i in range(0,cntsyst-1,1):print" "+catsyst_sl[i]
print" }"
print" menu \"System\" applications-system {"
print" menu \"Preferences\" preferences-system {"
for i in range(0,cntsysp-1,1):print" "+catsysp_sl[i]
print" }";print" menu \"Administration\" preferences-other {"
for i in range(0,cntsysa-1,1):print" "+catsysa_sl[i]
print"}"

lion1810
29-05-2009, 14:31
:oVVoVe:

pera non mi abbandonerai mica qui!!!

lion1810
04-06-2009, 21:46
:cry: :cry:

eddai ragasi una manina?

psykopear
04-06-2009, 21:52
Originariamente inviato da lion1810
#! /usr/bin/python
#-*-coding:utf-8-*-
#- btekbas@gmail.com (btekbas_at_gmail_dot_com) - GPL licence
#- Based on gnome2fluxmenu
#- converts the Gnome menu (/usr/share/applications/*.desktop) into a icewm menu
#- usage: python icemenuyap.py > icemenu.txt
#- or: python icemenuyap.py > ~/.icewm/menu (please backup 'menu' document before)
#- note: results may need some small adjustments, like apps turned on/off with Alacarte
import gconf,os,sys,random,mimetypes
gnmp_st="/usr/share/applications"
catacce_sl=[""]*512;catutil_sl=[""]*512;catgame_sl=[""]*512;catgrap_sl=[""]*512
catnetw_sl=[""]*512;catoffi_sl=[""]*512;catothe_sl=[""]*512;catdeve_sl=[""]*512
catauvd_sl=[""]*512;catsyst_sl=[""]*512;catsysp_sl=[""]*512;catsysa_sl=[""]*512
cntacce=0;cntutil=0;cntgame=0;cntgrap=0;cntnetw=0; cntoffi=0
cntothe=0;cntdeve=0;cntauvd=0;cntsyst=0;cntsysp=0; cntsysa=0
diritems_sl=os.listdir(gnmp_st)
for item in diritems_sl:
finp_st=os.path.join(gnmp_st,item)
if finp_st.endswith(".desktop"):
finp_fl=open(finp_st,"r")
cate_st="";name_st="";exec_st="";catswc=0
while True:
text_st=finp_fl.readline()
if len(text_st)==0:break
text_st=text_st.replace("\n","")
if text_st.startswith("Categories="):
cate_st=text_st
if cate_st.find("Accessibility")>0:catswc+= 1
if cate_st.find("Utility")>0: catswc+= 2
if cate_st.find("Game")>0: catswc+= 4
if cate_st.find("Graphics")>0: catswc+= 8
if cate_st.find("Network")>0: catswc+= 16
if cate_st.find("Office")>0: catswc+= 32
if cate_st.find("Development")>0: catswc+= 64
if cate_st.find("AudioVideo")>0: catswc+= 128
if cate_st.find("System")>0: catswc+= 256
if cate_st.find("Settings")>0: catswc+= 512
if cate_st.find("Core")>0: catswc+=1024
if text_st.startswith("Name="):
name_st=text_st[5:];name_st=name_st.replace(")","\\)")
if text_st.startswith("Icon="):
icon_st=text_st[5:]
if text_st.startswith("Exec="):
exec_st=text_st[5:]
icepr_st="prog "+"\""+name_st+"\""+" "+"\""+icon_st+"\""+" "+exec_st
if (catswc& 1)== 1:
catacce_sl[cntacce]=icepr_st;cntacce+=1
if (catswc& 2)== 2:
catutil_sl[cntutil]=icepr_st;cntutil+=1
if (catswc& 4)== 4:
catgame_sl[cntgame]=icepr_st;cntgame+=1
if (catswc& 8)== 8:
catgrap_sl[cntgrap]=icepr_st;cntgrap+=1
if (catswc& 16)== 16:
catnetw_sl[cntnetw]=icepr_st;cntnetw+=1
if (catswc& 32)== 32:
catoffi_sl[cntoffi]=icepr_st;cntoffi+=1
if (catswc&1023)== 0:
catothe_sl[cntothe]=icepr_st;cntothe+=1
if (catswc& 64)== 64:
catdeve_sl[cntdeve]=icepr_st;cntdeve+=1
if (catswc& 128)==128:
catauvd_sl[cntauvd]=icepr_st;cntauvd+=1
if (catswc& 768)==256:
catsyst_sl[cntsyst]=icepr_st;cntsyst+=1
if (catswc& 768)==512:
catsysp_sl[cntsysp]=icepr_st;cntsysp+=1
if (catswc& 768)==768:
catsysa_sl[cntsysa]=icepr_st;cntsysa+=1
finp_fl.close()
print" menu \"Accessories\" applications-accessories {"
for i in range(0,cntutil-1,1):print" "+catutil_sl[i]
for i in range(0,cntacce-1,1):print" "+catacce_sl[i]
print" }";print" menu \"Games\" applications-games {"
for i in range(0,cntgame-1,1):print" "+catgame_sl[i]
print" }";print" menu \"Graphics\" applications-graphics {"
for i in range(0,cntgrap-1,1):print" "+catgrap_sl[i]
print" }";print" menu \"Internet\" applications-internet {"
for i in range(0,cntnetw-1,1):print" "+catnetw_sl[i]
print" }";print" menu \"Office\" applications-office {"
for i in range(0,cntoffi-1,1):print" "+catoffi_sl[i]
print" }";print" menu \"Other\" applications-other {"
for i in range(0,cntothe-1,1):print" "+catothe_sl[i]
print" }";print" menu \"Programming\" applications-development {"
for i in range(0,cntdeve-1,1):print" "+catdeve_sl[i]
print" }";print" menu \"Sound & Video\" applications-multimedia {"
for i in range(0,cntauvd-1,1):print" "+catauvd_sl[i]
print" }";print" menu \"System Tools\" applications-system {"
for i in range(0,cntsyst-1,1):print" "+catsyst_sl[i]
print" }"
print" menu \"System\" applications-system {"
print" menu \"Preferences\" preferences-system {"
for i in range(0,cntsysp-1,1):print" "+catsysp_sl[i]
print" }";print" menu \"Administration\" preferences-other {"
for i in range(0,cntsysa-1,1):print" "+catsysa_sl[i]
print"}"

Mmm, non che l'abbia visto tutto, ma hai provato a modificare sta riga

gnmp_st="/usr/share/applications"

in

gnmp_st="/usr/share/applications/*/*/*"

?

lion1810
05-06-2009, 15:10
non funziona ne cosė


gnmp_st="/usr/share/applications/*/*/*"

ne


gnmp_st="/usr/share/applications/*"


:master:

:cry:

vortex87
05-06-2009, 17:23
#! /usr/bin/python
#-*-coding:utf-8-*-
#- btekbas@gmail.com (btekbas_at_gmail_dot_com) - GPL licence
#- Based on gnome2fluxmenu
#- converts the Gnome menu (/usr/share/applications/*.desktop) into a icewm menu
#- usage: python icemenuyap.py > icemenu.txt
#- or: python icemenuyap.py > ~/.icewm/menu (please backup 'menu' document before)
#- note: results may need some small adjustments, like apps turned on/off with Alacarte
import gconf,os,sys,random,mimetypes
gnmp_st="/usr/share/applications"
catacce_sl=[""]*512;catutil_sl=[""]*512;catgame_sl=[""]*512;catgrap_sl=[""]*512
catnetw_sl=[""]*512;catoffi_sl=[""]*512;catothe_sl=[""]*512;catdeve_sl=[""]*512
catauvd_sl=[""]*512;catsyst_sl=[""]*512;catsysp_sl=[""]*512;catsysa_sl=[""]*512
cntacce=0;cntutil=0;cntgame=0;cntgrap=0;cntnetw=0; cntoffi=0
cntothe=0;cntdeve=0;cntauvd=0;cntsyst=0;cntsysp=0; cntsysa=0
diritems_sl=os.listdir(gnmp_st)
for item in diritems_sl:
finp_st=os.path.join(gnmp_st,item)
if finp_st.endswith(".desktop"):
finp_fl=open(finp_st,"r")
cate_st="";name_st="";exec_st="";catswc=0
while True:
text_st=finp_fl.readline()
if len(text_st)==0:break
text_st=text_st.replace("\n","")
if text_st.startswith("Categories="):
cate_st=text_st
if cate_st.find("Accessibility")>0:catswc+= 1
if cate_st.find("Utility")>0: catswc+= 2
if cate_st.find("Game")>0: catswc+= 4
if cate_st.find("Graphics")>0: catswc+= 8
if cate_st.find("Network")>0: catswc+= 16
if cate_st.find("Office")>0: catswc+= 32
if cate_st.find("Development")>0: catswc+= 64
if cate_st.find("AudioVideo")>0: catswc+= 128
if cate_st.find("System")>0: catswc+= 256
if cate_st.find("Settings")>0: catswc+= 512
if cate_st.find("Core")>0: catswc+=1024
if text_st.startswith("Name="):
name_st=text_st[5:];name_st=name_st.replace(")","\\)")
if text_st.startswith("Icon="):
icon_st=text_st[5:]
if text_st.startswith("Exec="):
exec_st=text_st[5:]
icepr_st="prog "+"\""+name_st+"\""+" "+"\""+icon_st+"\""+" "+exec_st
if (catswc& 1)== 1:
catacce_sl[cntacce]=icepr_st;cntacce+=1
if (catswc& 2)== 2:
catutil_sl[cntutil]=icepr_st;cntutil+=1
if (catswc& 4)== 4:
catgame_sl[cntgame]=icepr_st;cntgame+=1
if (catswc& 8)== 8:
catgrap_sl[cntgrap]=icepr_st;cntgrap+=1
if (catswc& 16)== 16:
catnetw_sl[cntnetw]=icepr_st;cntnetw+=1
if (catswc& 32)== 32:
catoffi_sl[cntoffi]=icepr_st;cntoffi+=1
if (catswc&1023)== 0:
catothe_sl[cntothe]=icepr_st;cntothe+=1
if (catswc& 64)== 64:
catdeve_sl[cntdeve]=icepr_st;cntdeve+=1
if (catswc& 128)==128:
catauvd_sl[cntauvd]=icepr_st;cntauvd+=1
if (catswc& 768)==256:
catsyst_sl[cntsyst]=icepr_st;cntsyst+=1
if (catswc& 768)==512:
catsysp_sl[cntsysp]=icepr_st;cntsysp+=1
if (catswc& 768)==768:
catsysa_sl[cntsysa]=icepr_st;cntsysa+=1
finp_fl.close()
print" menu \"Accessories\" applications-accessories {"
for i in range(0,cntutil-1,1):print" "+catutil_sl[i]
for i in range(0,cntacce-1,1):print" "+catacce_sl[i]
print" }";print" menu \"Games\" applications-games {"
for i in range(0,cntgame-1,1):print" "+catgame_sl[i]
print" }";print" menu \"Graphics\" applications-graphics {"
for i in range(0,cntgrap-1,1):print" "+catgrap_sl[i]
print" }";print" menu \"Internet\" applications-internet {"
for i in range(0,cntnetw-1,1):print" "+catnetw_sl[i]
print" }";print" menu \"Office\" applications-office {"
for i in range(0,cntoffi-1,1):print" "+catoffi_sl[i]
print" }";print" menu \"Other\" applications-other {"
for i in range(0,cntothe-1,1):print" "+catothe_sl[i]
print" }";print" menu \"Programming\" applications-development {"
for i in range(0,cntdeve-1,1):print" "+catdeve_sl[i]
print" }";print" menu \"Sound & Video\" applications-multimedia {"
for i in range(0,cntauvd-1,1):print" "+catauvd_sl[i]
print" }";print" menu \"System Tools\" applications-system {"
for i in range(0,cntsyst-1,1):print" "+catsyst_sl[i]
print" }"
print" menu \"System\" applications-system {"
print" menu \"Preferences\" preferences-system {"
for i in range(0,cntsysp-1,1):print" "+catsysp_sl[i]
print" }";print" menu \"Administration\" preferences-other {"
for i in range(0,cntsysa-1,1):print" "+catsysa_sl[i]
print"}"

Intanto mettiamolo dentro a un
che se spariscono i tab va tutto a bottane :D

Il punto interessato č questo:
[code]
diritems_sl=os.listdir(gnmp_st)
for item in diritems_sl:
finp_st=os.path.join(gnmp_st,item)
if finp_st.endswith(".desktop"):


os.listdir() ritorna soltanto i file e le directory presenti direttamente nel path specificato, non entra nei sottonodi.
Ci sono due strade:
1) usare glob
2) inserire un ciclo for prima di quello che controlla se item č una cartella e nel caso toglie la voce dalla lista e vi aggiunge i relativi file contenuti

lion1810
08-06-2009, 09:05
:D io lo sapevo che vortex con il pitone č un grande

:malol: :malol:

torniamo a noi:

mi sembra che seguire il punto

1) usare glob

sia pių semplice.


d'altro canto si potrebbe utilizzare il punto 2 magari per ricercare le vecchie applicazioni in gtk che hanno un'altro percorso .... ma tanto sono poche e ci interessano marginalmente
:D :D

Vortex con glob come bisogna modficare la stringa?

lion1810
08-06-2009, 11:36
cosė:

diritems_sl=glob(gnmp_st)
for item in diritems_sl:
finp_st=os.path.join(gnmp_st,item)
if finp_st.endswith(".desktop"):

lion1810
08-06-2009, 11:39
domanda utilizzando glob:

se all'interno della directory

/usr/share/applications

ci fossero dei link ad altre directoy c'č il rischio che vada alla ricerca anche in quelle dir. creando delle latenze mostruose?

vortex87
08-06-2009, 17:17
Originariamente inviato da lion1810
domanda utilizzando glob:

se all'interno della directory

/usr/share/applications

ci fossero dei link ad altre directoy c'č il rischio che vada alla ricerca anche in quelle dir. creando delle latenze mostruose?

Boh :stordita:


Io farei cosė, per leggere sia in applications che in applications/kde:


gnmp_st = "/usr/share/applications"
diritems_sl = glob.glob(os.path.join(gnmp_st, "*.desktop"))
diritems_sl += glob.glob(os.path.join(gnmp_st, "kde", "*.desktop"))

e poi dopo non serve neanche pių l'if, visto che glob trova solo i file .desktop.

Loading