view data/plugin/script/account/ @ 654:8c828d7b6cd4 tip

PDFList: check for pyPdf.utils.PdfReadError
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Wed, 07 Dec 2016 14:27:25 +0100
parents 127da830be6c
line wrap: on
line source
# -*- coding: iso-8859-1 -*-
MoinMoin - subscribes or unsubscribes users to a page

@copyright: 2011-2016 MoinMoin:ReimarBauer
@license: GNU GPL, see COPYING for details.

from MoinMoin import user
from MoinMoin.Page import Page
from MoinMoin.script import MoinScript

class PluginScript(MoinScript):
This tool allows you to subscribe or unsubscribe users of a wiki to a page

Detailed Instructions:
General syntax: moin [options] account subscribe [subscribe-options]

[options] usually should be:
    --config-dir=/path/to/my/cfg/ --wiki-url=

1. Required is one of the options --name, ---group, --all-users.
To subscribe a user to a page use the --name argument. For subscribe by a group of users
give the --group page argument. Or with --all-users you subscribe ALL users.
2. Required is also the pagename of the page to subscribe too
3. Optional the selected users could be unsubscribed by --unsubscribe

    def __init__(self, argv, def_values):
        MoinScript.__init__(self, argv, def_values)

            "-u", "--user", dest="priviledged_user",
            help="User as whom the homepage creation operation will be performed as."

            "-n", "--name", dest="user_subscribe",
            help="The name of the user to subscribe to a page."

            "-g", "--group", dest="name_of_group_page",
            help="The name of the group page to select users to subscribe to a page"

            "-a", "--all-users", dest="all_users", action="store_true",
            help="All existing users of the wiki to subscribe to a page"

            "-r", "--unsubscribe", dest="unsubscribe", action="store_true",
            help="unsubscribe users of a wiki page"

            "-p", "--pagename", dest="pagename",
            help="The name of the page to subscribe"

    def write_subscription(self, account, pagename, unsubscribe=False):
        # subscribes to a page
        if account.exists() and not account.disabled and Page(self.request, pagename).exists():
            if unsubscribe:

    def mainloop(self):
        # we don't expect non-option arguments
        request = self.request
        # Check for user
        if self.options.priviledged_user:
            uid = user.getUserId(request, self.options.priviledged_user)
            request.user = user.User(request, uid)
        # Check for Group definition
        members = []
        if self.options.user_subscribe:
            members = [self.options.user_subscribe, ]
        elif self.options.name_of_group_page:
            members = request.groups.get(self.options.name_of_group_page, [])
        elif self.options.all_users:
            uids = user.getUserList(request)
            members = [user.User(request, uid).name for uid in uids]

        if not members:
            print "No user selected!"
        if not self.options.pagename:
            print "No pagename given!"

        # loop through members for doing the subscription
        for name in members:
            uid = user.getUserId(request, name)
            account = user.User(request, uid)
            self.write_subscription(account, self.options.pagename, unsubscribe=self.options.unsubscribe)