#!/usr/local/bin/python
# -*- coding: iso-8859-1 -*-
#
# wikiget.py v1.0
#
# Retrieve the raw text of a Moin page.
#
# By: Max Campos <mcampos@bpsw.biz>
# Sept. 1, 2005

def parseOpts():
	from optparse import OptionParser

	usage = "usage: %prog [options] SomePage"
	op = OptionParser(usage=usage)
	op.add_option('-w', '--wikidir', dest='wikidir', 
		help="Dir containing your wikiconf.py");
	
	(options, args) = op.parse_args()
	if len(args) > 0:
		options.pagename = args[0]
	else:
		op.error("You must specify a page name.")

	return options
	
	
from MoinMoin.request import RequestCLI
from MoinMoin.Page import Page
import os
import sys

opts = parseOpts() or sys.exit(1)

# Do chdir to the wikidir so that any relative file paths in
# the wiki config work.
if opts.wikidir:
	os.chdir(opts.wikidir)
	sys.path.append(opts.wikidir)

request = RequestCLI(url='foo')
p = Page(request, opts.pagename)

# Return the raw wiki text.
print p.getPageText()