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
17 file_names["text_objects"] = "src/text_object.h"
18 file_names["conky"] = "src/conky.c"
19 file_names["vim_syntax"] = "extras/vim/syntax/conkyrc.vim"
20 file_names["nano_syntax"] = "extras/nano/conky.nanorc"
21 file_names["variables"] = "doc/variables.xml"
22 file_names["config_settings"] = "doc/config_settings.xml"
24 for fn in file_names.values():
25 if not os.path.exists(fn) or not os.path.isfile(fn):
26 print "'%s' doesn't exist, or isn't a file" % (fn)
30 # Do all the objects first
35 file = open(file_names["text_objects"], "r")
36 exp = re.compile("\s*OBJ_(\w*).*")
38 line = file.readline()
44 if not re.match("color\d", obj) and obj != "text":
45 # ignore colourN stuff
46 objects.append(res.group(1))
50 exp = re.compile("\s*<command><option>(\w*)</option></command>.*")
51 print "checking docs -> objs consistency (in %s)" % (file_names["text_objects"])
52 file = open(file_names["variables"], "r")
54 line = file.readline()
59 doc_objects.append(res.group(1))
60 if doc_objects[len(doc_objects) - 1] != "templateN" and doc_objects[len(doc_objects) - 1] not in objects:
61 print " '%s' is documented, but doesn't seem to be an object" % (doc_objects[len(doc_objects) - 1])
65 print "checking objs -> docs consistency (in %s)" % (file_names["variables"])
67 if obj not in doc_objects:
68 print " '%s' seems to be undocumented" % (obj)
72 # Now we'll do config settings
77 file = open(file_names["conky"], "r")
78 exp1 = re.compile('\s*CONF\("(\w*)".*')
79 exp2 = re.compile('\s*CONF2\("(\w*)".*')
80 exp3 = re.compile('\s*CONF3\("(\w*)".*')
82 line = file.readline()
85 res = exp1.match(line)
87 res = exp2.match(line)
89 res = exp3.match(line)
92 if re.match("color\d", conf):
94 if configs.count(conf) == 0:
99 exp = re.compile("\s*<term><command><option>(\w*)</option></command>.*")
100 print "checking docs -> configs consistency (in %s)" % (file_names["conky"])
101 file = open(file_names["config_settings"], "r")
103 line = file.readline()
106 res = exp.match(line)
108 doc_configs.append(res.group(1))
109 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:
110 print " '%s' is documented, but doesn't seem to be a config setting" % (doc_configs[len(doc_configs) - 1])
114 print "checking configs -> docs consistency (in %s)" % (file_names["config_settings"])
116 if obj != "text" and obj != "template" and obj not in doc_configs:
117 print " '%s' seems to be undocumented" % (obj)
122 # Cheat and add the colour/template stuff.
124 for i in range(0, 10):
125 objects.append("color" + str(i))
126 configs.append("color" + str(i))
127 objects.append("template" + str(i))
128 configs.append("template" + str(i))
130 # Finally, sort everything.
135 # Update nano syntax stuff
138 print "updating nano syntax...",
140 file = open(file_names["nano_syntax"], "rw+")
143 line = file.readline()
148 # find the line we want to update
150 if re.match("color green ", line):
151 idx = lines.index(line)
152 lines.pop(idx) # remove old line
153 line = 'color green "\<('
155 line += "%s|" % (obj)
156 line = line[:len(line) - 1]
158 lines.insert(idx, line)
159 if re.match("color brightblue ", line):
160 idx = lines.index(line)
161 lines.pop(idx) # remove old line
162 line = 'color brightblue "\<('
164 line += "%s|" % (obj)
165 line = line[:len(line) - 1]
167 lines.insert(idx, line)
168 break # want to ignore everything after this line
171 file.writelines(lines)
176 # Update vim syntax stuff
179 print "updating vim syntax...",
181 file = open(file_names["vim_syntax"], "rw+")
184 line = file.readline()
189 # find the line we want to update
191 if re.match("syn keyword ConkyrcSetting ", line):
192 idx = lines.index(line)
193 lines.pop(idx) # remove old line
194 line = 'syn keyword ConkyrcSetting '
196 line += "%s " % (obj)
197 line = line[:len(line) - 1]
199 lines.insert(idx, line)
200 if re.match("syn keyword ConkyrcVarName contained nextgroup=ConkyrcNumber,ConkyrcColour skipwhite ", line):
201 idx = lines.index(line)
202 lines.pop(idx) # remove old line
203 line = 'syn keyword ConkyrcVarName contained nextgroup=ConkyrcNumber,ConkyrcColour skipwhite '
205 line += "%s " % (obj)
206 line = line[:len(line) - 1]
208 lines.insert(idx, line)
209 break # want to ignore everything after this line
212 file.writelines(lines)