home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 July / maximum-cd-2010-07.iso / DiscContents / wesnoth-1.8-win32.exe / data / tools / extractbindings < prev    next >
Encoding:
Text File  |  2008-10-06  |  1.3 KB  |  49 lines

  1. #!/usr/bin/env python
  2. #
  3. # Extract and format a list of bindings from a theme file.
  4. # Presently this generates a table suitable for wiki inclusion.
  5.  
  6. import sys
  7.  
  8. def report(binding, description):
  9.     "Reporter suitable for a wiki inclusion"
  10.     tabcolumn=-32
  11.     print " %*s%s" % (tabcolumn, binding, description)
  12.  
  13. def strip(st):
  14.     if st.startswith('"'):
  15.         st = st[1:-1]
  16.     return st
  17.  
  18.  
  19. in_keydef = False
  20. entry = {}
  21. for line in sys.stdin:
  22.     line=line.strip()
  23.     if line.startswith("#!"):
  24.         (key, explanation) = line.split("=")
  25.         report(key[3:], explanation)
  26.     elif line.startswith("#"):
  27.         continue
  28.     elif line == "[hotkey]":
  29.         in_keydef = True
  30.     elif in_keydef:
  31.         if line == "[/hotkey]":
  32.             binding = ''
  33.             # Presently we ignore the Mac command key
  34.             for mod in ("ctrl", "alt", "shift"):
  35.                 if mod in entry and entry[mod] == 'yes':
  36.                     binding += mod + "-"
  37.             binding += strip(entry['key'])
  38.             report(binding, strip(entry['description']))
  39.             in_keydef = False
  40.             entry = {}
  41.         else:
  42.             try:
  43.                 (key, value) = line.split("=")
  44.             except ValueError:
  45.                 print >>sys.stderr, "Malformed line: %s" % `line`
  46.                 sys.exit(1)
  47.             entry[key] = value
  48.     
  49.