summaryrefslogtreecommitdiff
path: root/test/tokentest/get-tokens.py
blob: 42a8844e6742714c48025a293b1983392fa9ddd6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/python
# Copyright (C) 2008 Thomas Thurman
# 
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.


import os
import xml.sax

standard = ['x', 'y', 'width', 'height']

expressions = {
  'line': ['x1', 'x2', 'y1', 'y2'],
  'rectangle': standard,
  'arc': standard,
  'clip': standard,
  'gradient': standard,
  'image': standard,
  'gtk_arrow': standard,
  'gtk_box': standard,
  'gtk_vline': standard,
  'icon': standard,
  'title': standard,
  'include': standard,
  'tile': ['x', 'y', 'width', 'height',
           'tile_xoffset', 'tile_yoffset',
           'tile_width', 'tile_height'],
}

all_themes = '../../../all-themes/'

result = {}

class themeparser:
  def __init__(self, name):
    self.filename = name

  def processingInstruction(self):
    pass

  def characters(self, what):
    pass

  def setDocumentLocator(self, where):
    pass

  def startDocument(self):
    pass

  def startElement(self, name, attrs):
    if expressions.has_key(name):
      for attr in expressions[name]:
        if attrs.has_key(attr):
          expression = attrs[attr]
          if not result.has_key(expression): result[expression] = {}
          result[expression][self.filename] = 1

  def endElement(self, name):
    pass # print "end element"

  def endDocument(self):
    pass

def maybe_parse(themename, filename):
  if os.access(all_themes+filename, os.F_OK):
    parser = themeparser(themename)
    xml.sax.parse(all_themes+filename, parser)
  
for theme in os.listdir(all_themes):
  maybe_parse(theme, theme+'/metacity-1/metacity-theme-1.xml')
  maybe_parse(theme, theme+'/metacity-theme-1.xml')

print '[tokentest0]'

for expr in sorted(result.keys()):
  print "# %s" % (', '.join(sorted(result[expr])))
  print "%s=REQ" % (expr)
  print