def do_delattachment(self, filename, pagename, author=u"Scripting Subsystem", comment=u""): """ Removes an attachment @param pagename: Page where the file is attached. Or in 2.0, the file itself. @param filename: Filename of the attachment (just applicable for MoinMoin < 2.0) """ if self.request.user.may.write(pagename): _ = self.request.getText attachments = Page(self.request, pagename).getPagePath("attachments", check_create=1) filename = wikiutil.taintfilename(filename) target = os.path.join(attachments, filename) page = PageEditor(self.request, pagename, do_editor_backup=0, uid_override=author) rev = page.current_rev() path = page.getPagePath(check_create=0) if os.path.exists(target): os.remove(target) action = 'ATTDEL' edit_logfile_append(self, pagename, path, rev, action, logname='edit-log', comment=u'%(filename)s' % {"filename": filename}, author=author) self.msg += u"%(filename)s removed \n" % {"filename": filename} else: self.msg += u"%(filename)s does not exist \n" % {"filename": filename} else: self.msg += u"action delete attachment: not enough rights - nothing done \n"
def do_addattachment(self, zipname, filename, pagename, author=u"Scripting Subsystem", comment=u""): """ Installs an attachment @param pagename: Page where the file is attached. Or in 2.0, the file itself. @param zipname: Filename of the attachment from the zip file @param filename: Filename of the attachment (just applicable for MoinMoin < 2.0) """ if self.request.user.may.write(pagename): _ = self.request.getText attachments = Page(self.request, pagename).getPagePath("attachments", check_create=1) filename = wikiutil.taintfilename(filename) zipname = wikiutil.taintfilename(zipname) target = os.path.join(attachments, filename) page = PageEditor(self.request, pagename, do_editor_backup=0, uid_override=author) rev = page.current_rev() path = page.getPagePath(check_create=0) if not os.path.exists(target): self._extractToFile(zipname, target) if os.path.exists(target): os.chmod(target, config.umask ) action = 'ATTNEW' edit_logfile_append(self, pagename, path, rev, action, logname='edit-log', comment=u'%(filename)s' % {"filename": filename}, author=author) self.msg += u"%(filename)s attached \n" % {"filename": filename} else: self.msg += u"%(filename)s not attached \n" % {"filename": filename} else: self.msg += u"action add attachment: not enough rights - nothing done \n"
def do_addattachment(self, zipname, filename, pagename, author=u"Scripting Subsystem", comment=u""): """ Installs an attachment @param pagename: Page where the file is attached. Or in 2.0, the file itself. @param zipname: Filename of the attachment from the zip file @param filename: Filename of the attachment (just applicable for MoinMoin < 2.0) """ if self.request.user.may.write(pagename): _ = self.request.getText attachments = Page(self.request, pagename).getPagePath("attachments", check_create=1) filename = wikiutil.taintfilename(filename) zipname = wikiutil.taintfilename(zipname) target = os.path.join(attachments, filename) page = PageEditor(self.request, pagename, do_editor_backup=0, uid_override=author) rev = page.current_rev() path = page.getPagePath(check_create=0) if not os.path.exists(target): self._extractToFile(zipname, target) if os.path.exists(target): filesys.chmod(target, 0666 & config.umask) action = 'ATTNEW' edit_logfile_append(self, pagename, path, rev, action, logname='edit-log', comment=u'%(filename)s' % {"filename": filename}, author=author) self.msg += u"%(filename)s attached \n" % { "filename": filename } else: self.msg += u"%(filename)s not attached \n" % { "filename": filename } else: self.msg += u"action add attachment: not enough rights - nothing done \n"
def execute(pagename, request): # parse the action request: pe = PageEditor(request, pagename) padtext = pe.get_raw_body() currev = pe.current_rev() padtextEP = padtext.encode('utf-8') # get the etherpad instance and related information: (ep, padname, padURL) = etherpadConnect(pagename) # start the actual writing out to Etherpad. success = False try: r = ep.getText(padname) ep.setText(padname, padtextEP) success = True except ValueError: # print "Etherpad reported valueError" ep.createPad(padname, padtextEP) success = True except: msg = "Unknown error occured when trying to access Etherpad." # put the result of the etherpad invocation back on wiki: if success: admon = """{{{#!wiki caution '''Do not edit this page, it is currently on Etherpad!''' This wiki page is currently edited in an Etherpad session - URL: %s. You really should not edit this page since it is very likely that your edits will get lost once the Etherpad session is integrated back into the wiki. Use the action PullFromEtherpad to trigger that integration (and then stop the Etherpad editing!). }}} """ % padURL savetext = admon + "\n\n" + padtext request.reset() try: pe.saveText(savetext, currev) msg = "no error" except pe.EditConflict, e: # print e msg = "Edit Conflict when trying to push out to Etherpad!" + e.message request.theme.add_msg(msg, "info") pe.send_page()
def do_delattachment(self, filename, pagename, author=u"Scripting Subsystem", comment=u""): """ Removes an attachment @param pagename: Page where the file is attached. Or in 2.0, the file itself. @param filename: Filename of the attachment (just applicable for MoinMoin < 2.0) """ if self.request.user.may.write(pagename): _ = self.request.getText attachments = Page(self.request, pagename).getPagePath("attachments", check_create=1) filename = wikiutil.taintfilename(filename) target = os.path.join(attachments, filename) page = PageEditor(self.request, pagename, do_editor_backup=0, uid_override=author) rev = page.current_rev() path = page.getPagePath(check_create=0) if os.path.exists(target): os.remove(target) action = 'ATTDEL' edit_logfile_append(self, pagename, path, rev, action, logname='edit-log', comment=u'%(filename)s' % {"filename": filename}, author=author) self.msg += u"%(filename)s removed \n" % {"filename": filename} else: self.msg += u"%(filename)s does not exist \n" % { "filename": filename } else: self.msg += u"action delete attachment: not enough rights - nothing done \n"
def execute (pagename, request): # get the etherpad instance and related information: (ep, padname, padURL) = etherpadConnect (pagename) # teh moinmoin data: pe = PageEditor(request, pagename) currev = pe.current_rev() request.reset() try: padtext = ep.getText (padname)[u'text'] try: pe.saveText (padtext, currev) msg = "Text has been successfully obtained from Etherpad." except Exception as e: msg = "Text has been obtained from Etherpad, but an error occured when saving it to Wiki. " except Exception as e: msg = "An error occured when trying to obtain text from Etherpad." request.theme.add_msg(msg, "info") pe.send_page()
def addcomment(macro, comicon, comauthor, comtext, compasswd, comrev, comautopass, commarkup): # Add a comment with inputs request = Globs.macro.request cfg = request.cfg _ = request.getText datapagename = Globs.datapagename pg = PageEditor( request, datapagename ) pagetext = pg.get_raw_body() # HACK for despam try: if not request.user.may.save( pg, comtext, pg.current_rev()): #message("No permission to save this text.") #return 0 pass except pg.SaveError, msg: message(msg) return 0
def execute(pagename, request): # get the etherpad instance and related information: (ep, padname, padURL) = etherpadConnect(pagename) # teh moinmoin data: pe = PageEditor(request, pagename) currev = pe.current_rev() request.reset() try: padtext = ep.getText(padname)[u'text'] try: pe.saveText(padtext, currev) msg = "Text has been successfully obtained from Etherpad." except Exception as e: msg = "Text has been obtained from Etherpad, but an error occured when saving it to Wiki. " except Exception as e: msg = "An error occured when trying to obtain text from Etherpad." request.theme.add_msg(msg, "info") pe.send_page()
def addcomment(macro, comicon, comauthor, comtext, compasswd, comrev, comautopass, commarkup, rating): # Add a comment with inputs request = Globs.macro.request cfg = request.cfg _ = request.getText datapagename = Globs.datapagename pg = PageEditor(request, datapagename) pagetext = pg.get_raw_body() # HACK for despam try: if not request.user.may.save(pg, comtext, pg.current_rev()): #message("No permission to save this text.") #return 0 pass except pg.SaveError, msg: message(msg) return 0
def processWeapon(j, context, is_sub, dry_run): status_map = j.get(u'subStatusMap' if is_sub else u'statusMap', {}) or {} weapon_name = j.get(u'subWeaponName' if is_sub else u'weaponName', u'').strip() level = j.get(u'subWeaponLevel' if is_sub else u'weaponLevel', 0) if not status_map or not weapon_name or not level: print u'Weapon %s is missing critical params.' % weapon_name return page = PageEditor(context, weapon_name) body_pre = u'' body_json = {} body_post = u'' if page.isStandardPage(): match = RE_WEAPON_PAGE.match(page.get_body()) if match: body_pre = match.group(u'pre') body_post = match.group(u'post') try: body_json = json.loads(match.group(u'body')) except Error: pass diff_dst_json = statusMapToAttrs(status_map) if not is_sub and j.get(u'subStatusMap', {}): diff_dst_json[u'サブウェポン'] = { u'名称': j[u'subWeaponName'].strip(), u'レベル': int(j[u'subWeaponLevel']), } if not body_json: body_pre = WEAPON_PAGE_DEFAULT_BODY_PRE body_post = WEAPON_PAGE_DEFAULT_BODY_POST body_json = { u'名称': weapon_name, u'レベル': {}, u'弾種': j.get(u'subBulletTypeName' if is_sub else u'bulletTypeName', u''), } levels_json = body_json.get(u'レベル', {}) if not levels_json: levels_json = {} body_json[u'レベル'] = levels_json dst_json = levels_json.get(u'%d' % level, {}) if not dst_json: dst_json = {} levels_json[u'%d' % level] = dst_json dst_json.update(diff_dst_json) # clenup legacy attrs if u'爆発半径' in dst_json: del dst_json[u'爆発半径'] if u'発射準備時間' in dst_json: del dst_json[u'発射準備時間'] output = (body_pre + u'\n' + json_printer.print_json(body_json, indent=2) + u'\n' + body_post) try: if not dry_run: page.saveText(output, page.current_rev()) print u'Processed weapon %s correctly.' % weapon_name else: differ = difflib.Differ(charjunk=lambda c:c.isspace()) l = map(lambda s: s.strip(), page.get_body().splitlines()) r = map(lambda s: s.strip(), output.splitlines()) if l != r: d = u'\n'.join(filter(lambda s: s and s[0] in u'+-?', differ.compare(l, r))) print((u'#### Diff in %s ####' % weapon_name).encode('utf-8')) print(d.encode('utf-8')) except PageEditor.Unchanged: pass if not is_sub and j.get(u'subStatusMap', {}): processWeapon(j, context, True, dry_run)
def processWeaponPack(j, context, dry_run): wp_name = j.get(u'weaponPackName', None) if not wp_name: return page = PageEditor(context, wp_name) body_pre = u'' body_json = {} body_post = u'' if page.isStandardPage(): match = RE_WP_PAGE.match(page.get_body()) if match: body_pre = match.group(u'pre') body_post = match.group(u'post') try: body_json = json.loads(match.group(u'body')) except Error: pass def getBriefWeaponJson(weapon): return { u'名称': weapon.get(u'weaponName').strip(), u'レベル': weapon.get(u'weaponLevel'), } w_map = j.get(u'weaponMap', {}) json_diff = { u'コスト': j.get(u'cost', 0), u'耐久力': j.get(u'hitPoint', 0), u'格闘補正': j.get(u'grappleUp', 1.0), u'右手武器': getBriefWeaponJson(w_map.get(u'right', {})), u'左手武器': getBriefWeaponJson(w_map.get(u'left', {})), u'サイド武器': getBriefWeaponJson(w_map.get(u'side', {})), u'タンデム武器': getBriefWeaponJson(w_map.get(u'tandem', {})), } if not body_json: body_pre = WP_PAGE_DEFAULT_BODY_PRE body_json = { u'名称': wp_name, u'入手条件': u'', u'タイプ': u'' } body_post = WP_PAGE_DEFAULT_BODY_POST body_json.update(json_diff) output = (body_pre + u'\n' + json_printer.print_json(body_json, indent=2) + u'\n' + body_post) try: if not dry_run: page.saveText(output, page.current_rev()) print u'Processed %s correctly.' % wp_name else: differ = difflib.Differ() l = map(lambda s: s.strip(), page.get_body().splitlines()) r = map(lambda s: s.strip(), output.splitlines()) if l != r: d = u'\n'.join(filter(lambda s: s and s[0] in u'+-?', differ.compare(l, r))) print((u'#### Diff in %s ####' % wp_name).encode('utf-8')) print(d.encode('utf-8')) except PageEditor.Unchanged: pass
import argparse from MoinMoin.PageEditor import PageEditor from MoinMoin.web.contexts import ScriptContext from MoinMoin.web.request import TestRequest from MoinMoin.Page import RootPage from macro.utils import json_printer, json_loader COMMENTS = u"""==== コメント ==== <<AddComment>> <<Comments>>""" RE_COMMENTS = re.compile(ur"====\s*コメント\s*====\s*<<AddComment>>\s*<<Comments>>") if __name__ == "__main__": from MoinMoin import config context = ScriptContext() context.remote_addr = "127.0.0.1" root_page = RootPage(context) for page_name in root_page.getPageList(user=""): page = PageEditor(context, page_name) data = page.get_raw_body() match = RE_COMMENTS.search(data) if match: data = RE_COMMENTS.sub(u"", data) data += COMMENTS page.saveText(data, page.current_rev())