From: <sv...@ww...> - 2004-07-10 05:17:23
|
Author: mkrose Date: 2004-07-09 22:17:16 -0700 (Fri, 09 Jul 2004) New Revision: 1153 Modified: trunk/CSP/CSPSim/Bin/CSPSim.py trunk/CSP/CSPSim/CHANGES.current Log: Added instructions for using the --pause option for debugging under GNU/Linux. Changed the --log to --logcat, and added the ability to specify category exclusions. For example, --logcat=PHYSICS:NETWORK:TERRAIN will only log messages in those three categories, while --logcat=ALL:-NETWORK will log all categories _except_ NETWORK. Replaced the --slog parameter with --logpri, which overrides the logging priority for both simdata and cspsim. Accepts either numeric values (e.g. 5) or symbolic names (e.g. "INFO"). Browse at: https://www.zerobar.net/viewcvs/viewcvs.cgi?view=rev&rev=1153 Modified: trunk/CSP/CSPSim/Bin/CSPSim.py =================================================================== --- trunk/CSP/CSPSim/Bin/CSPSim.py 2004-07-09 06:28:26 UTC (rev 1152) +++ trunk/CSP/CSPSim/Bin/CSPSim.py 2004-07-10 05:17:16 UTC (rev 1153) @@ -1,7 +1,7 @@ #!/usr/bin/python -O # Combat Simulator Project - CSPSim -# 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 @@ -26,12 +26,14 @@ #import Shell #from SimData.Compile import Compiler, CompilerUsageError + def initDynamicLoading(): """Enable lazy loading of shared library modules if available""" if os.name == 'posix': import dl sys.setdlopenflags(dl.RTLD_GLOBAL|dl.RTLD_LAZY) + def setDefaultJoystick(): """Provide a default value for the SDL joystick environment variable""" if not os.environ.has_key("SDL_JOYSTICK_DEVICE"): @@ -39,48 +41,81 @@ if os.path.exists("/dev/input/js0"): os.environ["SDL_JOYSTICK_DEVICE"]="/dev/input/js0" + def printUsage(): print "Combat Simulator Project - CSPSim" print print " Primary options:" - print " --compile-data run the data compiler" - print " --config=path path to config (.ini) file" - print " --log=classes set the logging classes" - print " --slog=level set the simdata logging level" - 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" + print " --compile-data run the data compiler" + print " --config=path path to config (.ini) file" + print " --logcat=categories set the logging categories (colon-delimited)" + print " examples: --logcat=APP:TERRAIN:PHYSICS" + print " --logcat=ALL:-NETWORK (all but network)" + print " --logpri=priority set the logging priority threshold (overrides .ini)" + print " examples: --logpri=INFO" + 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" def setLogCategory(): - if len(log_classes) == 0: return + if len(log_categories) == 0: return flags = 0 - for class_name in log_classes: + for class_name in log_categories: + invert = 0 + if class_name.startswith('-'): + class_name = class_name[1:] + invert = 1 try: class_flag = getattr(CSP, "CSP_"+class_name); - flags = flags | class_flag + if invert: + flags = flags & ~class_flag + else: + flags = flags | class_flag except: print "Unrecognized log class:", class_name CSP.csplog().setLogCategory(flags) +def setLogPriority(): + if log_priority is None: return + CSP.csplog().setLogPriority(log_priority) + SimData.log().setLogPriority(log_priority) + + +def parseLogPriority(priority): + try: + priority = int(priority) + except ValueError: + priority = getattr(SimData, "LOG_" + priority.upper(), None) + return priority + + def runCSPSim(args): if len(args): - print "Unrecognized option '%s'" % args[0] - print + print "Unrecognized option '%s'\n" % args[0] printUsage() print sys.exit(1) + cachepath = CSP.getCachePath() dar = os.path.join(cachepath, "sim.dar") if not os.path.exists(dar): print print "Static data archive '%s' not found." % dar compileData([]) + import Shell app = CSP.CSPSim() + + # logging will have already been configured from the ini file at this point, + # so we can safely override the settings. setLogCategory() + setLogPriority() + app.init() try: @@ -105,10 +140,8 @@ dar = arg[12:] archive = SimData.DataArchive(dar, 1) archive.dump() - archive.getObject("sim:terrain.balkan") - archive.getObject("sim:theater.balkan") - + def compileData(args): datapath = CSP.getDataPath() cachepath = CSP.getCachePath() @@ -144,7 +177,8 @@ print 'Aborting' sys.exit(1) print - + + def runClientNode(args): print "CSPSim.py - runClientNode - Starting Test Client Node..." print "CSPSim.py - runClientNode - calling loadCSP" @@ -154,12 +188,14 @@ print "CSPSim.py - runClientNode - calling app.run" app.run() + def runEchoServerNode(args): print "Starting Test Echo Server Node..." loadCSP() app = CSP.EchoServerNode() app.run() + def loadSimData(): """Load the SimData module""" global SimData @@ -238,7 +274,8 @@ def main(argv): - global log_classes + global log_categories + global log_priority initDynamicLoading() setDefaultJoystick() @@ -248,10 +285,11 @@ # process command line options program = argv[0] all_args = argv[1:] - log_classes = [] + log_categories = [] + log_priority = None + log_priority_arg = None other_args = [] pause = 0 - simdata_loglevel = "ALERT" config = findConfig() @@ -279,39 +317,53 @@ other_args.append(arg) elif arg.startswith("--config="): config = arg[9:] - elif arg.startswith("--log="): - log_classes.extend(arg[6:].split(':')) - elif arg.startswith("--slog="): - simdata_loglevel = arg[7:] + elif arg.startswith("--logcat="): + log_categories.extend(arg[9:].split(':')) + elif arg.startswith("--logpri="): + log_priority_arg = arg[9:] else: other_args.append(arg) if action is None: action = runCSPSim + loadSimData() + + if log_priority_arg is not None: + log_priority = parseLogPriority(log_priority_arg) + if log_priority is None: + print "Invalid logging priority, using .ini setting." + + # capture Object class registration and other errors when CSP loads SimData.log().setLogCategory(SimData.LOG_ALL) SimData.log().setLogPriority(SimData.LOG_DEBUG) loadCSP() - try: - simdata_loglevel = eval("SimData.LOG_%s" % simdata_loglevel.upper()) - except: - print "Invalid SimData logging level, defaulting to 'ALERT'" - simdata_loglevel = SimData.LOG_ALERT - - SimData.log().setLogPriority(simdata_loglevel) - print "Loading configuration from '%s'." % config if not CSP.openConfig(config): print "Unable to open primary configuration file (%s)" % config sys.exit(0) if pause: - print "Hit <ctrl-break> to temporarily exit and set breakpoints." - print "When you are done, continue execution and hit <enter>." - sys.stdin.readline() + print + print "CSPSim has loaded all extension modules, and is now paused to give you" + print "an opportunity to attach a debugging session. Under GNU/Linux run the" + print "following command from a separate shell to attach a debug session:" + print + print " gdb python %d" % os.getpid() + print + print "This will run gdb and attach to the CSPSim process. Once gdb finishes" + print "loading symbols for all the modules, you can set breakpoints as needed" + print "and then enter 'c' to continue." + print + print "Finally, return to this window and press <enter> to resume CSPSim." + print + try: + sys.stdin.readline() + except KeyboardInterrupt: + sys.exit(1) action(other_args) Modified: trunk/CSP/CSPSim/CHANGES.current =================================================================== --- trunk/CSP/CSPSim/CHANGES.current 2004-07-09 06:28:26 UTC (rev 1152) +++ trunk/CSP/CSPSim/CHANGES.current 2004-07-10 05:17:16 UTC (rev 1153) @@ -1,6 +1,22 @@ Version 0.4.0 (in progress) =========================== +2004-07-08: onsight + * Slight tweak of the logging macros. See the SimData changelog for + details. + + * Added instructions for using the --pause option for debugging under + GNU/Linux. + + * Changed the --log to --logcat, and added the ability to specify + category exclusions. For example, --logcat=PHYSICS:NETWORK:TERRAIN + will only log messages in those three categories, while + --logcat=ALL:-NETWORK will log all categories _except_ NETWORK. + + * Replaced the --slog parameter with --logpri, which overrides the + logging priority for both simdata and cspsim. Accepts either + numeric values (e.g. 5) or symbolic names (e.g. "INFO"). + 2004-07-07: onsight * More network code reformatting and redirecting messages from stdout to the csp log. Changed logging class to NETWORK. |