You are not logged in.
Hi All,
i'm learning python and have writen a script to add keybindings (it might be usefull)
anyway looking for sugestions on my coding in python.
Thanks
Matthew
#!/usr/bin/python -O
### Keybinding tool for openbox
### args keybind startupnotify command name
import sys
def checksysargs ():
test=""
if len(sys.argv) < 5:
print "wrong number of arguments"
print sys.argv[0] +" Keybind, startup notification (true/false), Command, keybind name"
sys.exit(1)
return
### check args
checksysargs()
### copy sys args to XML template
newaction = sys.argv[1]
startup = sys.argv[2]
command = sys.argv[3]
name = sys.argv[4]
### Setup lists etc
newkeybinds=[]
filename="test.xml"
newlist = []
newlist1 = []
newlist2 = []
each=""
a=0 ## our reusable counter :)
positionstore = 0 ### store position of <keyboard>
endposition=0 ## hopefully store end of the keybind section
` temp="" ## used for temp stuff
##open file
FILE = open(filename,"r")
## read contents
contents=FILE.read()
FILE.close()
##convert contents to a list
newlist = contents.split('\n')
for spaces in newlist:
newlist1.append(spaces)
while not a ==(len(newlist1)):
each=newlist1[a]
if each==" <keyboard>":
positionstore=a
while not newlist1[a]==" </keyboard>": ##not working
newlist2.append(newlist1[a])
endposition=a
a=a+1
a=a +1
### newlist2 is the keyboard section
###create data structure for XML output
XML1=" <keybind key=" +'"'+ newaction +'"' + ">"
XML2=' <action name="Execute">'
XML3=' <startupnotify>'
XML4=' <enabled>' + startup + '</enabled>'
XML5=' <name>' + name + '</name>'
XML6=' </startupnotify>'
XML7=' <command>' + command + '</command>'
XML8=' </action'
XML9=' </keybind>'
#add that to the list
newlist2.append(XML1)
newlist2.append(XML2)
newlist2.append(XML3)
newlist2.append(XML4)
newlist2.append(XML5)
newlist2.append(XML6)
newlist2.append(XML7)
newlist2.append(XML8)
newlist2.append(XML9)
outputlist=[]
#print newlist1[positionstore]
print positionstore
print len(newlist2)
a=0 ## reset counter
while not a == positionstore:
outputlist.append(newlist1[a])
a=a+1
a=0
while not a==len(newlist2):
outputlist.append(newlist2[a])
a=a+1
print newlist1[endposition+1]
a=endposition+1
while not a == len(newlist1):
outputlist.append(newlist1[a])
a=a+1
FILE2 = open("test.xml","w")
a=0 ## reset counter
while not a == (len(outputlist)):
temp=outputlist[a]
FILE2.write (temp+'\n')
a=a+1
FILE2.close
"is adult entertainment killing our children or is killing our children entertaining adults?" Marilyn Manson
Offline