view document_it.py @ 2:58befca0eb17

somethin
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 01 Aug 2011 16:37:59 -0700
parents 53c7f9c7dfb6
children 550f4b240e20
line wrap: on
line source

#!/usr/bin/env python

"""
update documentation for Mozmill
"""

#http://developer.mindtouch.com/en/ref/MindTouch_API/POST%3Apages%2F%2F%7Bpageid%7D%2F%2Fcontents

import os
import sys
import urllib2
from optparse import OptionParser

# necessary imports
try:
    import markdown
except ImportError:
    raise ImportError("markdown is not installed, run (e.g.):\neasy_install Markdown")

#DEST='http://developer.mozilla.org/'
DEST='https://developer-stage9.mozilla.org/'
DIR=os.path.dirname(os.path.abspath(__file__))
README=['README.md', 'README.txt', 'README']

def find_readme(directory):
    """find a README file in a directory"""
    for name in README:
        path = os.path.join(directory, name)
        if os.path.exists(path):
            return path

def main(args=sys.argv[1:]):

    # parse command line options
    usage = '%prog [options]'
    parser = OptionParser(usage=usage, description=__doc__)
    parser.add_option('-d', '--directory', dest='directory',
                      help='render the documentation to this directory')
    parser.add_option('-p', '--package', dest='packages',
                      action='append',
                      help='package to operate on')
    parser.add_option('--list', dest='list', action='store_true',
                      help="list packages")
    options, args = parser.parse_args(args)

    # find packages
    packages = options.__dict__.pop('packages')
    if not packages:
        packages = [i for i in os.listdir(DIR)
                    if os.path.isdir(os.path.join(DIR, i))
                    and find_readme(os.path.join(DIR, i))]
    if options.list:
        for i in packages:
            print i

    # run setup_development.py in this directory
    # to ensure documentation is up to date
    # TODO; as yet unneeded

    # render and upload READMEs
    # TODO

if __name__ == '__main__':
    main()