fix to detect n900 battery; add support to built in battery variables to work with...
[monky] / check_docs.py
index e780640..330f600 100755 (executable)
@@ -17,6 +17,8 @@
 import os.path
 import re
 import sys
+import mmap
+from datetime import *
 
 file_names = dict()
 file_names["text_objects"]    = "src/text_object.h"
@@ -25,11 +27,43 @@ file_names["vim_syntax"]      = "extras/vim/syntax/conkyrc.vim"
 file_names["nano_syntax"]     = "extras/nano/conky.nanorc"
 file_names["variables"]       = "doc/variables.xml"
 file_names["config_settings"] = "doc/config_settings.xml"
+file_names["lua"]             = "doc/lua.xml"
+file_names["docs"]            = "doc/docs.xml"
+file_names["command_options"] = "doc/command_options.xml"
 
 for fn in file_names.values():
        if not os.path.exists(fn) or not os.path.isfile(fn):
                print "'%s' doesn't exist, or isn't a file" % (fn)
-               exit(0)
+               exit(1)
+
+print 'sorting/tidying docs...'
+
+# sort the docs by variable/config setting
+import string
+import xml.etree.ElementTree as ET
+
+vars_xml = ET.parse(file_names['variables'])
+config_xml = ET.parse(file_names['config_settings'])
+
+getkey = lambda x: x.findtext('term/command/option')
+
+vars = vars_xml.getroot()
+vars[:] = sorted(vars, key=getkey)
+
+configs = config_xml.getroot()
+configs[:] = sorted(configs, key=getkey)
+
+vars_xml.write(file_names['variables'])
+config_xml.write(file_names['config_settings'])
+
+def tidy(file):
+       command = ['tidy', '-qim', '-xml', '-utf8', '--indent-spaces', '4']
+       os.system('%s %s 2>/dev/null' % (string.join(command), file))
+
+tidy(file_names['variables'])
+tidy(file_names['config_settings'])
+tidy(file_names['lua'])
+tidy(file_names['command_options'])
 
 #
 # Do all the objects first
@@ -50,21 +84,19 @@ while file:
                        # ignore colourN stuff
                        objects.append(res.group(1))
 file.close()
+print 'counted %i text objects' % len(objects)
 
 doc_objects = []
 exp = re.compile("\s*<command><option>(\w*)</option></command>.*")
 print "checking docs -> objs consistency (in %s)" % (file_names["text_objects"])
-file = open(file_names["variables"], "r")
-while file:
-       line = file.readline()
-       if len(line) == 0:
-               break
-       res = exp.match(line)
-       if res:
-               doc_objects.append(res.group(1))
-               if doc_objects[len(doc_objects) - 1] != "templateN" and doc_objects[len(doc_objects) - 1] not in objects:
-                       print "   '%s' is documented, but doesn't seem to be an object" % (doc_objects[len(doc_objects) - 1])
-file.close()
+for var in vars:
+       term = getkey(var)
+       doc_objects.append(term)
+       if ['templaten', 'colorn'].count(doc_objects[len(doc_objects) - 1].lower()):
+               # ignore these
+               continue
+       if doc_objects[len(doc_objects) - 1] not in objects:
+               print "   '%s' is documented, but doesn't seem to be an object" % (doc_objects[len(doc_objects) - 1])
 print "done\n"
 
 print "checking objs -> docs consistency (in %s)" % (file_names["variables"])
@@ -77,7 +109,7 @@ print "done\n"
 # Now we'll do config settings
 #
 
-configs = []
+config_entries = []
 
 file = open(file_names["conky"], "r")
 exp1 = re.compile('\s*CONF\("(\w*)".*')
@@ -96,28 +128,25 @@ while file:
                conf = res.group(1)
                if re.match("color\d", conf):
                        conf = "colorN"
-               if configs.count(conf) == 0:
-                       configs.append(conf)
+               if config_entries.count(conf) == 0:
+                       config_entries.append(conf)
 file.close()
+print 'counted %i config settings' % len(config_entries)
 
 doc_configs = []
-exp = re.compile("\s*<term><command><option>(\w*)</option></command>.*")
 print "checking docs -> configs consistency (in %s)" % (file_names["conky"])
-file = open(file_names["config_settings"], "r")
-while file:
-       line = file.readline()
-       if len(line) == 0:
-               break
-       res = exp.match(line)
-       if res:
-               doc_configs.append(res.group(1))
-               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:
-                       print "   '%s' is documented, but doesn't seem to be a config setting" % (doc_configs[len(doc_configs) - 1])
-file.close()
+for config in configs:
+       term = getkey(config)
+       doc_configs.append(term)
+       if ['text', 'templaten'].count(doc_configs[len(doc_configs) - 1].lower()):
+               # ignore these
+               continue
+       if doc_configs[len(doc_configs) - 1] not in config_entries:
+               print "   '%s' is documented, but doesn't seem to be a config setting" % (doc_configs[len(doc_configs) - 1])
 print "done\n"
 
 print "checking configs -> docs consistency (in %s)" % (file_names["config_settings"])
-for obj in configs:
+for obj in config_entries:
        if obj != "text" and obj != "template" and obj not in doc_configs:
                print "   '%s' seems to be undocumented" % (obj)
 print "done\n"
@@ -128,13 +157,13 @@ print "done\n"
 
 for i in range(0, 10):
        objects.append("color" + str(i))
-       configs.append("color" + str(i))
+       config_entries.append("color" + str(i))
        objects.append("template" + str(i))
-       configs.append("template" + str(i))
+       config_entries.append("template" + str(i))
 
 # Finally, sort everything.
 objects.sort()
-configs.sort()
+config_entries.sort()
 
 #
 # Update nano syntax stuff
@@ -156,7 +185,7 @@ for line in lines:
                idx = lines.index(line)
                lines.pop(idx) # remove old line
                line = 'color green "\<('
-               for obj in configs:
+               for obj in config_entries:
                        line += "%s|" % (obj)
                line = line[:len(line) - 1]
                line += ')\>"\n'
@@ -197,7 +226,7 @@ for line in lines:
                idx = lines.index(line)
                lines.pop(idx) # remove old line
                line = 'syn keyword ConkyrcSetting '
-               for obj in configs:
+               for obj in config_entries:
                        line += "%s " % (obj)
                line = line[:len(line) - 1]
                line += '\n'
@@ -217,32 +246,13 @@ file.seek(0)
 file.writelines(lines)
 file.close()
 
-
-print 'sorting/tidying docs...'
-
-# sort the docs by variable/config setting
-import string
-import xml.etree.ElementTree as ET
-
-vars_xml = ET.parse(file_names['variables'])
-config_xml = ET.parse(file_names['config_settings'])
-
-getkey = lambda x: x.findtext('term/command/option')
-
-vars = vars_xml.getroot()
-vars[:] = sorted(vars, key=getkey)
-
-configs = config_xml.getroot()
-configs[:] = sorted(configs, key=getkey)
-
-vars_xml.write(file_names['variables'])
-config_xml.write(file_names['config_settings'])
-
-def tidy(file):
-       command = ['tidy', '-qim', '-xml', '-utf8', '--indent-spaces', '4']
-       os.system('%s %s 2>/dev/null' % (string.join(command), file))
-
-tidy(file_names['variables'])
-tidy(file_names['config_settings'])
+# lastly, update the date in docs.xml
+file = open(file_names["docs"], 'r+')
+map = mmap.mmap(file.fileno(), os.path.getsize(file_names["docs"]))
+d = map.find("<date>")
+d += 6 # skip over first date stuff
+map[d:d+10] = datetime.now().strftime("%F")
+map.close()
+file.close()
 
 print "done."