def run(): usage = "usage: %prog [options] <path to wiki> <pagename>" parser = OptionParser(usage=usage) parser.add_option("-v", "--verbose", action="store_true", dest="verbose", help="Report success") parser.add_option("-a", "--auth", action="store_true", dest="auth", help="Use local user-based wiki authentication") parser.add_option("-c", "--comment", dest="comment", help="Optional change comment for the edit") (options, args) = parser.parse_args() if len(args) != 2: print parser.get_usage() sys.exit(2) # Configdir to path, so wikiconfig can be imported by Request cp = args[0] cp2 = os.path.join(cp, 'config') if os.path.isdir(cp2): cp = cp2 sys.path.insert(0, cp) pagename = unicode(args[1], sys.getfilesystemencoding()) # Make a new request for the page req = MinimalMoinScript(pagename, parse=False) req.page = Page(req, pagename) # Auth if options.auth: import posix, pwd # We need to import contexts before importing users, because otherwise # the relative imports in MoinMoin will fail. import MoinMoin.web.contexts from MoinMoin.user import User req.user = User(req, auth_username=pwd.getpwuid(posix.getuid())[0]) mytext = unicode(sys.stdin.read(), sys.getfilesystemencoding()) if options.comment: savetext(req, pagename, mytext, comment=unicode(options.comment)) else: savetext(req, pagename, mytext) # Must finish the request to ensure that metadata is saved graphdata_close(req)
from graphingwiki.backend.shelvedb import GraphData scriptcontext._graphdata = GraphData(scriptcontext) scriptcontext._graphdata.close() if os.path.exists(options.filename): if not os.path.isfile(options.filename): sys.stderr.write("Destination not a file: %s\n" % (options.filename)) sys.exit(1) os.unlink(options.filename) scriptcontext._graphdata.db = scriptcontext._graphdata.shelveopen(options.filename, "c") scriptcontext._graphdata.readlock = lambda: None scriptcontext._graphdata.writelock = lambda: None for pageobj in pages: page_enc = _e(pageobj.page_name) print "(%*d/%*d) Rehashing %s " % (padding, count, padding, total, page_enc) count += 1 # Implant relevant bits for this page into our recycleable scriptcontext scriptcontext.page = pageobj pagepath = underlay_to_pages(scriptcontext, pageobj) text = pageobj.get_raw_body() # Save the page metadata savegraphdata(pageobj.page_name, scriptcontext, text, pagepath, pageobj) # Must finish the scriptcontext to ensure that metadata is saved & committed scriptcontext.finish() scriptcontext.graphdata.commit() scriptcontext.graphdata.close()