#!/usr/bin/env python

WIKI_CONF = "/home/moinwiki/NumpyDocWiki"
PREFIX = "Docstrings"
REPO_DIR = "numpy"
MODULE = "numpy"
FRONTPAGE_FILE = "introduction.rst"

BZR_AUTHOR = "pydoc-moin"
BZR_MESSAGE = "Updated %s docstring"

# -----------------------------------------------------------------------------

import subprocess
import os, shutil

DIR       = os.path.dirname(os.path.abspath(__file__))
REPO_DIR  = os.path.join(DIR, REPO_DIR)
BASEXML   = os.path.join(REPO_DIR, "base.xml")
PYDOCMOIN = os.path.join(DIR, "pydoc-moin.py")
SITE_PTH  = os.path.join(REPO_DIR, "dist/lib/python2.5/site-packages")

def main():
    if not os.path.isdir(SITE_PTH):
        os.makedirs(SITE_PTH)

    os.environ['PYTHONPATH'] = os.path.abspath(SITE_PTH)
    os.chdir(REPO_DIR)
    exec_cmd(['python2.5', 'setupegg.py', 'install', '--prefix=dist'])
    os.chdir(DIR)

    exec_cmd(("%(PYDOCMOIN)s collect -s %(SITE_PTH)s %(MODULE)s "
               "| %(PYDOCMOIN)s prune "
               "| %(PYDOCMOIN)s mangle "
               "| %(PYDOCMOIN)s numpy-docs -s %(SITE_PTH)s -o %(BASEXML)s")
              % dict(SITE_PTH=SITE_PTH, MODULE=MODULE, BASEXML=BASEXML, PYDOCMOIN=PYDOCMOIN), shell=True)
    exec_cmd([PYDOCMOIN, 'moin-upload-local', '-p', PREFIX, 
              '-i', BASEXML, WIKI_CONF, '-f', FRONTPAGE_FILE])
    print "All done."
    print ("Don't recompile %(REPO_DIR)s manually, or regenerate "
           "a new base.xml there." % dict(REPO_DIR=REPO_DIR))

def exec_cmd(cmd, ok_return_value=0, show_cmd=True, echo=False, **kw):
    """
    Run given command and check return value.
    Return concatenated input and output.
    """
    try:
        if show_cmd:
            print '%s$' % os.getcwd(),
            if isinstance(cmd, str):
                print cmd
            else:
                print ' '.join(cmd)
            print '[running ...]'
        p = subprocess.Popen(cmd,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE,
                             stdin=subprocess.PIPE, **kw)
        out, err = p.communicate()
    except OSError, e:
        raise RuntimeError("Command %s failed: %s" % (' '.join(cmd), e))
    
    if ok_return_value is not None and p.returncode != ok_return_value:
        raise RuntimeError("Command %s failed (code %d): %s"
                           % (' '.join(cmd), p.returncode, out + err))
    if echo: print out + err
    return out + err

if __name__ == "__main__": main()

# vim: sw=4 expandtab smarttab

@@ -807,16 +807,30 @@
 nstall',
+%0A             
  '--pref
@@ -836,13 +836,25 @@
 fix=
+%25s/
 dist'
+%25REPO_DIR
 %5D)%0A 

Use full path as install path, so that the source paths seen by inspect become absolute.