def mainloop(self):
        argc = len(self.args)

        self.init_request()
        request = self.request

        if self.options.py_append_file:
            def logs(request):
                """ generator for log objects """
                # global edit-log
                yield editlog.EditLog(request)
                # local edit-log of every page
                for pn in request.rootpage.getPageList(exists=False):
                    yield editlog.EditLog(request, rootpagename=pn)

            def uids(log):
                """ generator for userids found in a log """
                for line in log:
                    uid = line.userid
                    if uid:
                        yield uid

            fn = self.options.py_append_file
            editlog_uids = set()
            for log in logs(request):
                editlog_uids |= set(uids(log))
            with open(fn, "a") as f:
                for uid in editlog_uids:
                    u = User(request, uid)
                    code = u'editlog_uids.add(%r)  # %r %r %r\n' % (
                               uid, u.name, u.email, u.jid)
                    f.write(code.encode('utf-8'))

        elif self.options.py_exec_file:
            def check_interactive(u):
                if self.options.interactive:
                    prompt = "%s %r %r %r disabled=%r (y/N)? " % (u.id, u.name, u.email, u.jid, u.disabled)
                    return raw_input(prompt).strip() in ['y', 'Y', ]
                else:
                    return True

            fn = self.options.py_exec_file
            locs = dict(editlog_uids=set())
            execfile(fn, {}, locs)
            editlog_uids = locs.get('editlog_uids')

            profile_uids = set(getUserList(request))

            inactive_uids = profile_uids - editlog_uids
            for uid in inactive_uids:
                u = User(request, uid)
                if self.options.show:
                    print "%s\t%r\t%r\t%r" % (uid, u.name, u.email, u.disabled)
                if self.options.disable:
                    if check_interactive(u):
                        u.disabled = 1
                        u.save()
                elif self.options.remove:
                    if check_interactive(u):
                        u.remove()
Exemplo n.º 2
0
    def mainloop(self):
        argc = len(self.args)

        self.init_request()
        request = self.request

        if self.options.py_append_file:

            def logs(request):
                """ generator for log objects """
                # global edit-log
                yield editlog.EditLog(request)
                # local edit-log of every page
                for pn in request.rootpage.getPageList(exists=False):
                    yield editlog.EditLog(request, rootpagename=pn)

            def uids(log):
                """ generator for userids found in a log """
                for line in log:
                    uid = line.userid
                    if uid:
                        yield uid

            fn = self.options.py_append_file
            editlog_uids = set()
            for log in logs(request):
                editlog_uids |= set(uids(log))
            with open(fn, "a") as f:
                for uid in editlog_uids:
                    u = User(request, uid)
                    code = u'editlog_uids.add(%r)  # %r %r %r\n' % (
                        uid, u.name, u.email, u.jid)
                    f.write(code.encode('utf-8'))

        elif self.options.py_exec_file:

            def check_interactive(u):
                if self.options.interactive:
                    prompt = "%s %r %r %r disabled=%r (y/N)? " % (
                        u.id, u.name, u.email, u.jid, u.disabled)
                    return raw_input(prompt).strip() in [
                        'y',
                        'Y',
                    ]
                else:
                    return True

            fn = self.options.py_exec_file
            locs = dict(editlog_uids=set())
            execfile(fn, {}, locs)
            editlog_uids = locs.get('editlog_uids')

            profile_uids = set(getUserList(request))

            inactive_uids = profile_uids - editlog_uids
            for uid in inactive_uids:
                u = User(request, uid)
                if self.options.show:
                    print "%s\t%r\t%r\t%r" % (uid, u.name, u.email, u.disabled)
                if self.options.disable:
                    if check_interactive(u):
                        u.disabled = 1
                        u.save()
                elif self.options.remove:
                    if check_interactive(u):
                        u.remove()