fix python run mode

This commit is contained in:
David Rose 2009-08-22 22:35:42 +00:00
parent cf6a220cb7
commit 5b744c5ab8

View File

@ -9,11 +9,10 @@ previously been generated via packp3d.py.
Usage: Usage:
runp3d.py app.p3d [keyword=value [keyword=value ...] ] runp3d.py app.p3d [args]
The command-line keywords mimic the additional parameters that may The command-line arguments following the application name are passed
appear in HTML syntax when the p3d file appears on a web page. These into the application unchanged.
are passed as given to the app, which may decide what to do with them.
See pack3d.py for a script that generates these p3d files. See pack3d.py for a script that generates these p3d files.
@ -478,9 +477,16 @@ class AppRunner(DirectObject):
self.sendRequest('drop_p3dobj', objectId) self.sendRequest('drop_p3dobj', objectId)
def parseSysArgs(self): def parseSysArgs(self):
""" Converts sys.argv into (p3dFilename, tokens). """ """ Handles sys.argv, if there are any local arguments, and
returns a new argv suitable for passing into the
application. """
import getopt import getopt
opts, args = getopt.getopt(sys.argv[1:], 'h')
# We prefix a "+" sign, following the GNU convention, to tell
# getopt not to parse options following the first non-option
# parameter.
opts, args = getopt.getopt(sys.argv[1:], '+h')
for option, value in opts: for option, value in opts:
if option == '-h': if option == '-h':
@ -490,30 +496,20 @@ class AppRunner(DirectObject):
if not args or not args[0]: if not args or not args[0]:
raise ArgumentError, "No Panda app specified. Use:\nrunp3d.py app.p3d" raise ArgumentError, "No Panda app specified. Use:\nrunp3d.py app.p3d"
tokens = [] arg0 = args[0]
for token in args[1:]: p3dFilename = Filename.fromOsSpecific(arg0)
if '=' in token: if p3dFilename.exists():
keyword, value = token.split('=', 1) p3dFilename.makeAbsolute()
else: arg0 = p3dFilename.toOsSpecific()
keyword = token
value = ''
tokens.append((keyword.lower(), value))
p3dFilename = Filename.fromOsSpecific(sys.argv[1]) return [arg0] + args[1:]
osFilename = p3dFilename.toOsSpecific()
if not p3dFilename.exists():
# If the filename doesn't exist, it must be a URL.
osFilename = ''
if 'src' not in dict(tokens):
tokens.append(('src', sys.argv[1]))
return (osFilename, tokens)
if __name__ == '__main__': if __name__ == '__main__':
runner = AppRunner() runner = AppRunner()
runner.gotWindow = True runner.gotWindow = True
try: try:
runner.setP3DFilename(*runner.parseSysArgs()) argv = runner.parseSysArgs()
runner.setP3DFilename(argv[0], argv = argv)
except ArgumentError, e: except ArgumentError, e:
print e.args[0] print e.args[0]
sys.exit(1) sys.exit(1)