# HG changeset patch # User Jeff Hammel # Date 1312394325 25200 # Node ID 67e4becc7d49cf765c03eb1b4294435f0864360b # Parent 10c5e6d11ef8c1f2b2619e57ab74f54c20f2988e first steps for cleaning up this awful mess diff -r 10c5e6d11ef8 -r 67e4becc7d49 document_it.py --- a/document_it.py Wed Aug 03 09:53:27 2011 -0700 +++ b/document_it.py Wed Aug 03 10:58:45 2011 -0700 @@ -28,13 +28,15 @@ import tempfile import urllib2 -# necessary imports +# import markdown try: import markdown except ImportError: raise ImportError("markdown is not installed, run (e.g.):\neasy_install Markdown") -DIR=os.path.dirname(os.path.abspath(__file__)) # XXX currently unused +destinations = {'stage': 'https://developer-stage9.mozilla.org/@api/deki/pages/=%(page)s/contents', + 'MDN': 'https://developer.mozilla.org/@api/deki/pages/=%(page)s/contents'} + def find_readme(directory): """find a README file in a directory""" @@ -46,12 +48,13 @@ return path def all_files(directory): + """get all files in a directory tree""" filenames = [] for dirpath, dirnames, files in os.walk(directory): filenames.extend([os.path.join(dirpath, f) for f in files]) return sorted(filenames) -def parse_manifest(filename, baseurl, directory=None): +def parse_manifest(filename, directory=None): """ reads a documentation manifest; returns a list of two-tuples: [(filename, destination)] @@ -65,24 +68,22 @@ 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() + f, page = line.split() # TODO: include options as third segment (e.g. format=ReST) except ValueError: raise ValueError("illegal manifest line: '%s'" % line) - if '://' not in url: - url = '%s%s' % (baseurl, url) filename = os.path.join(directory, f) if os.path.isdir(filename): + raise NotImplementedError files = all_files(filename) for i in files: relpath = os.path.relpath(i, filename) - items.append((i, '%s%s' % (url.rstrip('/'), relpath.lstrip('/')))) + items.append((i, relpath)) else: - items.append((filename, url)) + items.append((filename, page)) return items def main(args=sys.argv[1:]): @@ -133,7 +134,7 @@ # read the manifests files = [] for manifest in manifests: - for item in parse_manifest(manifest, baseurl, options.directory): + for item in parse_manifest(manifest, options.directory): if item not in files: files.append(item) if options.list: