def run(provided_request=None): global request if provided_request: request = provided_request else: from MoinMoin.request import RequestCLI request = RequestCLI() request.form = request.args = request.setup_args() # {'query_string': 'action=print'} request.user = user.User(request) suite = makeSuite() unittest.TextTestRunner(stream=request, verbosity=2).run(suite)
def run(request=None, names=None): """ Run test suit @param request: current request @param names: list fully qualified module names to test, e.g MoinMoin._tests.test_error """ if request is None: from MoinMoin.request import RequestCLI from MoinMoin.user import User request = RequestCLI() request.form = request.args = request.setup_args() request.user = User(request) suite = makeSuite(request, names) TextTestRunner(stream=request, verbosity=2).run(suite)
def main(): args = sys.argv if len(args)-1 not in (2, 3) or args[1] not in ('l', 'i'): print >> sys.stderr, """MoinMoin Package Installer v%(version)i %(myname)s action packagefile [request URL] action - Either "l" for listing the script or "i" for installing. packagefile - The path to the file containing the MoinMoin installer package request URL - Just needed if you are running a wiki farm, used to differentiate the correct wiki. Example: %(myname)s i ../package.zip """ % {"version": MAX_VERSION, "myname": os.path.basename(args[0])} raise SystemExit packagefile = args[2] if len(args) > 3: request_url = args[3] else: request_url = "localhost/" # Setup MoinMoin environment from MoinMoin.request import RequestCLI request = RequestCLI(url = 'localhost/') request.form = request.args = request.setup_args() package = ZipPackage(request, packagefile) if not package.isPackage(): print "The specified file %s is not a package." % packagefile raise SystemExit if args[1] == 'l': print package.getScript() elif args[1] == 'i': if package.installPackage(): print "Installation was successful!" else: print "Installation failed." if package.msg: print package.msg
from MoinMoin import wikiutil from MoinMoin.request import RequestCLI from MoinMoin.Page import Page from MoinMoin.PageEditor import PageEditor def makepage(rootdir, pagename, text): """quick and dirty!""" pagedir = os.path.join(rootdir, 'pages', wikiutil.quoteWikinameFS(pagename)) os.makedirs(pagedir) revstr = '%08d' % 1 cf = os.path.join(pagedir, 'current') open(cf, 'w').write(revstr+'\n') revdir = os.path.join(pagedir, 'revisions') os.makedirs(revdir) tf = os.path.join(revdir, revstr) text = text.replace("\n","\r\n") codecs.open(tf, 'wb', config.charset).write(text) request = RequestCLI(url=url) request.form = request.args = request.setup_args() pagelist = list(request.rootpage.getPageList(user='')) for pagename in pagelist: p = Page(request, pagename) text = p.get_raw_body() makepage(destdir, pagename, text)
def mainloop(self): """ moin-dump's main code. """ if len(sys.argv) == 1: self.parser.print_help() sys.exit(1) # Prepare output directory outputdir = self.args[0] outputdir = os.path.abspath(outputdir) if not os.path.isdir(outputdir): try: os.mkdir(outputdir) _util.log("Created output directory '%s'!" % outputdir) except OSError: _util.fatal("Cannot create output directory '%s'!" % outputdir) # Load the configuration configdir = self.options.configdir if configdir: if os.path.isfile(configdir): configdir = os.path.dirname(configdir) if not os.path.isdir(configdir): _util.fatal("Bad path given to --config parameter") configdir = os.path.abspath(configdir) sys.path[0:0] = [configdir] os.chdir(configdir) # Dump the wiki request = RequestCLI(self.options.wiki_url) request.form = request.args = request.setup_args() # fix url_prefix so we get relative paths in output html request.cfg.url_prefix = url_prefix if self.options.page: pages = [self.options.page] else: # Get all existing pages in the wiki pages = list(request.rootpage.getPageList(user="")) pages.sort() wikiutil.quoteWikinameURL = lambda pagename, qfn=wikiutil.quoteWikinameFS: (qfn(pagename) + HTML_SUFFIX) errfile = os.path.join(outputdir, "error.log") errlog = open(errfile, "w") errcnt = 0 page_front_page = wikiutil.getSysPage(request, "FrontPage").page_name page_title_index = wikiutil.getSysPage(request, "TitleIndex").page_name page_word_index = wikiutil.getSysPage(request, "WordIndex").page_name navibar_html = "" for p in [page_front_page, page_title_index, page_word_index]: navibar_html += ' [<a href="%s">%s</a>]' % (wikiutil.quoteWikinameFS(p), wikiutil.escape(p)) for pagename in pages: file = wikiutil.quoteWikinameURL(pagename) # we have the same name in URL and FS _util.log('Writing "%s"...' % file) try: pagehtml = "" page = Page.Page(request, pagename) try: request.reset() out = StringIO.StringIO() request.redirect(out) page.send_page(request, count_hit=0, content_only=1) pagehtml = out.getvalue() request.redirect() except: errcnt = errcnt + 1 print >>sys.stderr, "*** Caught exception while writing page!" print >> errlog, "~" * 78 print >> errlog, file # page filename import traceback traceback.print_exc(None, errlog) finally: timestamp = time.strftime("%Y-%m-%d %H:%M") filepath = os.path.join(outputdir, file) fileout = codecs.open(filepath, "w", config.charset) fileout.write( page_template % { "charset": config.charset, "pagename": pagename, "pagehtml": pagehtml, "logo_html": logo_html, "navibar_html": navibar_html, "timestamp": timestamp, "theme": request.cfg.theme_default, } ) fileout.close() # copy FrontPage to "index.html" indexpage = page_front_page if self.options.page: indexpage = self.options.page shutil.copyfile( os.path.join(outputdir, wikiutil.quoteWikinameFS(indexpage) + HTML_SUFFIX), os.path.join(outputdir, "index" + HTML_SUFFIX), ) errlog.close() if errcnt: print >>sys.stderr, "*** %d error(s) occurred, see '%s'!" % (errcnt, errfile)