Mercurial > mozilla > hg > DocumentIt
comparison 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 |
comparison
equal
deleted
inserted
replaced
13:1efb669ab1c8 | 14:145a11393a73 |
---|---|
43 for name in README: | 43 for name in README: |
44 path = os.path.join(directory, name) | 44 path = os.path.join(directory, name) |
45 if os.path.exists(path): | 45 if os.path.exists(path): |
46 return path | 46 return path |
47 | 47 |
48 def parse_manifest(filename, directory=None): | 48 def parse_manifest(filename, baseurl, directory=None): |
49 """ | 49 """ |
50 reads a documentation manifest; returns a list of two-tuples: | 50 reads a documentation manifest; returns a list of two-tuples: |
51 [(filename, destination)] | 51 [(filename, destination)] |
52 """ | 52 """ |
53 | 53 |
57 directory = os.path.dirname(os.path.abspath(filename)) | 57 directory = os.path.dirname(os.path.abspath(filename)) |
58 lines = [line.strip() for line in file(filename).readlines()] | 58 lines = [line.strip() for line in file(filename).readlines()] |
59 lines = [line for line in lines | 59 lines = [line for line in lines |
60 if line and not line.startswith('#')] | 60 if line and not line.startswith('#')] |
61 items = [] | 61 items = [] |
62 baseurl = baseurl.rstrip('/') | |
62 for line in lines: | 63 for line in lines: |
63 try: | 64 try: |
64 f, url = line.split() | 65 f, url = line.split() |
65 # TODO: include options as third segment (e.g. format=ReST) | 66 # TODO: include options as third segment (e.g. format=ReST) |
66 except ValueError: | 67 except ValueError: |
67 raise ValueError("illegal manifest line: '%s'" % line) | 68 raise ValueError("illegal manifest line: '%s'" % line) |
68 | 69 |
69 url = url.lstrip('/') # no leading /s | 70 if '://' not in url: |
71 url = '%s/%s' % (baseurl, url.lstrip('/')) | |
70 filename = os.path.join(directory, f) | 72 filename = os.path.join(directory, f) |
71 if os.path.isdir(filename): | 73 if os.path.isdir(filename): |
72 pass # TODO | 74 pass # TODO |
73 else: | 75 else: |
74 items.append((filename, url)) | 76 items.append((filename, url)) |
118 baseurl = 'file://' + options.dest | 120 baseurl = 'file://' + options.dest |
119 | 121 |
120 # read the manifests | 122 # read the manifests |
121 files = [] | 123 files = [] |
122 for manifest in manifests: | 124 for manifest in manifests: |
123 for item in parse_manifest(manifest, options.directory): | 125 for item in parse_manifest(manifest, baseurl, options.directory): |
124 if item not in files: | 126 if item not in files: |
125 files.append(item) | 127 files.append(item) |
126 if options.list: | 128 if options.list: |
127 for item in files: | 129 for item in files: |
128 print '%s -> %s/%s' % (item[0], baseurl.rstrip('/'), item[1].lstrip('/')) | 130 print '%s -> %s' % item |
129 | 131 |
130 if not files: | 132 if not files: |
131 return # you're done | 133 return # you're done |
132 | 134 |
133 # render and upload READMEs | 135 # render and upload READMEs |