コード例 #1
0
ファイル: wikisync.py プロジェクト: steveyen/moingo
 def get_pages(self, **kwargs):
     options = {"include_revno": True,
                "include_deleted": True,
                "exclude_non_writable": kwargs["exclude_non_writable"],
                "include_underlay": False,
                "prefix": self.prefix,
                "pagelist": self.pagelist,
                "mark_deleted": True}
     if self.token:
         m = MultiCall(self.connection)
         m.applyAuthToken(self.token)
         m.getAllPagesEx(options)
         tokres, pages = m()
     else:
         pages = self.connection.getAllPagesEx(options)
     rpages = []
     for name, revno in pages:
         normalised_name = normalise_pagename(name, self.prefix)
         if normalised_name is None:
             continue
         if abs(revno) != 99999999: # I love sane in-band signalling
             remote_rev = abs(revno)
             remote_deleted = revno < 0
             rpages.append(SyncPage(normalised_name, remote_rev=remote_rev, remote_name=name, remote_deleted=remote_deleted))
     return rpages
コード例 #2
0
ファイル: write.py プロジェクト: steveyen/moingo
    def mainloop(self):
        # grab parameters
        url = self.argv[0] + '?action=xmlrpc2'
        user = self.argv[1]
        passwd = self.argv[2]
        pagename = self.argv[3]

        # get auth token from server giving username/password
        s = xmlrpclib.ServerProxy(url)
        token = s.getAuthToken(user, passwd)

        if not token:
            print 'Invalid username/password'
            return

        # Verify that the token is valid by using it
        # and checking that the result is 'SUCCESS'.
        # The token should be valid for 15 minutes.
        assert s.applyAuthToken(token) == 'SUCCESS'

        try:
            # read new page contents
            content = sys.stdin.read()

            # build a multicall object that
            mcall = MultiCall(s)
            # first applies the token and
            mcall.applyAuthToken(token)
            # then edits the page
            mcall.putPage(pagename, content)

            # now execute the multicall
            results = mcall()

            # everything should have worked
            # instead of the asserts you can have anything else
            # but you should definitely access all the results
            # once so that faults are checked and raised
            assert results[0] == 'SUCCESS'
            assert results[1] is True

        finally:
            # be nice to the server and clean up the token
            # regardless of what happened
            assert s.deleteAuthToken(token) == 'SUCCESS'
コード例 #3
0
ファイル: UpdateGroupTest.py プロジェクト: steveyen/moingo
def updateGroup(server_url, username, password, groupname, groupdesc, groupmembers, acl=''):
    """
    Update a Wiki Group Page named <groupname> with a list of <groupmembers> via xmlrpc.
    Contact the target wiki xmlrpc service at <server_url> and use <username>
    and <password> to authenticate as wiki user there.

    @param server_url: xmlrpc service url of target wiki (str)
    @param username: username used to authenticate at server_url wiki (unicode)
    @param password: password of <username> (unicode)
    @param groupname: group page name (unicode)
    @param groupdesc: group description (unicode)
    @param groupmembers: group member names (list of unicode)
    @param acl: Access Control List value (optional, unicode)
    """
    wiki = xmlrpclib.ServerProxy(server_url)
    auth_token = wiki.getAuthToken(username, password)
    assert auth_token, 'Invalid username/password'

    # Verify that the token is valid by using it
    # and checking that the result is 'SUCCESS'.
    # The token should be valid for 15 minutes.
    assert wiki.applyAuthToken(auth_token) == 'SUCCESS'

    try:
        # build a multicall object that
        mcall = MultiCall(wiki)
        # first applies the token and
        mcall.applyAuthToken(auth_token)
        # then creates/updates the group page
        mcall.UpdateGroup(groupname, groupdesc, groupmembers, acl)
        # now execute the multicall
        results = mcall()

        # everything should have worked
        # instead of the asserts you can have anything else
        # but you should definitely access all the results
        # once so that faults are checked and raised
        assert results[0] == 'SUCCESS'
        # TODO: process other results / xmlrpc faults
    finally:
        # be nice to the server and clean up the token
        # regardless of what happened
        assert wiki.deleteAuthToken(auth_token) == 'SUCCESS'