toybox/scripts/mkstatus.py
<<
>>
Prefs
   1#!/usr/bin/python
   2
   3# Create status.html
   4
   5import subprocess,sys
   6
   7def readit(args, shell=False):
   8  ret={}
   9  arr=[]
  10  blob=subprocess.Popen(args, stdout=subprocess.PIPE, shell=shell)
  11  for i in blob.stdout.read().split("\n"):
  12    if not i: continue
  13    i=i.split()
  14    try: ret[i[0]].extend(i[1:])
  15    except: ret[i[0]]=i[1:]
  16    arr.extend(i)
  17  return ret,arr
  18
  19# Run sed on roadmap and source to get command lists, and run toybox too
  20# This gives us a dictionary of types, each with a list of commands
  21
  22print "Collecting data..."
  23
  24stuff,blah=readit(["sed","-n", 's/<span id=\\([a-z_]*\\)>/\\1 /;t good;d;:good;h;:loop;n;s@</span>@@;t out;H;b loop;:out;g;s/\\n/ /g;p', "www/roadmap.html"])
  25blah,toystuff=readit(["./toybox"])
  26blah,stuff["shell"]=readit(["sed", "-n", "s/.*NEWTOY[(]\\([^,]*\\).*TOYFLAG_NOFORK.*/\\1/p", "toys/pending/sh.c"])
  27blah,pending=readit(["/bin/bash", "-c", "sed -n 's/[^ \\t].*TOY(\\([^,]*\\),.*/\\1/p' toys/pending/*.c"])
  28version=readit(["./toybox","--version"])[-1][-1]
  29
  30print "Analyzing..."
  31
  32# Create reverse mappings: reverse["command"] gives list of categories it's in
  33reverse={}
  34for i in stuff:
  35  for j in stuff[i]:
  36    try: reverse[j].append(i)
  37    except: reverse[j]=[i]
  38print "all commands=%s" % len(reverse)
  39
  40# Run a couple sanity checks on input
  41
  42for i in toystuff:
  43  if (i in pending): print "barf %s" % i
  44
  45unknowns=[]
  46for i in toystuff + pending:
  47  if not i in reverse: unknowns.append(i)
  48
  49if unknowns: print "uncategorized: %s" % " ".join(unknowns)
  50
  51conv = [("posix", '<a href="http://pubs.opengroup.org/onlinepubs/9699919799/utilities/%s.html">%%s</a>', "[%s]"),
  52        ("lsb", '<a href="http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/%s.html">%%s</a>', '&lt;%s&gt;'),
  53        ("development", '<a href="https://man7.org/linux/man-pages/man1/%s.1.html">%%s</a>', '(%s)'),
  54        ("toolbox", "", '{%s}'), ("klibc_cmd", "", '=%s='),
  55        ("sash_cmd", "", '#%s#'), ("sbase_cmd", "", '@%s@'),
  56        ("beastiebox_cmd", "", '*%s*'), ("tizen_cmd", "", '$%s$'),
  57        ("fhs_cmd", "", '-%s-'), ("yocto_cmd", "", ".%s."),
  58        ("shell", "", "%%%s%%"),
  59        ("request", '<a href="https://man7.org/linux/man-pages/man1/%s.1.html">%%s</a>', '+%s+')]
  60
  61def categorize(reverse, i, skippy=""):
  62  linky = "%s"
  63  out = i
  64
  65  if skippy: types = filter(lambda a: a != skippy, reverse[i])
  66  else: types = reverse[i]
  67
  68  for j in conv:
  69    if j[0] in types:
  70      if j[1]: linky = j[1] % i
  71      out = j[2] % out
  72      if not skippy: break
  73  if (not skippy) and out == i:
  74    sys.stderr.write("unknown %s %s\n" % (i,reverse[i]))
  75
  76  return linky % out
  77
  78# Sort/annotate done, pending, and todo item lists
  79
  80allcmd=[]
  81done=[]
  82pend=[]
  83todo=[]
  84blah=list(reverse)
  85blah.sort()
  86for i in blah:
  87  out=categorize(reverse, i)
  88  allcmd.append(out)
  89  if i in toystuff or i in pending:
  90    if i in toystuff: done.append(out)
  91    else: pend.append(out)
  92    out='<strike>%s</strike>' % out
  93  else: todo.append(out)
  94
  95print "implemented=%s" % len(toystuff)
  96
  97# Write data to output file
  98
  99outfile=open("www/status.html", "w")
 100outfile.write("""<html><head><title>toybox current status</title>
 101<!--#include file="header.html" -->
 102<title>Toybox Status</title>
 103""");
 104outfile.write("<h1>Status of toybox %s</h1>\n" % version);
 105outfile.write("<h3>Legend: %s <strike>pending</strike></h3>\n"%" ".join(map(lambda i: i[2]%(i[0].split("_")[0]), conv)))
 106
 107outfile.write("<a name=done><h2><a href=#done>Completed</a></h2><blockquote><p>%s</p></blockquote>\n" % "\n".join(done))
 108outfile.write("<a name=part><h2><a href=#part>Partially implemented (in toys/pending)</a></h2><blockquote><p>%s</p></blockquote>\n" % "\n".join(pend))
 109outfile.write("<a name=todo><h2><a href=#todo>Not started yet</a></h2><blockquote><p>%s</p></blockquote>\n" % "\n".join(todo))
 110
 111# Output unfinished commands by category
 112
 113outfile.write("<hr><h2>Categories of remaining todo items</h2>")
 114
 115for i in conv:
 116  todo = []
 117  i=i[0]
 118
 119  for j in stuff[i]:
 120    if j in toystuff: continue
 121    if j in pending: todo.append('<strike>%s</strike>' % j)
 122    else: todo.append(categorize(reverse,j,i))
 123
 124  if todo:
 125    k = i
 126    for j in conv:
 127      if j[0] == i:
 128        k = j[2] % i.split("_")[0]
 129
 130    outfile.write("<a name=%s><h2><a href=#%s>%s<a></h2><blockquote><p>" % (i,i,k))
 131    outfile.write(" ".join(todo))
 132    outfile.write("</p></blockquote>\n")
 133
 134outfile.write("<hr><a name=all><h2><a href=#all>All commands together in one big list</a></h2><blockquote><p>%s</p></blockquote>\n" % "\n".join(allcmd))
 135
 136outfile.write("""
 137<p>See the <a href=roadmap.html>Roadmap page</a> for more information.</p>
 138
 139<!-- #include "footer.html" -->""")
 140