changeset 4:550f4b240e20

make almost look like what we want to do
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 01 Aug 2011 18:31:27 -0700
parents 2a0f13707ccb
children 3464eda1af80
files document_it.py
diffstat 1 files changed, 51 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/document_it.py	Mon Aug 01 17:01:49 2011 -0700
+++ b/document_it.py	Mon Aug 01 18:31:27 2011 -0700
@@ -1,11 +1,19 @@
 #!/usr/bin/env python
 
 """
-update documentation for Mozmill
+update MDN documentation
+
+see:
+http://developer.mindtouch.com/en/ref/MindTouch_API/POST%3Apages%2F%2F%7Bpageid%7D%2F%2Fcontents
+
+The manifest format is in the form:
+
+mozrunner/README.txt  https://developer.mozilla.org/en/Mozrunner
+jsbridge/README.txt   https://developer.mozilla.org/en/JSbridge
+mozmill/README.txt    https://developer.mozilla.org/en/Mozmill
+mozmill/docs/         https://developer.mozilla.org/en/Mozmill/
 """
 
-#http://developer.mindtouch.com/en/ref/MindTouch_API/POST%3Apages%2F%2F%7Bpageid%7D%2F%2Fcontents
-
 import os
 import sys
 import urllib2
@@ -24,34 +32,58 @@
 
 def find_readme(directory):
     """find a README file in a directory"""
+    # XXX currently unused
     for name in README:
         path = os.path.join(directory, name)
         if os.path.exists(path):
             return path
 
+def parse_manifest(filename, directory=None):
+    """
+    reads a documentation manifest; returns a list of two-tuples:
+    [
+    """
+    
+    assert os.path.exists(filename) and os.path.isfile(filename)
+    if directory is None:
+        directory = os.path.dirname(os.path.abspath(filename))
+    lines = [line.strip() for file(filename).readlines()]
+    lines = [line for line in lines
+             if line and not line.startswith('#')]
+    items = []
+    for line in lines:
+        try:
+            f, url = line.split()
+            # TODO: include options as third segment (e.g. format=ReST)
+        except ValueError:
+            raise ValueError("illegal manifest line: '%s'" % line)
+
+        filename = os.path.join(directory, f)
+        if os.path.isdir(filename):
+            pass # TODO
+        else:
+            items.append((filename, url))
+    return items
+
 def main(args=sys.argv[1:]):
 
     # parse command line options
-    usage = '%prog [options]'
+    usage = '%prog [options] manifest <manifest> <...>'
     parser = OptionParser(usage=usage, description=__doc__)
     parser.add_option('-d', '--directory', dest='directory',
                       help='render the documentation to this directory')
-    parser.add_option('-p', '--package', dest='packages',
-                      action='append',
-                      help='package to operate on')
+    parser.add_option('--dest', dest='dest',
+                      default=DEST,
+                      help='base URL of destination')
+    parser.add_option('-u', '--user', dest='user',
+                      help='user name')
     parser.add_option('--list', dest='list', action='store_true',
                       help="list packages")
-    options, args = parser.parse_args(args)
+    options, manifests = parser.parse_args(args)
 
-    # find packages
-    packages = options.__dict__.pop('packages')
-    if not packages:
-        packages = [i for i in os.listdir(DIR)
-                    if os.path.isdir(os.path.join(DIR, i))
-                    and find_readme(os.path.join(DIR, i))]
-    if options.list:
-        for i in packages:
-            print i
+    if not args:
+        parser.print_usage()
+        parser.exit()
 
     # run setup_development.py in this directory
     # to ensure documentation is up to date
@@ -60,5 +92,7 @@
     # render and upload READMEs
     # TODO
 
+
+
 if __name__ == '__main__':
     main()