3 # This script will check the documentation consistency against the code. It
4 # doesn't check the actual accuracy of the documentation, it just ensures that
5 # everything is documented and that nothing which doesn't exist in Conky
6 # appears in the documentation.
8 # This script also updates the vim and nano syntax files so it doesn't have to
11 # Requires the ElementTree Python module for the sorting stuff, see:
12 # http://effbot.org/zone/element-index.htm
14 # You should also install htmltidy, but it's not necessary.
22 file_names["text_objects"] = "src/text_object.h"
23 file_names["conky"] = "src/conky.c"
24 file_names["vim_syntax"] = "extras/vim/syntax/conkyrc.vim"
25 file_names["nano_syntax"] = "extras/nano/conky.nanorc"
26 file_names["variables"] = "doc/variables.xml"
27 file_names["config_settings"] = "doc/config_settings.xml"
29 for fn in file_names.values():
30 if not os.path.exists(fn) or not os.path.isfile(fn):
31 print "'%s' doesn't exist, or isn't a file" % (fn)
35 # Do all the objects first
40 file = open(file_names["text_objects"], "r")
41 exp = re.compile("\s*OBJ_(\w*).*")
43 line = file.readline()
49 if not re.match("color\d", obj) and obj != "text":
50 # ignore colourN stuff
51 objects.append(res.group(1))
55 exp = re.compile("\s*<command><option>(\w*)</option></command>.*")
56 print "checking docs -> objs consistency (in %s)" % (file_names["text_objects"])
57 file = open(file_names["variables"], "r")
59 line = file.readline()
64 doc_objects.append(res.group(1))
65 if doc_objects[len(doc_objects) - 1] != "templateN" and doc_objects[len(doc_objects) - 1] not in objects:
66 print " '%s' is documented, but doesn't seem to be an object" % (doc_objects[len(doc_objects) - 1])
70 print "checking objs -> docs consistency (in %s)" % (file_names["variables"])
72 if obj not in doc_objects:
73 print " '%s' seems to be undocumented" % (obj)
77 # Now we'll do config settings
82 file = open(file_names["conky"], "r")
83 exp1 = re.compile('\s*CONF\("(\w*)".*')
84 exp2 = re.compile('\s*CONF2\("(\w*)".*')
85 exp3 = re.compile('\s*CONF3\("(\w*)".*')
87 line = file.readline()
90 res = exp1.match(line)
92 res = exp2.match(line)
94 res = exp3.match(line)
97 if re.match("color\d", conf):
99 if configs.count(conf) == 0:
104 exp = re.compile("\s*<term><command><option>(\w*)</option></command>.*")
105 print "checking docs -> configs consistency (in %s)" % (file_names["conky"])
106 file = open(file_names["config_settings"], "r")
108 line = file.readline()
111 res = exp.match(line)
113 doc_configs.append(res.group(1))
114 if doc_configs[len(doc_configs) - 1] != "TEXT" and doc_configs[len(doc_configs) - 1] != "templateN" and doc_configs[len(doc_configs) - 1] not in configs:
115 print " '%s' is documented, but doesn't seem to be a config setting" % (doc_configs[len(doc_configs) - 1])
119 print "checking configs -> docs consistency (in %s)" % (file_names["config_settings"])
121 if obj != "text" and obj != "template" and obj not in doc_configs:
122 print " '%s' seems to be undocumented" % (obj)
127 # Cheat and add the colour/template stuff.
129 for i in range(0, 10):
130 objects.append("color" + str(i))
131 configs.append("color" + str(i))
132 objects.append("template" + str(i))
133 configs.append("template" + str(i))
135 # Finally, sort everything.
140 # Update nano syntax stuff
143 print "updating nano syntax...",
145 file = open(file_names["nano_syntax"], "rw+")
148 line = file.readline()
153 # find the line we want to update
155 if re.match("color green ", line):
156 idx = lines.index(line)
157 lines.pop(idx) # remove old line
158 line = 'color green "\<('
160 line += "%s|" % (obj)
161 line = line[:len(line) - 1]
163 lines.insert(idx, line)
164 if re.match("color brightblue ", line):
165 idx = lines.index(line)
166 lines.pop(idx) # remove old line
167 line = 'color brightblue "\<('
169 line += "%s|" % (obj)
170 line = line[:len(line) - 1]
172 lines.insert(idx, line)
173 break # want to ignore everything after this line
176 file.writelines(lines)
181 # Update vim syntax stuff
184 print "updating vim syntax...",
186 file = open(file_names["vim_syntax"], "rw+")
189 line = file.readline()
194 # find the line we want to update
196 if re.match("syn keyword ConkyrcSetting ", line):
197 idx = lines.index(line)
198 lines.pop(idx) # remove old line
199 line = 'syn keyword ConkyrcSetting '
201 line += "%s " % (obj)
202 line = line[:len(line) - 1]
204 lines.insert(idx, line)
205 if re.match("syn keyword ConkyrcVarName contained nextgroup=ConkyrcNumber,ConkyrcColour skipwhite ", line):
206 idx = lines.index(line)
207 lines.pop(idx) # remove old line
208 line = 'syn keyword ConkyrcVarName contained nextgroup=ConkyrcNumber,ConkyrcColour skipwhite '
210 line += "%s " % (obj)
211 line = line[:len(line) - 1]
213 lines.insert(idx, line)
214 break # want to ignore everything after this line
217 file.writelines(lines)
221 print 'sorting/tidying docs...'
223 # sort the docs by variable/config setting
225 import xml.etree.ElementTree as ET
227 vars_xml = ET.parse(file_names['variables'])
228 config_xml = ET.parse(file_names['config_settings'])
230 getkey = lambda x: x.findtext('term/command/option')
232 vars = vars_xml.getroot()
233 vars[:] = sorted(vars, key=getkey)
235 configs = config_xml.getroot()
236 configs[:] = sorted(configs, key=getkey)
238 vars_xml.write(file_names['variables'])
239 config_xml.write(file_names['config_settings'])
242 command = ['tidy', '-qim', '-xml', '-utf8', '--indent-spaces', '4']
243 os.system('%s %s 2>/dev/null' % (string.join(command), file))
245 tidy(file_names['variables'])
246 tidy(file_names['config_settings'])