/Mac/Modules/folder/foldersupport.py

http://unladen-swallow.googlecode.com/ · Python · 56 lines · 26 code · 14 blank · 16 comment · 1 complexity · 0ce66194cd0ce5a35d1891170b910406 MD5 · raw file

  1. # This script generates a Python interface for an Apple Macintosh Manager.
  2. # It uses the "bgen" package to generate C code.
  3. # The function specifications are generated by scanning the mamager's header file,
  4. # using the "scantools" package (customized for this particular manager).
  5. import string
  6. # Declarations that change for each manager
  7. MACHEADERFILE = 'Folders.h' # The Apple header file
  8. MODNAME = '_Folder' # The name of the module
  9. # The following is *usually* unchanged but may still require tuning
  10. MODPREFIX = 'Folder' # The prefix for module-wide routines
  11. INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
  12. OUTPUTFILE = MODNAME + "module.c" # The file generated by this program
  13. from macsupport import *
  14. # Create the type objects
  15. ConstStrFileNameParam = ConstStr255Param
  16. StrFileName = Str255
  17. FolderClass = OSTypeType("FolderClass")
  18. # FolderDesc
  19. FolderDescFlags = Type("FolderDescFlags", "l")
  20. FolderLocation = OSTypeType("FolderLocation")
  21. # FolderRouting
  22. FolderType = OSTypeType("FolderType")
  23. RoutingFlags = Type("RoutingFlags", "l")
  24. includestuff = includestuff + """
  25. #include <Carbon/Carbon.h>
  26. """
  27. execfile(string.lower(MODPREFIX) + 'typetest.py')
  28. # From here on it's basically all boiler plate...
  29. # Create the generator groups and link them
  30. module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
  31. # Create the generator classes used to populate the lists
  32. Function = OSErrFunctionGenerator
  33. # Create and populate the lists
  34. functions = []
  35. execfile(INPUTFILE)
  36. # add the populated lists to the generator groups
  37. # (in a different wordl the scan program would generate this)
  38. for f in functions: module.add(f)
  39. # generate output (open the output file as late as possible)
  40. SetOutputFileName(OUTPUTFILE)
  41. module.generate()