annotate MoinMoin/wikidicts.py @ 3077:66d35649ca99

add 'percent' kw to getText (must be True when using result as left side of % operator), refactored some code, better comments (ported from 1.6)
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Fri, 22 Feb 2008 22:35:46 +0100
parents dd2226c7f5fe
children 2a3a6cb34e45
rev   line source
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
2 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
3 MoinMoin - Dictionary / Group Functions
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
4
2247
d782b0db4757 wikidicts: more comments, minor cleanup, converted tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
5 @copyright: 2003-2007 MoinMoin:ThomasWaldmann,
d782b0db4757 wikidicts: more comments, minor cleanup, converted tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
6 2003 by Gustavo Niemeyer
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
7 @license: GNU GPL, see COPYING for details.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
8 """
1791
6dd2e29acffe Eclipse PyDev Check: fixed lots of its errors and warnings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1638
diff changeset
9 import re, time
381
f0ecf4656a58 include a fixed copy.py, taken from Python 2.4.2
Thomas Waldmann <tw@waldmann-edv.de>
parents: 336
diff changeset
10
1791
6dd2e29acffe Eclipse PyDev Check: fixed lots of its errors and warnings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1638
diff changeset
11 from MoinMoin import caching, wikiutil, Page, logfile
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
12 from MoinMoin.logfile.editlog import EditLog
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
13
2437
0b2a95feb672 wikidicts surely doesn't need copy
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2287
diff changeset
14
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
15 # Version of the internal data structure which is pickled.
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
16 # Please increment if you have changed the structure.
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
17 DICTS_PICKLE_VERSION = 6
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 749
diff changeset
18
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
19
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
20 class DictBase(dict):
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
21 """ Base class for wiki dicts
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
22
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
23 To use this class, subclass it and override regex and initFromText.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
24 """
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
25 def __init__(self, request=None, pagename=None):
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
26 dict.__init__(self)
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
27 self.name = None
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
28 if request is not None and pagename is not None:
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
29 self.loadFromPage(request, pagename)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
30
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
31 # Regular expression used to parse text - subclass should override this
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
32 regex = ''
1044
0f7f98a19685 Fixed sre unpickle issues seen on some machines by avoiding to pickle the regex.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 974
diff changeset
33 def initRegex(cls):
0f7f98a19685 Fixed sre unpickle issues seen on some machines by avoiding to pickle the regex.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 974
diff changeset
34 """ Make it a class attribute to avoid it being pickled. """
0f7f98a19685 Fixed sre unpickle issues seen on some machines by avoiding to pickle the regex.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 974
diff changeset
35 cls.regex = re.compile(cls.regex, re.MULTILINE | re.UNICODE)
0f7f98a19685 Fixed sre unpickle issues seen on some machines by avoiding to pickle the regex.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 974
diff changeset
36 initRegex = classmethod(initRegex)
0f7f98a19685 Fixed sre unpickle issues seen on some machines by avoiding to pickle the regex.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 974
diff changeset
37
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
38 def loadFromPage(self, request, name):
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
39 """ load the dict from wiki page <name>'s content """
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
40 self.name = name
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
41 self.initRegex()
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
42 text = Page.Page(request, name).get_raw_body()
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
43 self.initFromText(text)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
44
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
45 def initFromText(self, text):
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
46 """ parse the wiki page text and init the dict from it """
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
47 raise NotImplementedError('subclasses should override this')
475
ad2bc0980876 added some __repr__ to wikidicts to make debugging easier
Thomas Waldmann <tw@waldmann-edv.de>
parents: 472
diff changeset
48
2247
d782b0db4757 wikidicts: more comments, minor cleanup, converted tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
49
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
50 class Dict(DictBase):
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
51 """ Mapping of keys to values in a wiki page.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
52
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
53 How a Dict definition page should look like:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
54
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
55 any text ignored
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
56 key1:: value1
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
57 * ignored, too
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
58 key2:: value2 containing spaces
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
59 ...
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
60 keyn:: ....
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
61 any text ignored
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 749
diff changeset
62 """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
63 # Key:: Value - ignore all but key:: value pairs, strip whitespace
2287
0005f996ff92 wikidicts: add comment about (empty) dict entry syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2286
diff changeset
64 regex = r'^ (?P<key>.+?):: (?P<val>.*?) *$' # exactly one space after the :: is required
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
65
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
66 def initFromText(self, text):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
67 for match in self.regex.finditer(text):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
68 key, val = match.groups()
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
69 self[key] = val
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
70
475
ad2bc0980876 added some __repr__ to wikidicts to make debugging easier
Thomas Waldmann <tw@waldmann-edv.de>
parents: 472
diff changeset
71 def __repr__(self):
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
72 return "<Dict name=%r items=%r>" % (self.name, self.items())
475
ad2bc0980876 added some __repr__ to wikidicts to make debugging easier
Thomas Waldmann <tw@waldmann-edv.de>
parents: 472
diff changeset
73
2247
d782b0db4757 wikidicts: more comments, minor cleanup, converted tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
74
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
75 class Group(DictBase):
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
76 """ Group of users, of pages, of whatever.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
77
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
78 How a Group definition page should look like:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
79
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
80 any text ignored
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
81 * member1
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
82 * ignored, too
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
83 * member2
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
84 * ....
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
85 * memberN
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
86 any text ignored
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
87
2766
44ebe3cdd515 fix group entries that use free links for new link syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2437
diff changeset
88 If there are any free links using [[free link]] notation, the markup
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
89 is stripped from the member.
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 749
diff changeset
90 """
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
91 # * Member - ignore all but first level list items, strip whitespace,
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
92 # strip free links markup if exists.
2766
44ebe3cdd515 fix group entries that use free links for new link syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2437
diff changeset
93 regex = r'^ \* +(?:\[\[)?(?P<member>.+?)(?:\]\])? *$'
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
94
2891
7e4627efd98e make wikidicts.Group() keep order for iterator and members() method
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2837
diff changeset
95 def __init__(self, request=None, pagename=None):
7e4627efd98e make wikidicts.Group() keep order for iterator and members() method
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2837
diff changeset
96 self._list = []
7e4627efd98e make wikidicts.Group() keep order for iterator and members() method
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2837
diff changeset
97 DictBase.__init__(self, request, pagename)
7e4627efd98e make wikidicts.Group() keep order for iterator and members() method
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2837
diff changeset
98
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
99 def initFromText(self, text):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
100 for match in self.regex.finditer(text):
2247
d782b0db4757 wikidicts: more comments, minor cleanup, converted tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
101 member = match.group('member')
d782b0db4757 wikidicts: more comments, minor cleanup, converted tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
102 self.addmember(member)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
103
2898
dd2226c7f5fe fix wikidicts by overriding Group.update()
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2891
diff changeset
104 def update(self, members):
dd2226c7f5fe fix wikidicts by overriding Group.update()
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2891
diff changeset
105 self.addmembers(members.keys())
dd2226c7f5fe fix wikidicts by overriding Group.update()
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2891
diff changeset
106
2891
7e4627efd98e make wikidicts.Group() keep order for iterator and members() method
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2837
diff changeset
107 def __iter__(self):
7e4627efd98e make wikidicts.Group() keep order for iterator and members() method
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2837
diff changeset
108 return iter(self._list)
7e4627efd98e make wikidicts.Group() keep order for iterator and members() method
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2837
diff changeset
109
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
110 def members(self):
2247
d782b0db4757 wikidicts: more comments, minor cleanup, converted tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
111 """ return the group's members """
2891
7e4627efd98e make wikidicts.Group() keep order for iterator and members() method
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2837
diff changeset
112 return self._list[:]
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
113
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
114 def addmembers(self, members):
2247
d782b0db4757 wikidicts: more comments, minor cleanup, converted tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
115 """ add a list of members to the group """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
116 for m in members:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
117 self.addmember(m)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
118
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
119 def addmember(self, member):
2247
d782b0db4757 wikidicts: more comments, minor cleanup, converted tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
120 """ add a member to the group """
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
121 self[member] = 1
2891
7e4627efd98e make wikidicts.Group() keep order for iterator and members() method
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2837
diff changeset
122 self._list.append(member)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
123
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
124 def has_member(self, member):
2247
d782b0db4757 wikidicts: more comments, minor cleanup, converted tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
125 """ check if the group has member <member> """
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
126 return self.has_key(member)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
127
475
ad2bc0980876 added some __repr__ to wikidicts to make debugging easier
Thomas Waldmann <tw@waldmann-edv.de>
parents: 472
diff changeset
128 def __repr__(self):
2898
dd2226c7f5fe fix wikidicts by overriding Group.update()
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2891
diff changeset
129 return "<Group name=%r items=%r>" % (self.name, self._list)
475
ad2bc0980876 added some __repr__ to wikidicts to make debugging easier
Thomas Waldmann <tw@waldmann-edv.de>
parents: 472
diff changeset
130
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
131
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
132 class DictDict:
2247
d782b0db4757 wikidicts: more comments, minor cleanup, converted tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
133 """ a dictionary of Dict objects
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
134
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
135 Config:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
136 cfg.page_dict_regex
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
137 Default: ".*Dict$" Defs$ Vars$ ???????????????????
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
138 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
139
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
140 def __init__(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
141 self.reset()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
142
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
143 def reset(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
144 self.dictdict = {}
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
145 self.namespace_timestamp = 0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
146 self.pageupdate_timestamp = 0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
147 self.base_timestamp = 0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
148 self.picklever = DICTS_PICKLE_VERSION
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
149
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
150 def has_key(self, dictname, key):
2247
d782b0db4757 wikidicts: more comments, minor cleanup, converted tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
151 """ check if we have key <key> in dict <dictname> """
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
152 d = self.dictdict.get(dictname)
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
153 return d and d.has_key(key)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
154
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
155 def keys(self, dictname):
2247
d782b0db4757 wikidicts: more comments, minor cleanup, converted tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
156 """ get keys of dict <dictname> """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
157 try:
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
158 d = self.dictdict[dictname]
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
159 except KeyError:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
160 return []
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
161 return d.keys()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
162
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
163 def values(self, dictname):
2247
d782b0db4757 wikidicts: more comments, minor cleanup, converted tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
164 """ get values of dict <dictname> """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
165 try:
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
166 d = self.dictdict[dictname]
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
167 except KeyError:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
168 return []
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
169 return d.values()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
170
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
171 def dict(self, dictname):
2247
d782b0db4757 wikidicts: more comments, minor cleanup, converted tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
172 """ get dict <dictname> """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
173 try:
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
174 d = self.dictdict[dictname]
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
175 except KeyError:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
176 return {}
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
177 return d
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
178
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
179 def adddict(self, request, dictname):
2247
d782b0db4757 wikidicts: more comments, minor cleanup, converted tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
180 """ add a new dict (will be read from the wiki page) """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
181 self.dictdict[dictname] = Dict(request, dictname)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
182
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
183 def has_dict(self, dictname):
2247
d782b0db4757 wikidicts: more comments, minor cleanup, converted tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
184 """ check if we have a dict <dictname> """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
185 return self.dictdict.has_key(dictname)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
186
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
187 def keydict(self, key):
2247
d782b0db4757 wikidicts: more comments, minor cleanup, converted tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
188 """ list all dicts that contain key """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
189 dictlist = []
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
190 for d in self.dictdict.values():
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
191 if d.has_key(key):
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
192 dictlist.append(d.name)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
193 return dictlist
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
194
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
195
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
196 class GroupDict(DictDict):
2247
d782b0db4757 wikidicts: more comments, minor cleanup, converted tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
197 """ a dictionary of Group objects
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
198
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
199 Config:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
200 cfg.page_group_regex
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
201 Default: ".*Group$"
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
202 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
203
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
204 def __init__(self, request):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
205 self.cfg = request.cfg
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
206 self.request = request
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
207
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
208 def reset(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
209 self.dictdict = {}
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
210 self.groupdict = {} # unexpanded groups
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
211 self.picklever = DICTS_PICKLE_VERSION
2254
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
212 self.disk_cache_mtime = 0
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
213
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
214 def has_member(self, groupname, member):
2247
d782b0db4757 wikidicts: more comments, minor cleanup, converted tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
215 """ check if we have <member> as a member of group <groupname> """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
216 group = self.dictdict.get(groupname)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
217 return group and group.has_member(member)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
218
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
219 def members(self, groupname):
2247
d782b0db4757 wikidicts: more comments, minor cleanup, converted tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
220 """ get members of group <groupname> """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
221 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
222 group = self.dictdict[groupname]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
223 except KeyError:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
224 return []
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
225 return group.members()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
226
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
227 def addgroup(self, request, groupname):
2247
d782b0db4757 wikidicts: more comments, minor cleanup, converted tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
228 """ add a new group (will be read from the wiki page) """
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 749
diff changeset
229 grp = Group(request, groupname)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
230 self.groupdict[groupname] = grp
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
231 self.expand_groups()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
232
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
233 def hasgroup(self, groupname):
2247
d782b0db4757 wikidicts: more comments, minor cleanup, converted tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
234 """ check if we have a dict <dictname> """
1396
95f907618c53 fixes wikidicts crash triggered by a page 'WikiDict' being member of 'SystemPages*Group'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1044
diff changeset
235 return self.groupdict.has_key(groupname)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
236
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
237 def __getitem__(self, name):
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
238 return self.groupdict[name]
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
239
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
240 def membergroups(self, member):
2247
d782b0db4757 wikidicts: more comments, minor cleanup, converted tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
241 """ list all groups where member is a member of """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
242 grouplist = []
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
243 for group in self.dictdict.values():
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
244 if group.has_member(member):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
245 grouplist.append(group.name)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
246 return grouplist
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
247
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
248 def expand_groups(self):
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
249 """ copy expanded groups to self.dictdict """
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
250 for name in self.groupdict:
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
251 members, groups = self.expand_group(name)
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
252 members.update(groups)
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
253 grp = Group()
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
254 grp.update(members)
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
255 self.dictdict[name] = grp
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
256
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
257 def expand_group(self, name):
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
258 """ Recursively expand group <name>, using the groupdict (which is a not expanded
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
259 dict of all group names -> group dicts). We return a flat list of group member
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
260 names and group names.
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
261
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
262 Given a groupdict (self) with two groups:
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
263
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
264 MainGroup: [A, SubGroup]
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
265 SubGroup: [B, C]
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
266
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
267 MainGroup is expanded to:
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
268
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
269 self.expand_group('MainGroup') -> [A, B, C], [MainGroup, SubGroup]
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
270 """
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
271 groups = {name: 1}
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
272 members = {}
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
273 groupmembers = self[name].keys()
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
274 for member in groupmembers:
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
275 # Skip duplicates
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
276 if member in groups:
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
277 continue
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
278 # Add member and its children
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
279 if self.hasgroup(member):
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
280 new_members, new_groups = self.expand_group(member)
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
281 groups.update(new_groups)
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
282 members.update(new_members)
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
283 else:
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
284 members[member] = 1
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
285 return members, groups
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
286
2254
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
287 def load_dicts(self):
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
288 """ load the dict from the cache """
472
faeaf423ef69 fix/speedup scandicts for persistent servers
Thomas Waldmann <tw@waldmann-edv.de>
parents: 400
diff changeset
289 request = self.request
2254
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
290 rescan = False
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
291 arena = 'wikidicts'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
292 key = 'dicts_groups'
2254
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
293 cache = caching.CacheEntry(request, arena, key, scope='wiki', use_pickle=True)
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
294 current_disk_cache_mtime = cache.mtime()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
295 try:
1550
a4f0632414da using request.cfg.cache more
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1549
diff changeset
296 self.__dict__.update(self.cfg.cache.DICTS_DATA)
2254
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
297 if current_disk_cache_mtime > self.disk_cache_mtime:
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
298 self.reset()
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
299 raise AttributeError # not fresh, force load from disk
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
300 else:
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
301 return
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
302 except AttributeError:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
303 try:
1638
5070d0358544 caching: move use_pickle to __init__, remove unused encode/decode args from .content()/.update()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1637
diff changeset
304 data = cache.content()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
305 self.__dict__.update(data)
2254
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
306 self.disk_cache_mtime = current_disk_cache_mtime
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 749
diff changeset
307
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
308 # invalidate the cache if the pickle version changed
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
309 if self.picklever != DICTS_PICKLE_VERSION:
2254
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
310 raise # force rescan
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
311 except:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
312 self.reset()
2254
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
313 rescan = True
472
faeaf423ef69 fix/speedup scandicts for persistent servers
Thomas Waldmann <tw@waldmann-edv.de>
parents: 400
diff changeset
314
2254
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
315 if rescan:
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
316 self.scan_dicts()
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
317 self.load_dicts() # try again
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
318 return
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
319
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
320 data = {
2254
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
321 "disk_cache_mtime": self.disk_cache_mtime,
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
322 "dictdict": self.dictdict,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
323 "groupdict": self.groupdict,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
324 "picklever": self.picklever
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
325 }
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 749
diff changeset
326
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
327 # remember it (persistent environments)
1550
a4f0632414da using request.cfg.cache more
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1549
diff changeset
328 self.cfg.cache.DICTS_DATA = data
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
329
2254
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
330 def scan_dicts(self):
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
331 """ scan all pages matching the dict / group regex and
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
332 cache the results on disk
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
333 """
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
334 request = self.request
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
335 self.reset()
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
336
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
337 # XXX get cache write lock here
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
338 scan_begin_time = time.time()
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
339
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
340 # Get all pages in the wiki - without user filtering using filter
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
341 # function - this makes the page list about 10 times faster.
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
342 isdict = self.cfg.cache.page_dict_regex.search
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
343 dictpages = request.rootpage.getPageList(user='', filter=isdict)
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
344 for pagename in dictpages:
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
345 self.adddict(request, pagename)
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
346
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
347 isgroup = self.cfg.cache.page_group_regex.search
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
348 grouppages = request.rootpage.getPageList(user='', filter=isgroup)
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
349 for pagename in grouppages:
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
350 self.addgroup(request, pagename)
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
351
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
352 scan_end_time = time.time()
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
353 self.expand_groups()
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
354
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
355 arena = 'wikidicts'
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
356 key = 'dicts_groups'
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
357 cache = caching.CacheEntry(request, arena, key, scope='wiki', use_pickle=True)
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
358 data = {
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
359 "scan_begin_time": scan_begin_time,
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
360 "scan_end_time": scan_end_time,
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
361 "dictdict": self.dictdict,
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
362 "groupdict": self.groupdict,
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
363 "picklever": self.picklever
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
364 }
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
365 cache.update(data)
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
366 # XXX release cache write lock here