comparison document_it.py @ 18:f7dc318832dc

misc improvements
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 02 Aug 2011 19:14:32 -0700
parents 0a1aecef2c52
children 493683e17eae
comparison
equal deleted inserted replaced
17:0a1aecef2c52 18:f7dc318832dc
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 all_files(directory):
49 filenames = []
50 for dirpath, dirnames, files in os.walk(directory):
51 filenames.extend([os.path.join(dirpath, f) for f in files])
52 return sorted(filenames)
53
48 def parse_manifest(filename, baseurl, directory=None): 54 def parse_manifest(filename, baseurl, directory=None):
49 """ 55 """
50 reads a documentation manifest; returns a list of two-tuples: 56 reads a documentation manifest; returns a list of two-tuples:
51 [(filename, destination)] 57 [(filename, destination)]
52 """ 58 """
69 75
70 if '://' not in url: 76 if '://' not in url:
71 url = '%s/%s' % (baseurl, url.lstrip('/')) 77 url = '%s/%s' % (baseurl, url.lstrip('/'))
72 filename = os.path.join(directory, f) 78 filename = os.path.join(directory, f)
73 if os.path.isdir(filename): 79 if os.path.isdir(filename):
74 pass # TODO 80 files = all_files(filename)
81 for i in files:
82 relpath = os.path.relpath(i, filename)
83 items.append((i, '%s/%s' % (url.rstrip('/'), relpath.lstrip('/'))))
75 else: 84 else:
76 items.append((filename, url)) 85 items.append((filename, url))
77 return items 86 return items
78 87
79 def main(args=sys.argv[1:]): 88 def main(args=sys.argv[1:]):
148 dest = dest[len('file://'):] 157 dest = dest[len('file://'):]
149 158
150 # create a directory if needed 159 # create a directory if needed
151 dirname = os.path.dirname(dest) 160 dirname = os.path.dirname(dest)
152 if os.path.exists(dirname): 161 if os.path.exists(dirname):
153 assert os.path.isdir(dirname) 162 assert os.path.isdir(dirname), "%s exists and is not a directory" % dirname
154 else: 163 else:
155 os.makedirs(dirname) 164 os.makedirs(dirname)
156 165
157 # render 166 # render
158 f = file(dest, 'w') 167 f = file(dest, 'w')