generatePythonCode 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #!/usr/local/bin/python
  2. import getopt
  3. import sys
  4. import os
  5. import FFIConstants
  6. # Define a help string for the user
  7. helpString ="""
  8. generatePythonCode [opts] -i libtool libcode1 libcode2 ...
  9. Generates Python code for the C++ libraries listed.
  10. Example:
  11. Linux:
  12. ppython -d generatePythonCode -v -d $DIRECT/lib/py -e $DIRECT/src/extensions -i libdtoolconfig libpandaexpress libpanda libdirect libtoontown
  13. Windows debug:
  14. ppython -d generatePythonCode -v -d `cygpath -w $DIRECT/lib/py` -e `cygpath -w $DIRECT/src/extensions` -i libdtoolconfig libpandaexpress libpanda libdirect libtoontown
  15. Windows release:
  16. ppython generatePythonCode -v -d `cygpath -w $DIRECT/lib/py` -e `cygpath -w $DIRECT/src/extensions` -i libdtoolconfig libpandaexpress libpanda libdirect libtoontown
  17. Windows publish (no assertions, no comments, no docstrings):
  18. ppython -OO generatePythonCode -O -v -d `cygpath -w $DIRECT/lib/py` -e `cygpath -w $DIRECT/src/extensions` -i libdtoolconfig libpandaexpress libpanda libdirect libtoontown
  19. Options:
  20. -h print this message
  21. -v verbose
  22. -d dir directory to write output code
  23. -e dir directory to pull extension code from
  24. -i lib interrogate library
  25. -O no C++ comments or assertion statements
  26. """
  27. # Initialize variables
  28. outputDir = ''
  29. extensionsDir = ''
  30. interrogateLib = ''
  31. codeLibs = []
  32. # Extract the args the user passed in
  33. try:
  34. opts, pargs = getopt.getopt(sys.argv[1:], 'hvOd:e:i:')
  35. except Exception, e:
  36. # User passed in a bad option, print the error and the help, then exit
  37. print e
  38. print helpString
  39. sys.exit()
  40. if len(opts)==0:
  41. print helpString
  42. sys.exit()
  43. # Store the option values into our variables
  44. for opt in opts:
  45. flag, value = opt
  46. if (flag == '-h'):
  47. print helpString
  48. sys.exit()
  49. elif (flag == '-v'):
  50. FFIConstants.notify.setVerbose(1)
  51. elif (flag == '-d'):
  52. outputDir = value
  53. elif (flag == '-e'):
  54. extensionsDir = value
  55. elif (flag == '-i'):
  56. interrogateLib = value
  57. elif (flag == '-O'):
  58. FFIConstants.wantComments = 0
  59. FFIConstants.wantTypeChecking = 0
  60. else:
  61. FFIConstants.notify.error('illegal option: ' + flag)
  62. # Store the program arguments into the codeLibs
  63. codeLibs = pargs
  64. # Now do some error checking and verbose output
  65. if (not interrogateLib):
  66. FFIConstants.notify.error('You must specify an interrogate library (-i lib)')
  67. else:
  68. FFIConstants.notify.info('Setting interrogate library to: ' + interrogateLib)
  69. FFIConstants.InterrogateModuleName = interrogateLib
  70. if (not outputDir):
  71. FFIConstants.notify.info('Setting output directory to current directory')
  72. outputDir = '.'
  73. elif (not os.path.exists(outputDir)):
  74. FFIConstants.notify.info('Directory does not exist, creating: ' + outputDir)
  75. os.mkdir(outputDir)
  76. FFIConstants.notify.info('Setting output directory to: ' + outputDir)
  77. else:
  78. FFIConstants.notify.info('Setting output directory to: ' + outputDir)
  79. if (not extensionsDir):
  80. FFIConstants.notify.info('Setting extensions directory to current directory')
  81. extensionsDir = '.'
  82. elif (not os.path.exists(extensionsDir)):
  83. FFIConstants.notify.error('Directory does not exists: ' + extensionsDir)
  84. else:
  85. FFIConstants.notify.info('Setting extensions directory to: ' + extensionsDir)
  86. if (not codeLibs):
  87. FFIConstants.notify.error('You must specify one or more libraries to generate code from')
  88. else:
  89. FFIConstants.notify.info('Generating code for: ' + `codeLibs`)
  90. FFIConstants.CodeModuleNameList = codeLibs
  91. # Ok, now we can start generating code
  92. import FFIInterrogateDatabase
  93. db = FFIInterrogateDatabase.FFIInterrogateDatabase()
  94. db.generateCode(outputDir, extensionsDir)