def main(): args = sys.argv myusername = '' if (len(args) > 1) and (args[1] == '-u'): args.pop(1) myusername = args.pop(1) 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 = None # Setup MoinMoin environment from MoinMoin.web.contexts import ScriptContext request = ScriptContext(url=request_url) if myusername: request.user = user.User(request, auth_username=myusername) 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
def execute(pagename, request): """ Handle action=IntraFarmCopy """ if not request.user.may.read(pagename): Page(request, pagename).send_page() return # Which local farm wiki - assume team for now to_wiki_url = COPY_TO_WIKI_URL # New page name to_wiki_pagename = '%s%s' % (COPY_TO_PREFIX, pagename) # create page at local wiki if it doesn't exist to_request = ScriptContext(to_wiki_url) # login this user remotely to_uid = user.getUserId(to_request, request.user.name) to_user = user.User(to_request, id=to_uid, name=request.user.name, password=request.user.password, auth_method="moin") to_request.user = to_user try: page = Page(to_request, to_wiki_pagename) except: return action_error(u'Error accessing destination page') if not page.exists(): pe = PageEditor(to_request, to_wiki_pagename) # make initial revision pointer to original try: pe.saveText(u'[[%s:%s]]' % (request.cfg.interwikiname, pagename), 0, comment="Automated IntraFarmCopy pointing to original page") except pe.Unchanged: return action_error(u'Could not save initial page') except pe.AccessDenied: return action_error(u'Could not acquire credentials') # make next revision content of this page try: pe.saveText(Page(request, pagename).get_raw_body(), 0, comment="Automated IntraFarmCopy importing contents from original page at [[%s:%s]]" % (request.cfg.interwikiname, pagename)) except pe.Unchanged: return action_error(u'Could not save destination page text') # send attachments over attachments = AttachFile._get_files(request, pagename) for attachname in attachments: filename = AttachFile.getFilename(request, pagename, attachname) if not os.path.isfile(filename): continue to_filename = AttachFile.getFilename(to_request, to_wiki_pagename, attachname) shutil.copyfile(filename, to_filename) AttachFile._addLogEntry(to_request, 'ATTNEW', to_wiki_pagename, attachname) # redirect user to view new page in other wiki request.http_redirect('%s%s' % (to_wiki_url, to_wiki_pagename)) return else: return action_error(u'Destination page already exists!')
def main(): args = sys.argv myusername='' if (len(args) > 1) and (args[1] == '-u'): args.pop(1) myusername = args.pop(1) 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 = None # Setup MoinMoin environment from MoinMoin.web.contexts import ScriptContext request = ScriptContext(url=request_url) if myusername: request.user = user.User(request, auth_username=myusername) 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
def createpage(groupname, groupmemberlist): request = ScriptContext('http://*****:*****@example.com') request.user = user # Group name added at the end groupname = groupname + 'Group' pe = PageEditor(request, groupname) #memberlist =['Tom','Harry','Steph','Rama'] memberlist = groupmemberlist mystring = ' * ' mynewlist = ['#acl ItGroup:read,write,delete,revert,admin Known: All:' ] + [mystring + x for x in memberlist] mynewlist = '\n'.join(mynewlist) try: pe.saveText(mynewlist, 0) except pe.Unchanged: print "You did not change the page content, not saved!"
def newday (Wiki, ParentPage, TemplatePage, NewPage, Editor, UidName, GidName): from os import seteuid,setegid from pwd import getpwnam from grp import getgrnam uid = getpwnam(UidName).pw_uid gid = getgrnam(GidName).gr_gid setegid(gid) seteuid(uid) from MoinMoin.PageEditor import PageEditor from MoinMoin.Page import Page from MoinMoin.user import getUserId, User from MoinMoin.web.contexts import ScriptContext PageName = "%s/%s" % (ParentPage,NewPage) RequestPage = ScriptContext(Wiki, PageName) UserId = getUserId(RequestPage, Editor) RequestPage.user = User(RequestPage, UserId) Editor = PageEditor(RequestPage, PageName) Dummy, Revision, Exists = Editor.get_rev() if not Exists: RequestTemplate = ScriptContext(Wiki, TemplatePage) Viewer = Page(RequestTemplate, TemplatePage) Text = Viewer.getPageText().replace("@PAGE@", NewPage) Header = Viewer.getPageHeader() Text=Header+Text return Editor.saveText(Text, Revision)
#source http://stackoverflow.com/questions/5275856/moinmoin-1-9-programmatically-creating-page-error-moinmoin-pageeditor-accessden # and https://moinmo.in/MoinAPI/Examples#PageEditor.saveText.28.29 from MoinMoin.web.contexts import ScriptContext from MoinMoin.PageEditor import PageEditor import MoinMoin.user request = ScriptContext('http://*****:*****@example.com') request.user = user pe = PageEditor(request, 'MyNewTestPageGroup') memberlist = ['Tom', 'Harry', 'Steph', 'Rama'] mystring = ' * ' mynewlist = ['#acl ItGroup:read,write,delete,revert,admin Known: All:' ] + [mystring + x for x in memberlist] mynewlist = '\n'.join(mynewlist) try: pe.saveText(mynewlist, 0) except pe.Unchanged: print "You did not change the page content, not saved!" print ' t '
def execute(pagename, request): """ Handle action=IntraFarmCopy """ if not request.user.may.read(pagename): Page(request, pagename).send_page() return # Which local farm wiki - assume team for now to_wiki_url = COPY_TO_WIKI_URL # New page name to_wiki_pagename = '%s%s' % (COPY_TO_PREFIX, pagename) # create page at local wiki if it doesn't exist to_request = ScriptContext(to_wiki_url) # login this user remotely to_uid = user.getUserId(to_request, request.user.name) to_user = user.User(to_request, id=to_uid, name=request.user.name, password=request.user.password, auth_method="moin") to_request.user = to_user try: page = Page(to_request, to_wiki_pagename) except: return action_error(u'Error accessing destination page') if not page.exists(): pe = PageEditor(to_request, to_wiki_pagename) # make initial revision pointer to original try: pe.saveText( u'[[%s:%s]]' % (request.cfg.interwikiname, pagename), 0, comment="Automated IntraFarmCopy pointing to original page") except pe.Unchanged: return action_error(u'Could not save initial page') except pe.AccessDenied: return action_error(u'Could not acquire credentials') # make next revision content of this page try: pe.saveText( Page(request, pagename).get_raw_body(), 0, comment= "Automated IntraFarmCopy importing contents from original page at [[%s:%s]]" % (request.cfg.interwikiname, pagename)) except pe.Unchanged: return action_error(u'Could not save destination page text') # send attachments over attachments = AttachFile._get_files(request, pagename) for attachname in attachments: filename = AttachFile.getFilename(request, pagename, attachname) if not os.path.isfile(filename): continue to_filename = AttachFile.getFilename(to_request, to_wiki_pagename, attachname) shutil.copyfile(filename, to_filename) AttachFile._addLogEntry(to_request, 'ATTNEW', to_wiki_pagename, attachname) # redirect user to view new page in other wiki request.http_redirect('%s%s' % (to_wiki_url, to_wiki_pagename)) return else: return action_error(u'Destination page already exists!')