From: <sv...@ww...> - 2004-12-18 10:31:14
|
Author: mkrose Date: 2004-12-18 02:31:07 -0800 (Sat, 18 Dec 2004) New Revision: 1399 Modified: trunk/CSP/CSPSim/Bin/CSPSim.py trunk/CSP/CSPSim/CHANGES.current trunk/CSP/CSPSim/Tools/HID/cspinput Log: Minor changes to the cspinput command line. Now takes -Ipath option to set the base include path, and -o to specify the output file (instead of using the 2nd non-flag argument). Added a check in CSPSim.py for aircraft.hid and gamescreen.hid in ../Data/Input. If not found, CSPSim.py calls cspinput to try to regenerate them from the examples in ../Tools/HID/Examples. Browse at: https://www.zerobar.net/viewcvs/viewcvs.cgi?view=rev&rev=1399 Modified: trunk/CSP/CSPSim/Bin/CSPSim.py =================================================================== --- trunk/CSP/CSPSim/Bin/CSPSim.py 2004-12-18 10:19:27 UTC (rev 1398) +++ trunk/CSP/CSPSim/Bin/CSPSim.py 2004-12-18 10:31:07 UTC (rev 1399) @@ -50,6 +50,21 @@ os.environ["SDL_JOYSTICK_DEVICE"]="/dev/input/js0" +def ensureDefaultHID(hid_file): + """ + Verify that the specified hid input definition exists. If not, generate it from + from the example input maps in ../Tools/HID/Examples + """ + if not os.path.exists('../Data/Input'): return + output = '../Data/Input/%s.hid' % hid_file + if not os.path.exists(output): + os.system('../Tools/HID/cspinput -I../Tools/HID -o%s ../Tools/HID/Examples/%s.map' % (output, hid_file)) + if os.path.exists(output): + print 'Default input map created for %s.hid; see Tools/HID/README for details.' % hid_file + else: + print 'Unable to create default input map for %s.hid; see Tools/HID/README for details.' % hid_file + + def printUsage(): print "Combat Simulator Project - CSPSim" print @@ -64,8 +79,6 @@ print " --logpri=5" print " --pause pause on startup for attaching a debug session" print " --dump-data show the contents of sim.dar" - print " --client-node run networking test client node" - print " --echo-server-node run networking test echo server node" print " --help help message" @@ -117,6 +130,9 @@ print "Static data archive '%s' not found." % dar compileData([]) + ensureDefaultHID('aircraft') + ensureDefaultHID('gamescreen') + import Shell app = cCSP.CSPSim() @@ -188,23 +204,6 @@ print -def runClientNode(args): - print "CSPSim.py - runClientNode - Starting Test Client Node..." - print "CSPSim.py - runClientNode - calling loadCSP" - loadCSP() - print "CSPSim.py - runClientNode - calling CSP.ClientNode" - app = cCSP.ClientNode() - print "CSPSim.py - runClientNode - calling app.run" - app.run() - - -def runEchoServerNode(args): - print "Starting Test Echo Server Node..." - loadCSP() - app = cCSP.EchoServerNode() - app.run() - - def loadSimData(): """Load the SimData module""" global SimData @@ -310,10 +309,6 @@ elif arg.startswith('--dump-data='): action = dumpData other_args.append(arg) - elif arg == '--client-node': - action = runClientNode - elif arg == '--echo-server-node': - action = runEchoServerNode elif arg == '--pause': pause = 1 elif arg in ("--help", "-h", "-help"): @@ -336,7 +331,6 @@ if action is None: action = runCSPSim - loadSimData() if log_priority_arg is not None: Modified: trunk/CSP/CSPSim/CHANGES.current =================================================================== --- trunk/CSP/CSPSim/CHANGES.current 2004-12-18 10:19:27 UTC (rev 1398) +++ trunk/CSP/CSPSim/CHANGES.current 2004-12-18 10:31:07 UTC (rev 1399) @@ -4,6 +4,13 @@ * Add a message box to the onscreen display that displays/scrolls several lines of text, and fades out when unchanged for several seconds. + * Minor changes to the cspinput command line. Now takes -Ipath option to + set the base include path, and -o to specify the output file (instead + of using the 2nd non-flag argument). Added a check in CSPSim.py for + aircraft.hid and gamescreen.hid in ../Data/Input. If not found, + CSPSim.py calls cspinput to try to regenerate them from the examples + in ../Tools/HID/Examples. + 2004-12-17: delta * Updated FlightModel and m2k xml related files. Modified: trunk/CSP/CSPSim/Tools/HID/cspinput =================================================================== --- trunk/CSP/CSPSim/Tools/HID/cspinput 2004-12-18 10:19:27 UTC (rev 1398) +++ trunk/CSP/CSPSim/Tools/HID/cspinput 2004-12-18 10:31:07 UTC (rev 1399) @@ -1,29 +1,35 @@ #!/usr/bin/env python # Combat Simulator Project - MAP2HID input script compiler -# Copyright (C) 2002 The Combat Simulator Project +# Copyright (C) 2002, 2004 The Combat Simulator Project # http://csp.sourceforge.net -# +# # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. -# +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -## @author Mark Rose <tm...@st...> +## @author Mark Rose <mk...@us...> +""" +Combat Simulator Project Input Map Compiler +usage: %(prog)s [flags] infile +""" + import sys import os.path +from CSP.base import app KMODS = { @@ -168,7 +174,7 @@ class VirtualDeviceDefinition: - def __init__(self): + def __init__(self, include_path='.'): self.included = {} self.values = {} self.scripts = {} @@ -177,13 +183,16 @@ self.definitions = {} self.devices = {} self.filestack = [] - self.pathstack = ['.'] + self.pathstack = [include_path] self.line = 0 self.file = "" self.bind = {} def read(self, fn): - f = open(fn, 'rt') + if fn == '-': + f = sys.stdin + else: + f = open(fn, 'rt') if f is not None: self.file = fn self.parse(f) @@ -475,40 +484,17 @@ self.mode = 0 self.mapping = {} -def usage(program): - print "CSP map script to human interface device definition converter" - print "Copyright (C) 2003 Mark Rose <tm...@st...>" - print "usage: %s [--help] infile [outfile]" % program +def main(args): + mapfile = None -def main(argv): - file = None - outfile = None + if len(args) != 1: + app.usage() + return 1 - for arg in argv[1:]: - if arg.startswith('--'): - if arg == '--help': - usage(argv[0]) - print " infile : input map file" - print " outfile : output file ('-' for stdout)" - sys.exit(1) - continue - if file is None: - file = arg - elif outfile is None: - outfile = arg - else: - usage(argv[0]) - sys.exit(1) + mapfile = args[0] - if file is None: - usage(argv[0]) - sys.exit(1) - - if outfile is None and file.endswith('.map'): - outfile = file[:-4] + '.hid' - - outf = None + outfile = app.options.output_file if outfile == '-': outf = sys.stdout else: @@ -516,15 +502,17 @@ outf = open(outfile, "wt") except: print "Unable to write to '%s'." % outfile - sys.exit(1) - - v = VirtualDeviceDefinition() + return 1 + v = VirtualDeviceDefinition(include_path=app.options.include_path) + try: - v.read(file) + v.read(mapfile) + except KeyboardInterrupt: + return 0 except Error, e: print e.msg - sys.exit(1) + return 1 bindings = v.bind.keys() bindings.sort() @@ -533,7 +521,10 @@ for m in v.maps: m.write(outf) + return 0 -if __name__ == "__main__": - main(sys.argv) +app.addOption('-I', '--include_path', metavar='PATH', default='.', help='default include path') +app.addOption('-o', '--output_file', metavar='FILE', default='-', help='output file (default stdout)') +app.start() + |