Ejemplo n.º 1
0
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 parse_wiki_markup(self, formatter, text):
     """
     Return result of parsing previously escaped text by MoinMoin wiki parser.
     Only allowed and therefore unescaped special command is '<<BR>>'.
     """
     unescaped_text = text.replace('&lt;&lt;BR&gt;&gt;', '<<BR>>')
     request = ScriptContext()
     buf = StringIO.StringIO()
     request.redirect(buf)
     wiki_parser = text_moin_wiki.Parser(unescaped_text, request)
     wiki_parser.format(formatter)
     return buf.getvalue().replace('\n', ' ')
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
def MinimalMoinScript(pagename='', parse=True):
    """
    The MoinScript class does command line argument parsing, which
    might not be what is desired, as it will complain about custom
    arguments in graphingwiki-based scripts. MoinScript initialises
    the request by calling up ScriptContext, which is then assigned to
    the script.request.

    If a gwiki script uses non-MoinScript command line arguments,
    the ScriptContext is initialized with minimum sane default.
    """
    if parse:
        script = MoinScript()
        if pagename:
            script.parser.set_defaults(page=pagename)
        script.options, script.args = script.parser.parse_args()
        script.init_request()
        return script.request

    from MoinMoin.web.contexts import ScriptContext
    # Default values
    return ScriptContext(None, pagename)
Ejemplo n.º 5
0
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!"
Ejemplo n.º 6
0
            if not mailaddr in wiki_addrs
        ])
        subj_col = '[[%s|%s]]' % (pagename, msg['subject'])
        date_col = msg['date']
        attach_col = " ".join(attachment_links)
        new_line = u'|| <<DateTime(%s)>> || %s || %s || %s || %s ||' % (
            date_col, from_col, to_col, subj_col, attach_col)
        if found_table is not None:
            content = "\n".join(old_content[:table_ends] + [new_line] +
                                old_content[table_ends:])
        else:
            content = "\n".join(old_content) + table_header + new_line

        page = PageEditor(request, parent_page, do_editor_backup=0)
        page.saveText(content, 0, comment=comment)


if __name__ == "__main__":
    if len(sys.argv) > 1:
        request_url = sys.argv[1]
    else:
        request_url = None

    from MoinMoin.web.contexts import ScriptContext
    request = ScriptContext(url=request_url)

    try:
        import_mail_from_file(request, infile)
    except ProcessingError, e:
        print >> sys.stderr, "An error occurred while processing the message:", e.args
Ejemplo n.º 7
0
 def init_request(self):
     """ create request """
     from MoinMoin.web.contexts import ScriptContext
     url = self.options.wiki_url or None
     self.request = ScriptContext(url, self.options.page)
Ejemplo n.º 8
0
    # this needed for macros
    request.formatter = formatter

    p = Page(request, pagename)
    formatter.setPage(p)

    output = StringIO.StringIO()

    # wrap sys.stdout as RequestCLI has no interface to say where to output
    stdout = sys.stdout
    sys.stdout = output
    parser.format(formatter)
    sys.stdout = stdout

    return unicode(output.getvalue().decode('utf-8'))


request = ScriptContext()
formatter = Formatter(request)

if __name__ == "__main__":
    # pages/playground\(2f\)SyntaxReference/revisions/00000001
    if len(sys.argv) > 1:
        inputfile = sys.argv[1]
    else:
        inputfile = 'syntaxreference.txt'

    f = open(inputfile, 'r')
    text = f.read()
    print moin2doku('test', text)
Ejemplo n.º 9
0
import sys
import re
import urllib2
from urllib import quote
import xmlrpclib
import csv

from MoinMoin.web.contexts import ScriptContext
from MoinMoin.Page import Page

# monkeypatch the formatter to avoid line_anchors:
from MoinMoin.formatter import text_html
text_html.line_anchors = False

request = ScriptContext(None, None)


class DataNotFoundException(Exception): pass


class Task(object):
    def __init__(self, summary, desc, label, hours, mentors, difficulty, types):
        self.summary = summary
        self.label = label
        self.hours = hours
        self.mentors = mentors
        self.difficulty = difficulty
        self.types = types

        page = Page(request, "")
Ejemplo n.º 10
0
#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 '
Ejemplo n.º 11
0
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!')