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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
#! /usr/bin/python
import sys
data = []
def out(str):
sys.stderr.write(str)
sys.stderr.flush()
def read_bool():
while True:
inp = sys.stdin.readline(1).strip()
if inp == 'y' or inp == '': return True
if inp == 'n': return False
def getkeyval(line):
key = line[:line.find(':')].strip()
value = line[line.find(':') + 1:].strip()
if not (key and value):
key = value = None
return key, value
def simple_replace(data):
for i in range(len(data)):
l = data[i]
key, value = getkeyval(l)
if key and value:
pairs = {}
pairs['window.focus.font'] = 'window.label.focus.font'
pairs['window.unfocus.font'] = 'window.label.unfocus.font'
pairs['window.justify'] = 'window.label.justify'
pairs['menu.frame.disableColor'] = 'menu.disabled.textColor'
pairs['style.'] = 'info.'
pairs['menu.frame'] = 'menu.items'
pairs['menu.hilite'] = 'menu.selected'
pairs['.picColor'] = '.imageColor'
for k in pairs.keys():
if key.find(k) != -1:
newl = l.replace(k, pairs[k])
out('Updating "' + key +
'" to "' + key.replace(k, pairs[k]) + '"\n')
data[i] = newl
break
def remove(data):
i = 0
n = len(data)
while i < n:
l = data[i]
key, value = getkeyval(l)
if key and value:
invalid = []
invalid.append('toolbar')
invalid.append('rootCommand')
invalid.append('menu.frame.justify')
for inv in invalid:
if key.find(inv) != -1:
out(key + ' is no longer supported.\nRemove (Y/n)? ')
if read_bool():
out('Removing "' + key + '"\n')
data.pop(i)
i -= 1
n -= 1
break
i += 1
def pressed(data):
i = 0
n = len(data)
while i < n:
l = data[i]
key, value = getkeyval(l)
if key and value:
if key == 'window.button.pressed':
out('The window.button.pressed option has been replaced by ' +
'window.button.pressed.focus and ' +
'window.button.pressed.unfocus.\nUpdate (Y/n)? ')
if read_bool():
out('Removing "window.button.pressed"\n')
data.pop(i)
out('Adding "window.button.pressed.unfocus"\n')
data.insert(i, l.replace('window.button.pressed',
'window.button.pressed.unfocus'))
out('Adding "window.button.pressed.focus"\n')
data.insert(i, l.replace('window.button.pressed',
'window.button.pressed.focus'))
i += 1
n += 1
break
i += 1
def fonts(data):
for l in data:
key, value = getkeyval(l)
if key and value:
if key == 'window.font':
out('You appear to specify fonts using the old X fonts ' +
'syntax.\nShall I remove all fonts from the theme (Y/n)? ')
if not read_bool():
return
i = 0
n = len(data)
while i < n:
l = data[i]
key, value = getkeyval(l)
if key and value:
if key.find('font') != -1:
out('Removing "' + key + '"\n')
data.pop(i)
i -= 1
n -= 1
i += 1
def usage():
print 'Usage: ' + sys.argv[0] + ' /path/to/themerc > newthemerc'
print
sys.exit()
try:
file = open(sys.argv[1])
except IndexError:
usage()
except IOError:
print 'Unable to open file "' + sys.argv[1] + '"'
print
usage()
data = file.readlines()
for i in range(len(data)):
data[i] = data[i].strip()
#simple_replace(data)
#remove(data)
#pressed(data)
fonts(data)
for l in data:
print l
|