annotate MoinMoin/wikidicts.py @ 3688:c19b7a3d7539

Makefile: added fetching UPDATE instructions
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Sun, 08 Jun 2008 21:06:19 +0200
parents 39456a5dc4e8
children 874c4070bd7d
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
3175
2a3a6cb34e45 pylint findings: fix some harmless stuff
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2898
diff changeset
11 from MoinMoin import caching, Page
2437
0b2a95feb672 wikidicts surely doesn't need copy
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2287
diff changeset
12
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
13 # 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
14 # 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
15 DICTS_PICKLE_VERSION = 6
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 749
diff changeset
16
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
17
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
18 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
19 """ 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
20
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
21 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
22 """
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
23 def __init__(self, request=None, pagename=None):
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
24 dict.__init__(self)
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
25 self.name = None
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
26 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
27 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
28
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
29 # 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
30 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
31 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
32 """ 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
33 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
34 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
35
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
36 def loadFromPage(self, request, name):
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
37 """ 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
38 self.name = name
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
39 self.initRegex()
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
40 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
41 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
42
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
43 def initFromText(self, text):
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
44 """ 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
45 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
46
2247
d782b0db4757 wikidicts: more comments, minor cleanup, converted tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
47
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
48 class Dict(DictBase):
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
49 """ 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
50
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
51 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
52
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
53 any text ignored
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
54 key1:: value1
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
55 * ignored, too
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
56 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
57 ...
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
58 keyn:: ....
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
59 any text ignored
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 749
diff changeset
60 """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
61 # 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
62 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
63
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
64 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
65 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
66 key, val = match.groups()
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
67 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
68
475
ad2bc0980876 added some __repr__ to wikidicts to make debugging easier
Thomas Waldmann <tw@waldmann-edv.de>
parents: 472
diff changeset
69 def __repr__(self):
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
70 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
71
2247
d782b0db4757 wikidicts: more comments, minor cleanup, converted tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
72
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
73 class Group(DictBase):
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
74 """ 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
75
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
76 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
77
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
78 any text ignored
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
79 * member1
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
80 * ignored, too
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
81 * member2
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
82 * ....
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
83 * memberN
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
84 any text ignored
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
85
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
86 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
87 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
88 """
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
89 # * 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
90 # 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
91 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
92
2891
7e4627efd98e make wikidicts.Group() keep order for iterator and members() method
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2837
diff changeset
93 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
94 self._list = []
7e4627efd98e make wikidicts.Group() keep order for iterator and members() method
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2837
diff changeset
95 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
96
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
97 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
98 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
99 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
100 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
101
2898
dd2226c7f5fe fix wikidicts by overriding Group.update()
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2891
diff changeset
102 def update(self, members):
dd2226c7f5fe fix wikidicts by overriding Group.update()
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2891
diff changeset
103 self.addmembers(members.keys())
dd2226c7f5fe fix wikidicts by overriding Group.update()
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2891
diff changeset
104
2891
7e4627efd98e make wikidicts.Group() keep order for iterator and members() method
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2837
diff changeset
105 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
106 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
107
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
108 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
109 """ 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
110 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
111
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
112 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
113 """ 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
114 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
115 self.addmember(m)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
116
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
117 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
118 """ add a member to the group """
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
119 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
120 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
121
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
122 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
123 """ 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
124 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
125
475
ad2bc0980876 added some __repr__ to wikidicts to make debugging easier
Thomas Waldmann <tw@waldmann-edv.de>
parents: 472
diff changeset
126 def __repr__(self):
2898
dd2226c7f5fe fix wikidicts by overriding Group.update()
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2891
diff changeset
127 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
128
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
129
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
130 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
131 """ 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
132
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
133 Config:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
134 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
135 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
136 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
137
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
138 def __init__(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
139 self.reset()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
140
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
141 def reset(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
142 self.dictdict = {}
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
143 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
144 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
145 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
146 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
147
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
148 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
149 """ 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
150 d = self.dictdict.get(dictname)
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
151 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
152
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
153 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
154 """ 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
155 try:
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
156 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
157 except KeyError:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
158 return []
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
159 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
160
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
161 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
162 """ 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
163 try:
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
164 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
165 except KeyError:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
166 return []
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
167 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
168
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
169 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
170 """ 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
171 try:
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
172 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
173 except KeyError:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
174 return {}
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
175 return d
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
176
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
177 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
178 """ 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
179 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
180
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
181 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
182 """ 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
183 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
184
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
185 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
186 """ 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
187 dictlist = []
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
188 for d in self.dictdict.values():
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
189 if d.has_key(key):
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
190 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
191 return dictlist
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
192
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
193
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
194 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
195 """ 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
196
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
197 Config:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
198 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
199 Default: ".*Group$"
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
200 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
201
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
202 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
203 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
204 self.request = request
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
205
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
206 def reset(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
207 self.dictdict = {}
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
208 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
209 self.picklever = DICTS_PICKLE_VERSION
3610
39456a5dc4e8 fix failure of detection of on-disk cache updates (this fixes unreliable dicts/groups tests), remove unused Page attribute
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3573
diff changeset
210 self.disk_cache_id = None
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
211
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
212 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
213 """ 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
214 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
215 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
216
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
217 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
218 """ 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
219 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
220 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
221 except KeyError:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
222 return []
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
223 return group.members()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
224
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
225 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
226 """ 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
227 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
228 self.groupdict[groupname] = grp
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
229 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
230
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
231 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
232 """ 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
233 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
234
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
235 def __getitem__(self, name):
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
236 return self.groupdict[name]
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
237
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
238 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
239 """ 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
240 grouplist = []
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
241 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
242 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
243 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
244 return grouplist
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
245
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
246 def expand_groups(self):
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
247 """ copy expanded groups to self.dictdict """
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
248 for name in self.groupdict:
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
249 members, groups = self.expand_group(name)
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
250 members.update(groups)
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
251 grp = Group()
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
252 grp.update(members)
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
253 self.dictdict[name] = grp
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
254
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
255 def expand_group(self, name):
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
256 """ 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
257 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
258 names and group names.
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
259
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
260 Given a groupdict (self) with two groups:
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 MainGroup: [A, SubGroup]
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
263 SubGroup: [B, C]
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
264
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
265 MainGroup is expanded to:
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 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
268 """
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
269 groups = {name: 1}
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
270 members = {}
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
271 groupmembers = self[name].keys()
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
272 for member in groupmembers:
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
273 # Skip duplicates
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
274 if member in groups:
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
275 continue
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
276 # Add member and its children
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
277 if self.hasgroup(member):
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
278 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
279 groups.update(new_groups)
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
280 members.update(new_members)
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
281 else:
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
282 members[member] = 1
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
283 return members, groups
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
284
2254
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
285 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
286 """ load the dict from the cache """
472
faeaf423ef69 fix/speedup scandicts for persistent servers
Thomas Waldmann <tw@waldmann-edv.de>
parents: 400
diff changeset
287 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
288 rescan = False
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
289 arena = 'wikidicts'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
290 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
291 cache = caching.CacheEntry(request, arena, key, scope='wiki', use_pickle=True)
3610
39456a5dc4e8 fix failure of detection of on-disk cache updates (this fixes unreliable dicts/groups tests), remove unused Page attribute
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3573
diff changeset
292 current_disk_cache_id = cache.uid()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
293 try:
1550
a4f0632414da using request.cfg.cache more
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1549
diff changeset
294 self.__dict__.update(self.cfg.cache.DICTS_DATA)
3610
39456a5dc4e8 fix failure of detection of on-disk cache updates (this fixes unreliable dicts/groups tests), remove unused Page attribute
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3573
diff changeset
295 if (current_disk_cache_id is None or
39456a5dc4e8 fix failure of detection of on-disk cache updates (this fixes unreliable dicts/groups tests), remove unused Page attribute
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3573
diff changeset
296 current_disk_cache_id != self.disk_cache_id):
2254
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
297 self.reset()
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
298 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
299 else:
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
300 return
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
301 except AttributeError:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
302 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
303 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
304 self.__dict__.update(data)
3610
39456a5dc4e8 fix failure of detection of on-disk cache updates (this fixes unreliable dicts/groups tests), remove unused Page attribute
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3573
diff changeset
305 self.disk_cache_id = current_disk_cache_id
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 749
diff changeset
306
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
307 # 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
308 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
309 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
310 except:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
311 self.reset()
2254
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
312 rescan = True
472
faeaf423ef69 fix/speedup scandicts for persistent servers
Thomas Waldmann <tw@waldmann-edv.de>
parents: 400
diff changeset
313
2254
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
314 if rescan:
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
315 self.scan_dicts()
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
316 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
317 return
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
318
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
319 data = {
3610
39456a5dc4e8 fix failure of detection of on-disk cache updates (this fixes unreliable dicts/groups tests), remove unused Page attribute
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3573
diff changeset
320 "disk_cache_id": self.disk_cache_id,
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
321 "dictdict": self.dictdict,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
322 "groupdict": self.groupdict,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
323 "picklever": self.picklever
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
324 }
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 749
diff changeset
325
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
326 # remember it (persistent environments)
1550
a4f0632414da using request.cfg.cache more
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1549
diff changeset
327 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
328
2254
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
329 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
330 """ 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
331 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
332 """
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
333 request = self.request
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
334 self.reset()
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
335
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
336 # 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
337 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
338
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
339 # 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
340 # function - this makes the page list about 10 times faster.
3573
124d0ef138aa change page_*_regex processing, see docs/CHANGES (fixes Xapian category search for non-english)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3175
diff changeset
341 isdict = self.cfg.cache.page_dict_regexact.search
2254
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
342 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
343 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
344 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
345
3573
124d0ef138aa change page_*_regex processing, see docs/CHANGES (fixes Xapian category search for non-english)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3175
diff changeset
346 isgroup = self.cfg.cache.page_group_regexact.search
2254
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
347 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
348 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
349 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
350
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
351 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
352 self.expand_groups()
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
353
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
354 arena = 'wikidicts'
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
355 key = 'dicts_groups'
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
356 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
357 data = {
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
358 "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
359 "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
360 "dictdict": self.dictdict,
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
361 "groupdict": self.groupdict,
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
362 "picklever": self.picklever
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
363 }
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
364 cache.update(data)
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
365 # XXX release cache write lock here