PageRenderTime 25ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/dll.py

https://bitbucket.org/pygame/pygame/
Python | 72 lines | 39 code | 14 blank | 19 comment | 5 complexity | 3536e594d9cd70e6f25c674af34f1b99 MD5 | raw file
Possible License(s): LGPL-2.1
  1. # dll.py module
  2. """DLL specifics
  3. Configured for the Pygame 1.9.0 dependencies as built by msys_build_deps.py.
  4. """
  5. # Some definitions:
  6. # Library name (name): An internal identifier, a string, for a library.
  7. # e.g. FONT
  8. # Library file root (root): The library root used in linker -l options.
  9. # e.g. SDL_mixer
  10. import re
  11. # Table of dependencies.
  12. # name, root, File regex, Dependency list of names
  13. libraries = [
  14. ('MIXER', 'SDL_mixer', r'SDL_mixer\.dll$',
  15. ['SDL', 'VORBISFILE']),
  16. ('VORBISFILE', 'vorbisfile', r'libvorbisfile-3\.dll$',
  17. ['VORBIS']),
  18. ('VORBIS', 'vorbis', r'libvorbis-0\.dll$', ['OGG']),
  19. ('OGG', 'ogg', r'libogg-0\.dll$', []),
  20. ('IMAGE', 'SDL_image', r'SDL_image\.dll$',
  21. ['SDL', 'JPEG', 'PNG', 'TIFF']),
  22. ('TIFF', 'tiff', r'libtiff-3\.dll$', ['JPEG', 'Z']),
  23. ('JPEG', 'jpeg', r'libjpeg-8\.dll$', []),
  24. ('PNG', 'png', r'libpng14\.dll$', ['Z']),
  25. ('FONT', 'SDL_ttf', r'SDL_ttf\.dll$', ['SDL']),
  26. ('FREETYPE', 'freetype', r'libfreetype-6\.dll$', ['Z']),
  27. ('Z', 'z', r'zlib1\.dll$', []),
  28. ('SDL', 'SDL', r'SDL\.dll$', []),
  29. ('PORTMIDI', 'portmidi', r'portmidi\.dll', []),
  30. ('PORTTIME', 'portmidi', r'portmidi\.dll', []),
  31. ]
  32. # regexs: Maps name to DLL file name regex.
  33. # lib_dependencies: Maps name to list of dependencies.
  34. # file_root_names: Maps name to root.
  35. regexs = {}
  36. lib_dependencies = {}
  37. file_root_names = {}
  38. for name, root, ignore1, ignore2 in libraries:
  39. file_root_names[name] = root
  40. for name, root, regex, deps in libraries:
  41. regexs[name] = regex
  42. lib_dependencies[root] = [file_root_names[d] for d in deps]
  43. del name, root, regex, deps, ignore1, ignore2
  44. def tester(name):
  45. """For a library name return a function which tests dll file names"""
  46. def test(file_name):
  47. """Return true if file name f is a valid DLL name"""
  48. return match(file_name) is not None
  49. match = re.compile(regexs[name], re.I).match
  50. test.library_name = name # Available for debugging.
  51. return test
  52. def name_to_root(name):
  53. """Return the library file root for the library name"""
  54. return file_root_names[name]
  55. def libraries(name):
  56. """Return the library file roots this library links too"""
  57. return lib_dependencies[name_to_root(name)]