diff document_it.py @ 14:145a11393a73

better handling of urls
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 02 Aug 2011 16:40:10 -0700
parents 1efb669ab1c8
children d9026d114655
line wrap: on
line diff
--- a/document_it.py	Tue Aug 02 16:36:08 2011 -0700
+++ b/document_it.py	Tue Aug 02 16:40:10 2011 -0700
@@ -45,7 +45,7 @@
         if os.path.exists(path):
             return path
 
-def parse_manifest(filename, directory=None):
+def parse_manifest(filename, baseurl, directory=None):
     """
     reads a documentation manifest; returns a list of two-tuples:
     [(filename, destination)]
@@ -59,6 +59,7 @@
     lines = [line for line in lines
              if line and not line.startswith('#')]
     items = []
+    baseurl = baseurl.rstrip('/')
     for line in lines:
         try:
             f, url = line.split()
@@ -66,7 +67,8 @@
         except ValueError:
             raise ValueError("illegal manifest line: '%s'" % line)
 
-        url = url.lstrip('/') # no leading /s
+        if '://' not in url:
+            url = '%s/%s' % (baseurl, url.lstrip('/'))
         filename = os.path.join(directory, f)
         if os.path.isdir(filename):
             pass # TODO
@@ -120,12 +122,12 @@
     # read the manifests
     files = []
     for manifest in manifests:
-        for item in parse_manifest(manifest, options.directory):
+        for item in parse_manifest(manifest, baseurl, options.directory):
             if item not in files:
                 files.append(item)
     if options.list:
         for item in files:
-            print '%s -> %s/%s' % (item[0], baseurl.rstrip('/'), item[1].lstrip('/'))
+            print '%s -> %s' % item
 
     if not files:
         return # you're done