annotate MoinMoin/wikidicts.py @ 4468:fad2936d33a7 1.8.1

added dummy mig script for 1.8.1, bumped version number
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Wed, 24 Dec 2008 16:32:46 +0100
parents fef3c5039997
children 3f9147c23d9c 7a826f946da3
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
3729
fef3c5039997 wikidicts: simplify regex compiling
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3725
diff changeset
29 # Regular expression used to parse text - subclass must override this
fef3c5039997 wikidicts: simplify regex compiling
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3725
diff changeset
30 regex = None # re.compile(u'...', re.MULTILINE | re.UNICODE)
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
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
32 def loadFromPage(self, request, name):
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
33 """ 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
34 self.name = name
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
35 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
36 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
37
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
38 def initFromText(self, text):
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
39 """ 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
40 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
41
2247
d782b0db4757 wikidicts: more comments, minor cleanup, converted tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
42
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
43 class Dict(DictBase):
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
44 """ 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
45
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
46 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
47
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
48 any text ignored
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
49 key1:: value1
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
50 * ignored, too
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
51 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
52 ...
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
53 keyn:: ....
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
54 any text ignored
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 749
diff changeset
55 """
3729
fef3c5039997 wikidicts: simplify regex compiling
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3725
diff changeset
56 # Key:: Value - ignore all but key:: value pairs, strip whitespace, exactly one space after the :: is required
fef3c5039997 wikidicts: simplify regex compiling
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3725
diff changeset
57 regex = re.compile(ur'^ (?P<key>.+?):: (?P<val>.*?) *$', re.MULTILINE | re.UNICODE)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
58
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
59 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
60 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
61 key, val = match.groups()
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
62 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
63
475
ad2bc0980876 added some __repr__ to wikidicts to make debugging easier
Thomas Waldmann <tw@waldmann-edv.de>
parents: 472
diff changeset
64 def __repr__(self):
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
65 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
66
2247
d782b0db4757 wikidicts: more comments, minor cleanup, converted tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
67
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
68 class Group(DictBase):
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
69 """ 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
70
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
71 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
72
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
73 any text ignored
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
74 * member1
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
75 * ignored, too
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
76 * member2
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 * memberN
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
79 any text ignored
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
80
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
81 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
82 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
83 """
3729
fef3c5039997 wikidicts: simplify regex compiling
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3725
diff changeset
84 # * Member - ignore all but first level list items, strip whitespace, strip free links markup
fef3c5039997 wikidicts: simplify regex compiling
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3725
diff changeset
85 regex = re.compile(ur'^ \* +(?:\[\[)?(?P<member>.+?)(?:\]\])? *$', re.MULTILINE | re.UNICODE)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
86
2891
7e4627efd98e make wikidicts.Group() keep order for iterator and members() method
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2837
diff changeset
87 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
88 self._list = []
7e4627efd98e make wikidicts.Group() keep order for iterator and members() method
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2837
diff changeset
89 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
90
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
91 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
92 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
93 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
94 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
95
2898
dd2226c7f5fe fix wikidicts by overriding Group.update()
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2891
diff changeset
96 def update(self, members):
dd2226c7f5fe fix wikidicts by overriding Group.update()
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2891
diff changeset
97 self.addmembers(members.keys())
dd2226c7f5fe fix wikidicts by overriding Group.update()
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2891
diff changeset
98
2891
7e4627efd98e make wikidicts.Group() keep order for iterator and members() method
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2837
diff changeset
99 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
100 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
101
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
102 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
103 """ 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
104 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
105
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
106 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
107 """ 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
108 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
109 self.addmember(m)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
110
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
111 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
112 """ add a member to the group """
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
113 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
114 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
115
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
116 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
117 """ 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
118 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
119
475
ad2bc0980876 added some __repr__ to wikidicts to make debugging easier
Thomas Waldmann <tw@waldmann-edv.de>
parents: 472
diff changeset
120 def __repr__(self):
2898
dd2226c7f5fe fix wikidicts by overriding Group.update()
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2891
diff changeset
121 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
122
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 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
125 """ 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
126
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
127 Config:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
128 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
129 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
130 """
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 def __init__(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
133 self.reset()
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 def reset(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
136 self.dictdict = {}
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
137 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
138 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
139 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
140 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
141
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
142 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
143 """ 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
144 d = self.dictdict.get(dictname)
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
145 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
146
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
147 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
148 """ 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
149 try:
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
150 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
151 except KeyError:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
152 return []
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
153 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
154
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
155 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
156 """ 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
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.values()
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 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
164 """ 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
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
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 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
172 """ 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
173 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
174
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
175 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
176 """ 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
177 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
178
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
179 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
180 """ 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
181 dictlist = []
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
182 for d in self.dictdict.values():
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
183 if d.has_key(key):
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
184 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
185 return dictlist
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
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
188 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
189 """ 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
190
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
191 Config:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
192 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
193 Default: ".*Group$"
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 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
197 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
198 self.request = request
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
199
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
200 def reset(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
201 self.dictdict = {}
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
202 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
203 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
204 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
205
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
206 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
207 """ 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
208 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
209 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
210
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
211 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
212 """ 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
213 try:
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[groupname]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
215 except KeyError:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
216 return []
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
217 return group.members()
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 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
220 """ 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
221 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
222 self.groupdict[groupname] = grp
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
223 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
224
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
225 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
226 """ 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
227 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
228
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
229 def __getitem__(self, name):
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
230 return self.groupdict[name]
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
231
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
232 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
233 """ 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
234 grouplist = []
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
235 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
236 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
237 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
238 return grouplist
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
239
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
240 def expand_groups(self):
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
241 """ copy expanded groups to self.dictdict """
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
242 for name in self.groupdict:
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
243 members, groups = self.expand_group(name)
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
244 members.update(groups)
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
245 grp = Group()
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
246 grp.update(members)
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
247 self.dictdict[name] = grp
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
248
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
249 def expand_group(self, name):
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
250 """ 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
251 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
252 names and group names.
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
253
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
254 Given a groupdict (self) with two groups:
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
255
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
256 MainGroup: [A, SubGroup]
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
257 SubGroup: [B, C]
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
258
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
259 MainGroup is expanded to:
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
260
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
261 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
262 """
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
263 groups = {name: 1}
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
264 members = {}
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
265 groupmembers = self[name].keys()
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
266 for member in groupmembers:
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
267 # Skip duplicates
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
268 if member in groups:
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
269 continue
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
270 # Add member and its children
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
271 if self.hasgroup(member):
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
272 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
273 groups.update(new_groups)
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
274 members.update(new_members)
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
275 else:
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
276 members[member] = 1
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
277 return members, groups
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2247
diff changeset
278
2254
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
279 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
280 """ load the dict from the cache """
472
faeaf423ef69 fix/speedup scandicts for persistent servers
Thomas Waldmann <tw@waldmann-edv.de>
parents: 400
diff changeset
281 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
282 rescan = False
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
283 arena = 'wikidicts'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
284 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
285 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
286 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
287 try:
1550
a4f0632414da using request.cfg.cache more
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1549
diff changeset
288 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
289 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
290 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
291 self.reset()
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
292 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
293 else:
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
294 return
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
295 except AttributeError:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
296 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
297 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
298 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
299 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
300
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
301 # 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
302 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
303 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
304 except:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
305 self.reset()
2254
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
306 rescan = True
472
faeaf423ef69 fix/speedup scandicts for persistent servers
Thomas Waldmann <tw@waldmann-edv.de>
parents: 400
diff changeset
307
2254
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
308 if rescan:
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
309 self.scan_dicts()
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
310 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
311 return
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
312
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
313 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
314 "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
315 "dictdict": self.dictdict,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
316 "groupdict": self.groupdict,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
317 "picklever": self.picklever
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
318 }
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 749
diff changeset
319
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
320 # remember it (persistent environments)
1550
a4f0632414da using request.cfg.cache more
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1549
diff changeset
321 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
322
2254
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
323 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
324 """ 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
325 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
326 """
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
327 request = self.request
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
328 self.reset()
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
329
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
330 # 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
331 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
332
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
333 # 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
334 # 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
335 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
336 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
337 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
338 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
339
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
340 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
341 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
342 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
343 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
344
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
345 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
346 self.expand_groups()
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
347
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
348 arena = 'wikidicts'
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
349 key = 'dicts_groups'
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
350 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
351 data = {
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
352 "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
353 "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
354 "dictdict": self.dictdict,
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
355 "groupdict": self.groupdict,
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
356 "picklever": self.picklever
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
357 }
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
358 cache.update(data)
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
359 # XXX release cache write lock here