changeset 11:df6c2e71b87e

actually render
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 01 Aug 2011 23:25:46 -0700
parents 853214384bd0
children 54e27f046cd2
files document_it.py
diffstat 1 files changed, 19 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/document_it.py	Mon Aug 01 23:14:31 2011 -0700
+++ b/document_it.py	Mon Aug 01 23:25:46 2011 -0700
@@ -110,6 +110,7 @@
         parser.exit()
 
     # get base url
+    assert options.dest
     if '://' in options.dest:
         baseurl = options.dest
     else:
@@ -118,7 +119,7 @@
     # read the manifests
     files = []
     for manifest in manifests:
-        for item in parse_manifest(manifest):
+        for item in parse_manifest(manifest, options.directory):
             if item not in files:
                 files.append(item)
     if options.list:
@@ -129,23 +130,33 @@
         return # you're done
 
     # render and upload READMEs
-    if options.directory:
+    if baseurl.startswith('file://'):
+        options.dest = baseurl[len('file://'):] # deals with --dest file:///foo from command line
 
-        # create a directory if needed
-        if os.path.exists(options.directory):
-            assert os.path.isdir(options.directory), "'%s' - not a directory" % options.directory
-        else:
-            os.makedirs(options.directory)
+        # ensure a directory
+        if os.path.exists(options.dest):
+            assert os.path.isdir(options.dest), "'%s' - not a directory" % options.dest
 
         # TODO render to directory
         for src, dest in files:
             dest = os.path.join(options.dest, dest)
+
+            # create a directory if needed
+            dirname = os.path.dirname(dest)
+            os.makedirs(dirname)
+
+            # render
+            f = file(dest, 'w')
+            buffer = markdown.Markdown().convert(file(src).read())
+            f.write(buffer)
+            f.close()
     else:
         # TODO check credentials
         raise NotImplementedError
 
+    
     if options.dest == default_dir:
-        print "Files rendered to %s" % default_dir
+        print "Files rendered to\n%s" % default_dir
 
 if __name__ == '__main__':
     main()