Mercurial > mozilla > hg > DocumentIt
diff document_it.py @ 22:67e4becc7d49
first steps for cleaning up this awful mess
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Wed, 03 Aug 2011 10:58:45 -0700 |
parents | 7299c4529b41 |
children | e6ed732e8ce6 |
line wrap: on
line diff
--- 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: