/PC/VS7.1/field3.py

http://unladen-swallow.googlecode.com/ · Python · 35 lines · 17 code · 5 blank · 13 comment · 0 complexity · 940248ccf48d3932e536c36c5bafd93a MD5 · raw file

  1. # An absurd workaround for the lack of arithmetic in MS's resource compiler.
  2. # After building Python, run this, then paste the output into the appropriate
  3. # part of PC\python_nt.rc.
  4. # Example output:
  5. #
  6. # * For 2.3a0,
  7. # * PY_MICRO_VERSION = 0
  8. # * PY_RELEASE_LEVEL = 'alpha' = 0xA
  9. # * PY_RELEASE_SERIAL = 1
  10. # *
  11. # * and 0*1000 + 10*10 + 1 = 101.
  12. # */
  13. # #define FIELD3 101
  14. import sys
  15. major, minor, micro, level, serial = sys.version_info
  16. levelnum = {'alpha': 0xA,
  17. 'beta': 0xB,
  18. 'candidate': 0xC,
  19. 'final': 0xF,
  20. }[level]
  21. string = sys.version.split()[0] # like '2.3a0'
  22. print " * For %s," % string
  23. print " * PY_MICRO_VERSION = %d" % micro
  24. print " * PY_RELEASE_LEVEL = %r = %s" % (level, hex(levelnum))
  25. print " * PY_RELEASE_SERIAL = %d" % serial
  26. print " *"
  27. field3 = micro * 1000 + levelnum * 10 + serial
  28. print " * and %d*1000 + %d*10 + %d = %d" % (micro, levelnum, serial, field3)
  29. print " */"
  30. print "#define FIELD3", field3