generatePythonCode 3.2 KB

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