]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tools/tinyos/ncc/nesdoc-py/archive.py
Merge TinyOS 2.1.1 into master.
[tinyos-2.x.git] / tools / tinyos / ncc / nesdoc-py / archive.py
index d0acc40048b0e747c363fbed6ea39c9338da55a9..88fba77e2fd5251285eef8f7fd1337c48a24c346 100644 (file)
@@ -40,6 +40,8 @@ from sys import *
 from getopt import getopt
 from string import *
 from nesdoc.utils import *
+from nesdoc.graph import generate_graph
+from nesdoc.html import *
 import os
 
 def check(x):
@@ -52,11 +54,14 @@ def get1(x, tag):
   return check(xml_tagfind(x, tag))
 
 def usage():
-  print "Usage: %s [-t dir] [--topdir dir] [--preserve] repository" % argv[0]
+  print "Usage: %s [-t dir] [--topdir dir] [--preserve] [--app] [--quiet] repository" % argv[0]
   print "  where -t/--topdir specify prefixes to remove from file names"
   print "  to create nice, package-like names for interface and components"
   print "  (based on their full filename)."
   print "  If --preserve is specified, existing XML files are preserved."
+  print "  If --app is specified, a page for this application is created in the"
+  print "  current directory."
+  print "  If --quiet is specified, the program is less verbose."
   print "  The XML input is read from stdin."
 
 # Return package name for elem, or None if no valid name is found
@@ -65,7 +70,7 @@ def packagename(elem):
   loc = elem.getAttribute("loc")
   colon = index(loc, ":")
   filename = canonicalise(loc[colon + 1:])
-  for dir in topdirs:
+  for dir in topdir:
     dirlen = len(dir)
     if filename[0:dirlen] == dir:
       filename = filename[dirlen:]
@@ -99,12 +104,32 @@ def canonicalisedir(dirname):
     return dirname
 
 # option processing. See usage string for details.
-(opts, args) = getopt(argv[1:], "t:", [ "topdir=", "preserve" ])
-topopts = filter(lambda (x): x[0] != "--preserve", opts)
-preserve = filter(lambda(x): x[0] == "--preserve", opts) != []
-topdirs = map(lambda (x): canonicalisedir(x[1]), topopts)
+def process_opts(argv):
+  options = {
+    "topdir":   (True,  lambda (x): topdir + [canonicalisedir(x)]),
+    "preserve":         (False, lambda x: True),
+    "app":      (False, lambda x: True),
+    "quiet":    (False, lambda x: True),
+  }
+  getopt_args = []
+  for p in options:
+    globals()[p] = False
+    opt = p
+    if options[p][0]:
+      opt += "="
+    getopt_args += [ opt ]
+  (opts, args) = getopt(argv, "", getopt_args)
+  topdir = []
+  highlight = ""
+  for o, a in opts:
+    opt = o[2:]
+    globals()[opt] = options[opt][1](a)
+  return args
+
+args = process_opts(argv[1:])
 if len(args) != 1:
   usage()
+  exit(2)
 
 repository = args[0]
 try:
@@ -143,7 +168,8 @@ for x in interfaces.getElementsByTagName("interface"):
 # and bare commands, events
 for x in functions.getElementsByTagName("function"):
   # hack: tasks don't show up with a command/event attribute
-  if x.hasAttribute("event") or x.hasAttribute("command"):
+  # don't include commands/events from interfaces
+  if (x.hasAttribute("event") or x.hasAttribute("command")) and (not xml_tag(x, "interface-ref")):
     incomponent = get1(x, "component-ref").getAttribute("qname")
     if speclist.has_key(incomponent):
       speclist[incomponent].append(x)
@@ -172,6 +198,30 @@ for x in dom.getElementsByTagName("interfacedef-ref"):
 for x in dom.getElementsByTagName("component-ref"):
   set_nicename(x)
 
+# Do the app stuff if requested
+if app:
+  # The firt component is the main application component.
+  toplevel = xml_idx(components, 0)
+  name = toplevel.getAttribute("qname")
+  nicename = toplevel.getAttribute("nicename")
+  wiring = xml_tag(xml_tag(dom, "nesc"), "wiring")
+  generate_graph(".", repository, dom, wiring, name, nicename)
+
+  ht = Html("%s.html" % nicename)
+  ht.title("Application: " + nicename)
+  ht.body()
+  ht.push("h2");
+  ht.p("Application: " + nicename)
+  ht.popln();
+  ht.pushln("map", 'name="comp"')
+  cmap = file("%s.cmap" % nicename)
+  for line in cmap.readlines():
+    ht.pln(line)
+  cmap.close()
+  ht.popln()
+  ht.tag("img", 'src="%s.png"' % nicename, 'usemap="#comp"', 'id=imgwiring')
+  ht.close()
+
 # save xml information per-interface and per-component in the specified
 # repository
 nmkdir(repository)
@@ -186,7 +236,8 @@ for x in interfacedefs.getElementsByTagName("interfacedef"):
   filename = "interfaces/%s.xml" % nicename
   if preserve and os.path.exists(filename):
     continue
-  print "interface %s (%s)" % (name, nicename)
+  if not quiet:
+    print "interface %s (%s)" % (name, nicename)
   doc = creator.createDocument(None, None, None)
   copy = x.cloneNode(True)
   doc.appendChild(copy)
@@ -204,8 +255,8 @@ for x in components.getElementsByTagName("component"):
     filename = "components/%s.xml" % nicename
     if preserve and os.path.exists(filename):
       continue
-    
-    print "component %s (%s)" % (name, nicename)
+    if not quiet:
+      print "component %s (%s)" % (name, nicename)
     doc = creator.createDocument(None, None, None)
     # copy component and create its specification
     copy = x.cloneNode(True)