Added Michael Rans <rans@email.com> runxboxdrv script
This commit is contained in:
parent
908cd03a7f
commit
7f166ac7b8
2 changed files with 163 additions and 0 deletions
runxboxdrv
66
runxboxdrv/example.cfg
Normal file
66
runxboxdrv/example.cfg
Normal file
|
@ -0,0 +1,66 @@
|
|||
[options]
|
||||
silent=true
|
||||
trigger-as-button=true
|
||||
dpad-as-button=true
|
||||
led=0
|
||||
|
||||
[axis-sensitivity]
|
||||
X1=-0.5
|
||||
X2=-0.5
|
||||
Y2=-0.5
|
||||
|
||||
[axismap]
|
||||
Y2=-Y2
|
||||
|
||||
[ui-axismap]
|
||||
Y1=XK_1:XK_2
|
||||
|
||||
[ui-buttonmap]
|
||||
# speed
|
||||
du=XK_Up
|
||||
dd=XK_Down
|
||||
# previous, next target
|
||||
dl=XK_Left
|
||||
dr=XK_Right
|
||||
# fire lasers
|
||||
lt=XK_w
|
||||
# identify object
|
||||
rt=XK_r
|
||||
# next missile
|
||||
lb=XK_y
|
||||
# inject speed
|
||||
rb=XK_i
|
||||
# launch missile
|
||||
X=XK_Return
|
||||
# target missile
|
||||
A=XK_t
|
||||
# ecm
|
||||
B=XK_e
|
||||
# untarget missile
|
||||
Y=XK_u
|
||||
# scanner zoom
|
||||
start=XK_z
|
||||
# jumpdrive
|
||||
guide=XK_j
|
||||
# pause
|
||||
back=XK_p
|
||||
# buy equipment/ships
|
||||
lb+du=XK_3
|
||||
# market prices
|
||||
lb+dd=XK_8
|
||||
# local/galactic chart
|
||||
lb+dl=XK_6
|
||||
# planet info
|
||||
lb+dr=XK_7
|
||||
# current status/manifest
|
||||
lb+back=XK_5
|
||||
# hyperspace
|
||||
lb+guide=XK_h
|
||||
# slow dock with target
|
||||
lb+start=XK_c
|
||||
# fast dock
|
||||
lb+X=XK_d
|
||||
# advanced compass
|
||||
lb+A=XK_backslash
|
||||
# comms log
|
||||
lb+B=XK_m
|
97
runxboxdrv/runxboxdrv
Executable file
97
runxboxdrv/runxboxdrv
Executable file
|
@ -0,0 +1,97 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import os, sys
|
||||
import ConfigParser
|
||||
from subprocess import check_call, Popen, PIPE
|
||||
from signal import SIGINT
|
||||
|
||||
class RunXBoxDrv(object):
|
||||
def __init__(self, configfile, appandparams=[]):
|
||||
self.configfile = configfile
|
||||
self.appandparams = appandparams
|
||||
|
||||
@staticmethod
|
||||
def checkminusvalue(key, value):
|
||||
if value.startswith("-"):
|
||||
valstr = value[1:]
|
||||
try:
|
||||
number = float(valstr)
|
||||
except ValueError:
|
||||
return ("-%s" % key, valstr)
|
||||
return (key, value)
|
||||
|
||||
@staticmethod
|
||||
def getNext(myProc):
|
||||
out = ""
|
||||
while out == "":
|
||||
out = myProc.read()
|
||||
buf = out
|
||||
while out != "":
|
||||
out = myProc.read()
|
||||
buf = "%s%s" % (buf, out)
|
||||
return buf
|
||||
|
||||
def process(self):
|
||||
parser = ConfigParser.ConfigParser()
|
||||
parser.optionxform = str
|
||||
|
||||
if not parser.read(self.configfile):
|
||||
raise Exception("XBoxDrv game config not found: " + self.configfile)
|
||||
|
||||
cfg = dict([(s, dict(parser.items(s))) for s in parser.sections()])
|
||||
commandlist = ["xboxdrv"]
|
||||
for sectionname in cfg:
|
||||
section = cfg[sectionname]
|
||||
if sectionname == "options":
|
||||
for inkey in section:
|
||||
key, value = self.checkminusvalue(inkey, section[inkey])
|
||||
if value == "true":
|
||||
commandlist.append("--%s" % key)
|
||||
else:
|
||||
commandlist.append("--%s=%s" % (key, value))
|
||||
continue
|
||||
paramline = ""
|
||||
for inkey in section:
|
||||
key, value = self.checkminusvalue(inkey, section[inkey])
|
||||
paramline = "%s%s=%s," % (paramline, key, value)
|
||||
if paramline.endswith(","):
|
||||
commandlist.append("--%s" % sectionname)
|
||||
commandlist.append(paramline[:-1])
|
||||
print commandlist
|
||||
myProc = Process(commandlist)
|
||||
out = ""
|
||||
while out.lower().find("quit") == -1:
|
||||
out = self.getNext(myProc)
|
||||
print out
|
||||
if len(self.appandparams) == 0:
|
||||
print("WARNING: No path to application specified!")
|
||||
else:
|
||||
print(self.appandparams)
|
||||
check_call(self.appandparams)
|
||||
print "Sending SIGINT"
|
||||
myProc.kill(SIGINT)
|
||||
try:
|
||||
with_timeout(1, myProc.wait)
|
||||
sys.exit(0)
|
||||
except Timeout:
|
||||
pass
|
||||
print "Sending SIGINT again"
|
||||
myProc.kill(SIGINT)
|
||||
try:
|
||||
with_timeout(1, myProc.wait)
|
||||
sys.exit(0)
|
||||
except Timeout:
|
||||
pass
|
||||
print "Killing"
|
||||
myProc.terminate()
|
||||
|
||||
def main():
|
||||
# parse command line options
|
||||
if len(sys.argv) < 2:
|
||||
print "Usage: runxboxdrv configfile [path to app] [app parameters]"
|
||||
sys.exit(-1)
|
||||
runxboxdrv = RunXBoxDrv(sys.argv[1], sys.argv[2:])
|
||||
runxboxdrv.process()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Add table
Reference in a new issue