annotate MoinMoin/wikisync.py @ 2298:c81b9c983b1d

OpenID storage for moin session
author Johannes Berg <johannes AT sipsolutions DOT net>
date Tue, 10 Jul 2007 19:09:14 +0200
parents cf883a6917ea
children 59b3d8b8971f
rev   line source
1022
4e65c6eabe9b Forgot to add the wikisync.py file containing the Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
4e65c6eabe9b Forgot to add the wikisync.py file containing the Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
2 """
4e65c6eabe9b Forgot to add the wikisync.py file containing the Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
3 MoinMoin - Wiki Synchronisation
4e65c6eabe9b Forgot to add the wikisync.py file containing the Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
4
1918
bb2e053067fb fixing copyright headers: remove umlauts (encoding troubles), make epydoc compatible, reformat
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1805
diff changeset
5 @copyright: 2006 MoinMoin:AlexanderSchremmer
1022
4e65c6eabe9b Forgot to add the wikisync.py file containing the Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
6 @license: GNU GPL, see COPYING for details.
4e65c6eabe9b Forgot to add the wikisync.py file containing the Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
7 """
4e65c6eabe9b Forgot to add the wikisync.py file containing the Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
8
1087
cdd4e9418547 Added locking to the PickleTagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1047
diff changeset
9 import os
1415
6c017035a7f2 Implemented a password dialog in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1407
diff changeset
10 import socket
1261
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
11 import xmlrpclib
1087
cdd4e9418547 Added locking to the PickleTagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1047
diff changeset
12
1261
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
13 from MoinMoin import wikiutil
1793
2a4caa295346 Eclipse PyDev Check: fixed lots of its errors and warnings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1792
diff changeset
14 from MoinMoin.util import lock, pickle
1261
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
15 from MoinMoin.Page import Page
1335
2cd1b40ea3e7 Added support for deletion of local pages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1330
diff changeset
16 from MoinMoin.PageEditor import PageEditor
1261
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
17 from MoinMoin.packages import unpackLine, packLine
1386
0559fa036536 Added authentication support, fixed a few messages (added pagename).
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1385
diff changeset
18 from MoinMoin.support.multicall import MultiCall
1261
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
19
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
20
1303
a0b8e78621d0 Preliminary support for items of different mime types.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1302
diff changeset
21 MIMETYPE_MOIN = "text/wiki"
1267
eb9e5e21b0e5 Implemented the DOWN direction, refactored direction handling. The synctags of older syncs are invalid now, you have to delete them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1266
diff changeset
22 # sync directions
eb9e5e21b0e5 Implemented the DOWN direction, refactored direction handling. The synctags of older syncs are invalid now, you have to delete them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1266
diff changeset
23 UP, DOWN, BOTH = range(3)
eb9e5e21b0e5 Implemented the DOWN direction, refactored direction handling. The synctags of older syncs are invalid now, you have to delete them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1266
diff changeset
24
eb9e5e21b0e5 Implemented the DOWN direction, refactored direction handling. The synctags of older syncs are invalid now, you have to delete them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1266
diff changeset
25
1261
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
26 def normalise_pagename(page_name, prefix):
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
27 """ Checks if the page_name starts with the prefix.
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
28 Returns None if it does not, otherwise strips the prefix.
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
29 """
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
30 if prefix:
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
31 if not page_name.startswith(prefix):
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
32 return None
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
33 else:
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
34 return page_name[len(prefix):]
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
35 else:
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
36 return page_name
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
37
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
38
1920
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
39 class UnsupportedWikiException(Exception):
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
40 pass
1261
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
41
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
42
1920
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
43 class NotAllowedException(Exception):
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
44 pass
1385
8bf6e48c6236 Added rollback and exception logging to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1344
diff changeset
45
8bf6e48c6236 Added rollback and exception logging to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1344
diff changeset
46
1261
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
47 class SyncPage(object):
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
48 """ This class represents a page in one or two wiki(s). """
1315
ed3baf538cd5 Added infrastructure support for deleted pages in the sync framework.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1304
diff changeset
49 def __init__(self, name, local_rev=None, remote_rev=None, local_name=None, remote_name=None,
ed3baf538cd5 Added infrastructure support for deleted pages in the sync framework.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1304
diff changeset
50 local_deleted=False, remote_deleted=False):
1261
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
51 """ Creates a SyncPage instance.
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
52 @param name: The canonical name of the page, without prefixes.
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
53 @param local_rev: The revision of the page in the local wiki.
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
54 @param remote_rev: The revision of the page in the remote wiki.
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
55 @param local_name: The page name of the page in the local wiki.
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
56 @param remote_name: The page name of the page in the remote wiki.
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
57 """
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
58 self.name = name
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
59 self.local_rev = local_rev
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
60 self.remote_rev = remote_rev
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
61 self.local_name = local_name
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
62 self.remote_name = remote_name
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
63 assert local_rev or remote_rev
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
64 assert local_name or remote_name
1315
ed3baf538cd5 Added infrastructure support for deleted pages in the sync framework.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1304
diff changeset
65 self.local_deleted = local_deleted
ed3baf538cd5 Added infrastructure support for deleted pages in the sync framework.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1304
diff changeset
66 self.remote_deleted = remote_deleted
1303
a0b8e78621d0 Preliminary support for items of different mime types.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1302
diff changeset
67 self.local_mime_type = MIMETYPE_MOIN # XXX no usable storage API yet
a0b8e78621d0 Preliminary support for items of different mime types.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1302
diff changeset
68 self.remote_mime_type = MIMETYPE_MOIN
1326
0c3927a3b8a2 Getting syncing of pages working that are just on one side, still faulty, though.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1315
diff changeset
69 assert remote_rev != 99999999
1261
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
70
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
71 def __repr__(self):
1335
2cd1b40ea3e7 Added support for deletion of local pages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1330
diff changeset
72 return repr("<Sync Page %r>" % unicode(self))
1261
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
73
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
74 def __unicode__(self):
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
75 return u"%s[%s|%s]<%r:%r>" % (self.name, self.local_name, self.remote_name, self.local_rev, self.remote_rev)
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
76
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
77 def __lt__(self, other):
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
78 return self.name < other.name
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
79
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
80 def __hash__(self):
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
81 """ Ensures that the hash value of this page only depends on the canonical name. """
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
82 return hash(self.name)
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
83
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
84 def __eq__(self, other):
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
85 if not isinstance(other, SyncPage):
1407
e1419b1f9679 Fixed parameter checking code, now it evens gives you a warning instead of a traceback, fixed two minor typos (thanks to birkenfeld!), introduced prepare_multicall support in order to get authentication working and actually added the RPC-Aggregator.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1404
diff changeset
86 return False
1261
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
87 return self.name == other.name
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
88
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
89 def add_missing_pagename(self, local, remote):
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
90 """ Checks if the particular concrete page names are unknown and fills
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
91 them in.
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
92 """
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
93 if self.local_name is None:
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
94 n_name = normalise_pagename(self.remote_name, remote.prefix)
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
95 assert n_name is not None
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
96 self.local_name = (local.prefix or "") + n_name
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
97 elif self.remote_name is None:
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
98 n_name = normalise_pagename(self.local_name, local.prefix)
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
99 assert n_name is not None
1326
0c3927a3b8a2 Getting syncing of pages working that are just on one side, still faulty, though.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1315
diff changeset
100 self.remote_name = (remote.prefix or "") + n_name
1261
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
101
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
102 return self # makes using list comps easier
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
103
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
104 def filter(cls, sp_list, func):
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
105 """ Returns all pages in sp_list that let func return True
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
106 for the canonical page name.
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
107 """
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
108 return [x for x in sp_list if func(x.name)]
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
109 filter = classmethod(filter)
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
110
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
111 def merge(cls, local_list, remote_list):
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
112 """ Merges two lists of SyncPages into one, migrating attributes like the names. """
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
113 # map page names to SyncPage objects :-)
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
114 d = dict(zip(local_list, local_list))
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
115 for sp in remote_list:
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
116 if sp in d:
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
117 d[sp].remote_rev = sp.remote_rev
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
118 d[sp].remote_name = sp.remote_name
1315
ed3baf538cd5 Added infrastructure support for deleted pages in the sync framework.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1304
diff changeset
119 d[sp].remote_deleted = sp.remote_deleted
1303
a0b8e78621d0 Preliminary support for items of different mime types.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1302
diff changeset
120 # XXX merge mime type here
1261
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
121 else:
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
122 d[sp] = sp
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
123 return d.keys()
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
124 merge = classmethod(merge)
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
125
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
126 def is_only_local(self):
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
127 """ Is true if the page is only in the local wiki. """
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
128 return not self.remote_rev
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
129
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
130 def is_only_remote(self):
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
131 """ Is true if the page is only in the remote wiki. """
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
132 return not self.local_rev
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
133
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
134 def is_local_and_remote(self):
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
135 """ Is true if the page is in both wikis. """
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
136 return self.local_rev and self.remote_rev
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
137
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
138
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
139 class RemoteWiki(object):
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
140 """ This class should be the base for all implementations of remote wiki
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
141 classes. """
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
142
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
143 def __repr__(self):
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
144 """ Returns a representation of the instance for debugging purposes. """
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
145 return NotImplemented
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
146
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
147 def get_interwiki_name(self):
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
148 """ Returns the interwiki name of the other wiki. """
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
149 return NotImplemented
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
150
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
151 def get_iwid(self):
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
152 """ Returns the InterWiki ID. """
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
153 return NotImplemented
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
154
1793
2a4caa295346 Eclipse PyDev Check: fixed lots of its errors and warnings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1792
diff changeset
155 def get_pages(self, **kw):
1261
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
156 """ Returns a list of SyncPage instances. """
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
157 return NotImplemented
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
158
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
159
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
160 class MoinRemoteWiki(RemoteWiki):
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
161 """ Used for MoinMoin wikis reachable via XMLRPC. """
1386
0559fa036536 Added authentication support, fixed a few messages (added pagename).
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1385
diff changeset
162 def __init__(self, request, interwikiname, prefix, pagelist, user, password, verbose=False):
1261
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
163 self.request = request
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
164 self.prefix = prefix
1266
ff08338e67fe Filter the pagelists by pageList on both sides (speedup). Marked a few operations as direct API accesses.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1262
diff changeset
165 self.pagelist = pagelist
1330
df88b475c1f0 Reworked debugging.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1329
diff changeset
166 self.verbose = verbose
1261
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
167 _ = self.request.getText
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
168
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
169 wikitag, wikiurl, wikitail, wikitag_bad = wikiutil.resolve_wiki(self.request, '%s:""' % (interwikiname, ))
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
170 self.wiki_url = wikiutil.mapURL(self.request, wikiurl)
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
171 self.valid = not wikitag_bad
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
172 self.xmlrpc_url = self.wiki_url + "?action=xmlrpc2"
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
173 if not self.valid:
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
174 self.connection = None
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
175 return
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
176
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
177 self.connection = self.createConnection()
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
178
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
179 try:
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
180 iw_list = self.connection.interwikiName()
1805
ebcebba1afb3 removed some unused attributes, used 'dummy' for dummies
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1793
diff changeset
181 except socket.error:
1415
6c017035a7f2 Implemented a password dialog in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1407
diff changeset
182 raise UnsupportedWikiException(_("The wiki is currently not reachable."))
1805
ebcebba1afb3 removed some unused attributes, used 'dummy' for dummies
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1793
diff changeset
183 except xmlrpclib.Fault:
1386
0559fa036536 Added authentication support, fixed a few messages (added pagename).
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1385
diff changeset
184 raise UnsupportedWikiException(_("The remote version of MoinMoin is too old, version 1.6 is required at least."))
0559fa036536 Added authentication support, fixed a few messages (added pagename).
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1385
diff changeset
185
0559fa036536 Added authentication support, fixed a few messages (added pagename).
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1385
diff changeset
186 if user and password:
0559fa036536 Added authentication support, fixed a few messages (added pagename).
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1385
diff changeset
187 token = self.connection.getAuthToken(user, password)
0559fa036536 Added authentication support, fixed a few messages (added pagename).
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1385
diff changeset
188 if token:
0559fa036536 Added authentication support, fixed a few messages (added pagename).
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1385
diff changeset
189 self.token = token
0559fa036536 Added authentication support, fixed a few messages (added pagename).
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1385
diff changeset
190 else:
0559fa036536 Added authentication support, fixed a few messages (added pagename).
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1385
diff changeset
191 raise NotAllowedException(_("Invalid username or password."))
0559fa036536 Added authentication support, fixed a few messages (added pagename).
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1385
diff changeset
192 else:
0559fa036536 Added authentication support, fixed a few messages (added pagename).
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1385
diff changeset
193 self.token = None
1261
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
194
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
195 self.remote_interwikiname = remote_interwikiname = iw_list[0]
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
196 self.remote_iwid = remote_iwid = iw_list[1]
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
197 self.is_anonymous = remote_interwikiname is None
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
198 if not self.is_anonymous and interwikiname != remote_interwikiname:
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
199 raise UnsupportedWikiException(_("The remote wiki uses a different InterWiki name (%(remotename)s)"
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
200 " internally than you specified (%(localname)s).") % {
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
201 "remotename": wikiutil.escape(remote_interwikiname), "localname": wikiutil.escape(interwikiname)})
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
202
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
203 if self.is_anonymous:
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
204 self.iwid_full = packLine([remote_iwid])
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
205 else:
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
206 self.iwid_full = packLine([remote_iwid, interwikiname])
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
207
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
208 def createConnection(self):
1330
df88b475c1f0 Reworked debugging.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1329
diff changeset
209 return xmlrpclib.ServerProxy(self.xmlrpc_url, allow_none=True, verbose=self.verbose)
1261
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
210
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
211 # Public methods
1404
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1394
diff changeset
212 def get_diff_pre(self, pagename, from_rev, to_rev, n_name=None):
1261
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
213 """ Returns the binary diff of the remote page named pagename, given
1404
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1394
diff changeset
214 from_rev and to_rev. Generates the call. """
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1394
diff changeset
215 return "getDiff", (pagename, from_rev, to_rev, n_name)
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1394
diff changeset
216
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1394
diff changeset
217 def get_diff_post(self, value):
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1394
diff changeset
218 """ Processes the return value of the call generated by get_diff_pre. """
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1394
diff changeset
219 if isinstance(value, xmlrpclib.Fault):
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1394
diff changeset
220 if value.faultCode == "INVALID_TAG":
1304
f103cf7c371e Detect renamed pages. Changed the getDiff interface.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1303
diff changeset
221 return None
1404
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1394
diff changeset
222 raise value
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1394
diff changeset
223 value["diff"] = str(value["diff"]) # unmarshal Binary object
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1394
diff changeset
224 return value
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1394
diff changeset
225
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1394
diff changeset
226 def merge_diff_pre(self, pagename, diff, local_rev, delta_remote_rev, last_remote_rev, interwiki_name, n_name):
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1394
diff changeset
227 """ Merges the diff into the page on the remote side. Generates the call. """
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1394
diff changeset
228 return "mergeDiff", (pagename, xmlrpclib.Binary(diff), local_rev, delta_remote_rev, last_remote_rev, interwiki_name, n_name)
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1394
diff changeset
229
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1394
diff changeset
230 def merge_diff_post(self, result):
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1394
diff changeset
231 """ Processes the return value of the call generated by merge_diff_pre. """
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1394
diff changeset
232 if isinstance(result, xmlrpclib.Fault):
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1394
diff changeset
233 if result.faultCode == "NOT_ALLOWED":
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1394
diff changeset
234 raise NotAllowedException
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1394
diff changeset
235 raise result
1261
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
236 return result
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
237
1404
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1394
diff changeset
238 def delete_page_pre(self, pagename, last_remote_rev, interwiki_name):
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1394
diff changeset
239 """ Deletes a remote page. Generates the call. """
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1394
diff changeset
240 return "mergeDiff", (pagename, None, None, None, last_remote_rev, interwiki_name, None)
1261
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
241
1404
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1394
diff changeset
242 def delete_page_post(self, result):
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1394
diff changeset
243 """ Processes the return value of the call generated by delete_page_pre. """
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1394
diff changeset
244 if isinstance(result, xmlrpclib.Fault):
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1394
diff changeset
245 if result.faultCode == "NOT_ALLOWED":
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1394
diff changeset
246 return result.faultString
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1394
diff changeset
247 raise result
1343
144c3281e88f Now the deletion of remote pages is working.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1336
diff changeset
248 return ""
1335
2cd1b40ea3e7 Added support for deletion of local pages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1330
diff changeset
249
1404
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1394
diff changeset
250 def create_multicall_object(self):
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1394
diff changeset
251 """ Generates an object that can be used like a MultiCall instance. """
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1394
diff changeset
252 return MultiCall(self.connection)
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1394
diff changeset
253
1407
e1419b1f9679 Fixed parameter checking code, now it evens gives you a warning instead of a traceback, fixed two minor typos (thanks to birkenfeld!), introduced prepare_multicall support in order to get authentication working and actually added the RPC-Aggregator.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1404
diff changeset
254 def prepare_multicall(self):
e1419b1f9679 Fixed parameter checking code, now it evens gives you a warning instead of a traceback, fixed two minor typos (thanks to birkenfeld!), introduced prepare_multicall support in order to get authentication working and actually added the RPC-Aggregator.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1404
diff changeset
255 """ Can be used to return initial calls that e.g. authenticate the user.
e1419b1f9679 Fixed parameter checking code, now it evens gives you a warning instead of a traceback, fixed two minor typos (thanks to birkenfeld!), introduced prepare_multicall support in order to get authentication working and actually added the RPC-Aggregator.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1404
diff changeset
256 @return: [(funcname, (arg,+)*]
e1419b1f9679 Fixed parameter checking code, now it evens gives you a warning instead of a traceback, fixed two minor typos (thanks to birkenfeld!), introduced prepare_multicall support in order to get authentication working and actually added the RPC-Aggregator.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1404
diff changeset
257 """
e1419b1f9679 Fixed parameter checking code, now it evens gives you a warning instead of a traceback, fixed two minor typos (thanks to birkenfeld!), introduced prepare_multicall support in order to get authentication working and actually added the RPC-Aggregator.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1404
diff changeset
258 if self.token:
e1419b1f9679 Fixed parameter checking code, now it evens gives you a warning instead of a traceback, fixed two minor typos (thanks to birkenfeld!), introduced prepare_multicall support in order to get authentication working and actually added the RPC-Aggregator.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1404
diff changeset
259 return [("applyAuthToken", (self.token, ))]
e1419b1f9679 Fixed parameter checking code, now it evens gives you a warning instead of a traceback, fixed two minor typos (thanks to birkenfeld!), introduced prepare_multicall support in order to get authentication working and actually added the RPC-Aggregator.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1404
diff changeset
260 return []
e1419b1f9679 Fixed parameter checking code, now it evens gives you a warning instead of a traceback, fixed two minor typos (thanks to birkenfeld!), introduced prepare_multicall support in order to get authentication working and actually added the RPC-Aggregator.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1404
diff changeset
261
2032
cf883a6917ea better xmlrpc auth token handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1920
diff changeset
262 def delete_auth_token(self):
cf883a6917ea better xmlrpc auth token handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1920
diff changeset
263 if self.token:
cf883a6917ea better xmlrpc auth token handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1920
diff changeset
264 self.connection.deleteAuthToken(self.token)
cf883a6917ea better xmlrpc auth token handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1920
diff changeset
265 self.token = None
cf883a6917ea better xmlrpc auth token handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1920
diff changeset
266
1261
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
267 # Methods implementing the RemoteWiki interface
1343
144c3281e88f Now the deletion of remote pages is working.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1336
diff changeset
268
1261
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
269 def get_interwiki_name(self):
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
270 return self.remote_interwikiname
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
271
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
272 def get_iwid(self):
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
273 return self.remote_iwid
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
274
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
275 def get_pages(self, **kwargs):
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
276 options = {"include_revno": True,
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
277 "include_deleted": True,
1262
16bed977b054 Added support for underlay page ignore and prefix filtering in getAllPagesEx,
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1261
diff changeset
278 "exclude_non_writable": kwargs["exclude_non_writable"],
16bed977b054 Added support for underlay page ignore and prefix filtering in getAllPagesEx,
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1261
diff changeset
279 "include_underlay": False,
1266
ff08338e67fe Filter the pagelists by pageList on both sides (speedup). Marked a few operations as direct API accesses.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1262
diff changeset
280 "prefix": self.prefix,
1315
ed3baf538cd5 Added infrastructure support for deleted pages in the sync framework.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1304
diff changeset
281 "pagelist": self.pagelist,
ed3baf538cd5 Added infrastructure support for deleted pages in the sync framework.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1304
diff changeset
282 "mark_deleted": True}
1386
0559fa036536 Added authentication support, fixed a few messages (added pagename).
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1385
diff changeset
283 if self.token:
0559fa036536 Added authentication support, fixed a few messages (added pagename).
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1385
diff changeset
284 m = MultiCall(self.connection)
0559fa036536 Added authentication support, fixed a few messages (added pagename).
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1385
diff changeset
285 m.applyAuthToken(self.token)
0559fa036536 Added authentication support, fixed a few messages (added pagename).
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1385
diff changeset
286 m.getAllPagesEx(options)
0559fa036536 Added authentication support, fixed a few messages (added pagename).
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1385
diff changeset
287 tokres, pages = m()
0559fa036536 Added authentication support, fixed a few messages (added pagename).
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1385
diff changeset
288 else:
0559fa036536 Added authentication support, fixed a few messages (added pagename).
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1385
diff changeset
289 pages = self.connection.getAllPagesEx(options)
1261
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
290 rpages = []
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
291 for name, revno in pages:
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
292 normalised_name = normalise_pagename(name, self.prefix)
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
293 if normalised_name is None:
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
294 continue
1326
0c3927a3b8a2 Getting syncing of pages working that are just on one side, still faulty, though.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1315
diff changeset
295 if abs(revno) != 99999999: # I love sane in-band signalling
0c3927a3b8a2 Getting syncing of pages working that are just on one side, still faulty, though.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1315
diff changeset
296 remote_rev = abs(revno)
0c3927a3b8a2 Getting syncing of pages working that are just on one side, still faulty, though.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1315
diff changeset
297 remote_deleted = revno < 0
0c3927a3b8a2 Getting syncing of pages working that are just on one side, still faulty, though.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1315
diff changeset
298 rpages.append(SyncPage(normalised_name, remote_rev=remote_rev, remote_name=name, remote_deleted=remote_deleted))
1261
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
299 return rpages
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
300
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
301 def __repr__(self):
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
302 return "<MoinRemoteWiki wiki_url=%r valid=%r>" % (getattr(self, "wiki_url", Ellipsis), getattr(self, "valid", Ellipsis))
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
303
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
304
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
305 class MoinLocalWiki(RemoteWiki):
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
306 """ Used for the current MoinMoin wiki. """
1266
ff08338e67fe Filter the pagelists by pageList on both sides (speedup). Marked a few operations as direct API accesses.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1262
diff changeset
307 def __init__(self, request, prefix, pagelist):
1261
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
308 self.request = request
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
309 self.prefix = prefix
1266
ff08338e67fe Filter the pagelists by pageList on both sides (speedup). Marked a few operations as direct API accesses.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1262
diff changeset
310 self.pagelist = pagelist
1261
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
311
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
312 def getGroupItems(self, group_list):
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
313 """ Returns all page names that are listed on the page group_list. """
1793
2a4caa295346 Eclipse PyDev Check: fixed lots of its errors and warnings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1792
diff changeset
314 from MoinMoin.wikidicts import Group
1261
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
315 pages = []
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
316 for group_pagename in group_list:
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
317 pages.extend(Group(self.request, group_pagename).members())
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
318 return [self.createSyncPage(x) for x in pages]
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
319
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
320 def createSyncPage(self, page_name):
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
321 normalised_name = normalise_pagename(page_name, self.prefix)
1329
4a8c4849d162 Got syncing working with pages that are just in one wiki.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1326
diff changeset
322 if normalised_name is None:
4a8c4849d162 Got syncing working with pages that are just in one wiki.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1326
diff changeset
323 return None
1296
93ecff3f806f Check for local write permissions early, fixed Python 2.3 incompatiblity.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1295
diff changeset
324 if not self.request.user.may.write(normalised_name):
93ecff3f806f Check for local write permissions early, fixed Python 2.3 incompatiblity.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1295
diff changeset
325 return None
1315
ed3baf538cd5 Added infrastructure support for deleted pages in the sync framework.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1304
diff changeset
326 page = Page(self.request, page_name)
1326
0c3927a3b8a2 Getting syncing of pages working that are just on one side, still faulty, though.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1315
diff changeset
327 revno = page.get_real_rev()
0c3927a3b8a2 Getting syncing of pages working that are just on one side, still faulty, though.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1315
diff changeset
328 if revno == 99999999: # I love sane in-band signalling
1329
4a8c4849d162 Got syncing working with pages that are just in one wiki.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1326
diff changeset
329 return None
1326
0c3927a3b8a2 Getting syncing of pages working that are just on one side, still faulty, though.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1315
diff changeset
330 return SyncPage(normalised_name, local_rev=revno, local_name=page_name, local_deleted=not page.exists())
1261
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
331
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
332 # Public methods:
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
333
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
334 # Methods implementing the RemoteWiki interface
1343
144c3281e88f Now the deletion of remote pages is working.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1336
diff changeset
335 def delete_page(self, pagename, comment):
1791
6dd2e29acffe Eclipse PyDev Check: fixed lots of its errors and warnings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1415
diff changeset
336 page = PageEditor(self.request, pagename)
1335
2cd1b40ea3e7 Added support for deletion of local pages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1330
diff changeset
337 try:
2cd1b40ea3e7 Added support for deletion of local pages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1330
diff changeset
338 page.deletePage(comment)
2cd1b40ea3e7 Added support for deletion of local pages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1330
diff changeset
339 except PageEditor.AccessDenied, (msg, ):
2cd1b40ea3e7 Added support for deletion of local pages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1330
diff changeset
340 return msg
2cd1b40ea3e7 Added support for deletion of local pages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1330
diff changeset
341 return ""
2cd1b40ea3e7 Added support for deletion of local pages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1330
diff changeset
342
1261
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
343 def get_interwiki_name(self):
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
344 return self.request.cfg.interwikiname
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
345
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
346 def get_iwid(self):
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
347 return self.request.cfg.iwid
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
348
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
349 def get_pages(self, **kwargs):
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
350 assert not kwargs
1266
ff08338e67fe Filter the pagelists by pageList on both sides (speedup). Marked a few operations as direct API accesses.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1262
diff changeset
351 if self.prefix or self.pagelist:
ff08338e67fe Filter the pagelists by pageList on both sides (speedup). Marked a few operations as direct API accesses.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1262
diff changeset
352 def page_filter(name, prefix=(self.prefix or ""), pagelist=self.pagelist):
ff08338e67fe Filter the pagelists by pageList on both sides (speedup). Marked a few operations as direct API accesses.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1262
diff changeset
353 n_name = normalise_pagename(name, prefix)
ff08338e67fe Filter the pagelists by pageList on both sides (speedup). Marked a few operations as direct API accesses.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1262
diff changeset
354 if not n_name:
ff08338e67fe Filter the pagelists by pageList on both sides (speedup). Marked a few operations as direct API accesses.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1262
diff changeset
355 return False
ff08338e67fe Filter the pagelists by pageList on both sides (speedup). Marked a few operations as direct API accesses.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1262
diff changeset
356 if not pagelist:
ff08338e67fe Filter the pagelists by pageList on both sides (speedup). Marked a few operations as direct API accesses.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1262
diff changeset
357 return True
ff08338e67fe Filter the pagelists by pageList on both sides (speedup). Marked a few operations as direct API accesses.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1262
diff changeset
358 return n_name in pagelist
1262
16bed977b054 Added support for underlay page ignore and prefix filtering in getAllPagesEx,
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1261
diff changeset
359 else:
16bed977b054 Added support for underlay page ignore and prefix filtering in getAllPagesEx,
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1261
diff changeset
360 page_filter = lambda x: True
16bed977b054 Added support for underlay page ignore and prefix filtering in getAllPagesEx,
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1261
diff changeset
361 pages = []
1315
ed3baf538cd5 Added infrastructure support for deleted pages in the sync framework.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1304
diff changeset
362 for x in self.request.rootpage.getPageList(exists=False, include_underlay=False, filter=page_filter):
1262
16bed977b054 Added support for underlay page ignore and prefix filtering in getAllPagesEx,
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1261
diff changeset
363 sp = self.createSyncPage(x)
16bed977b054 Added support for underlay page ignore and prefix filtering in getAllPagesEx,
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1261
diff changeset
364 if sp:
16bed977b054 Added support for underlay page ignore and prefix filtering in getAllPagesEx,
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1261
diff changeset
365 pages.append(sp)
16bed977b054 Added support for underlay page ignore and prefix filtering in getAllPagesEx,
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1261
diff changeset
366 return pages
1261
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
367
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
368 def __repr__(self):
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
369 return "<MoinLocalWiki>"
1087
cdd4e9418547 Added locking to the PickleTagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1047
diff changeset
370
1026
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
371
1344
564cc2b53ea9 Reworded a docstring in SyncPages.sync, whitespace cleanup.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1343
diff changeset
372 # ------------------ Tags ------------------
1262
16bed977b054 Added support for underlay page ignore and prefix filtering in getAllPagesEx,
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1261
diff changeset
373
16bed977b054 Added support for underlay page ignore and prefix filtering in getAllPagesEx,
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1261
diff changeset
374
1022
4e65c6eabe9b Forgot to add the wikisync.py file containing the Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
375 class Tag(object):
4e65c6eabe9b Forgot to add the wikisync.py file containing the Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
376 """ This class is used to store information about merging state. """
1344
564cc2b53ea9 Reworded a docstring in SyncPages.sync, whitespace cleanup.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1343
diff changeset
377
1272
e85ad6a95ae5 Documented new ideas in the docstring, changed tag format (store normalised name), transmit normalised name in mergeDiff.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1267
diff changeset
378 def __init__(self, remote_wiki, remote_rev, current_rev, direction, normalised_name):
1036
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
379 """ Creates a new Tag.
1344
564cc2b53ea9 Reworded a docstring in SyncPages.sync, whitespace cleanup.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1343
diff changeset
380
1036
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
381 @param remote_wiki: The identifier of the remote wiki.
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
382 @param remote_rev: The revision number on the remote end.
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
383 @param current_rev: The related local revision.
1267
eb9e5e21b0e5 Implemented the DOWN direction, refactored direction handling. The synctags of older syncs are invalid now, you have to delete them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1266
diff changeset
384 @param direction: The direction of the sync, encoded as an integer.
1036
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
385 """
1272
e85ad6a95ae5 Documented new ideas in the docstring, changed tag format (store normalised name), transmit normalised name in mergeDiff.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1267
diff changeset
386 assert (isinstance(remote_wiki, basestring) and isinstance(remote_rev, int)
e85ad6a95ae5 Documented new ideas in the docstring, changed tag format (store normalised name), transmit normalised name in mergeDiff.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1267
diff changeset
387 and isinstance(current_rev, int) and isinstance(direction, int)
e85ad6a95ae5 Documented new ideas in the docstring, changed tag format (store normalised name), transmit normalised name in mergeDiff.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1267
diff changeset
388 and isinstance(normalised_name, basestring))
1026
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
389 self.remote_wiki = remote_wiki
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
390 self.remote_rev = remote_rev
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
391 self.current_rev = current_rev
1267
eb9e5e21b0e5 Implemented the DOWN direction, refactored direction handling. The synctags of older syncs are invalid now, you have to delete them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1266
diff changeset
392 self.direction = direction
1272
e85ad6a95ae5 Documented new ideas in the docstring, changed tag format (store normalised name), transmit normalised name in mergeDiff.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1267
diff changeset
393 self.normalised_name = normalised_name
1022
4e65c6eabe9b Forgot to add the wikisync.py file containing the Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
394
1036
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
395 def __repr__(self):
1329
4a8c4849d162 Got syncing working with pages that are just in one wiki.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1326
diff changeset
396 return u"<Tag normalised_pagename=%r remote_wiki=%r remote_rev=%r current_rev=%r>" % (getattr(self, "normalised_name", "UNDEF"), self.remote_wiki, self.remote_rev, self.current_rev)
1036
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
397
1136
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1087
diff changeset
398 def __cmp__(self, other):
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1087
diff changeset
399 if not isinstance(other, Tag):
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1087
diff changeset
400 return NotImplemented
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1087
diff changeset
401 return cmp(self.current_rev, other.current_rev)
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1087
diff changeset
402
1022
4e65c6eabe9b Forgot to add the wikisync.py file containing the Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
403
1026
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
404 class AbstractTagStore(object):
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
405 """ This class is an abstract base class that shows how to implement classes
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
406 that manage the storage of tags. """
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
407
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
408 def __init__(self, page):
1036
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
409 """ Subclasses don't need to call this method. It is just here to enforce
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
410 them having accept a page argument at least. """
1026
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
411 pass
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
412
1258
adebc2c73ef7 Added dump method to the AbstractTagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1251
diff changeset
413 def dump(self):
adebc2c73ef7 Added dump method to the AbstractTagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1251
diff changeset
414 """ Returns all tags for a given item as a string. """
adebc2c73ef7 Added dump method to the AbstractTagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1251
diff changeset
415 return repr(self.get_all_tags())
adebc2c73ef7 Added dump method to the AbstractTagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1251
diff changeset
416
1026
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
417 def add(self, **kwargs):
1036
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
418 """ Adds a Tag object to the current TagStore. """
1026
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
419 print "Got tag for page %r: %r" % (self.page, kwargs)
1036
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
420 return NotImplemented
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
421
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
422 def get_all_tags(self):
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
423 """ Returns a list of all Tag objects associated to this page. """
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
424 return NotImplemented
1304
f103cf7c371e Detect renamed pages. Changed the getDiff interface.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1303
diff changeset
425
f103cf7c371e Detect renamed pages. Changed the getDiff interface.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1303
diff changeset
426 def get_last_tag(self):
f103cf7c371e Detect renamed pages. Changed the getDiff interface.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1303
diff changeset
427 """ Returns the newest tag. """
f103cf7c371e Detect renamed pages. Changed the getDiff interface.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1303
diff changeset
428 return NotImplemented
f103cf7c371e Detect renamed pages. Changed the getDiff interface.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1303
diff changeset
429
1047
51086fe55b58 Added clearing to the TagStore, use it in the test.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1036
diff changeset
430 def clear(self):
51086fe55b58 Added clearing to the TagStore, use it in the test.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1036
diff changeset
431 """ Removes all tags. """
51086fe55b58 Added clearing to the TagStore, use it in the test.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1036
diff changeset
432 return NotImplemented
1026
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
433
1920
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
434 def fetch(self, iwid_full=None, direction=None):
1136
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1087
diff changeset
435 """ Fetches tags by a special IWID or interwiki name. """
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1087
diff changeset
436 return NotImplemented
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1087
diff changeset
437
1026
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
438
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
439 class PickleTagStore(AbstractTagStore):
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
440 """ This class manages the storage of tags in pickle files. """
1022
4e65c6eabe9b Forgot to add the wikisync.py file containing the Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
441
4e65c6eabe9b Forgot to add the wikisync.py file containing the Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
442 def __init__(self, page):
1036
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
443 """ Creates a new TagStore that uses pickle files.
1344
564cc2b53ea9 Reworded a docstring in SyncPages.sync, whitespace cleanup.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1343
diff changeset
444
1036
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
445 @param page: a Page object where the tags should be related to
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
446 """
1295
9608758dca9a Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1272
diff changeset
447
1022
4e65c6eabe9b Forgot to add the wikisync.py file containing the Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
448 self.page = page
1026
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
449 self.filename = page.getPagePath('synctags', use_underlay=0, check_create=1, isfile=1)
1087
cdd4e9418547 Added locking to the PickleTagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1047
diff changeset
450 lock_dir = os.path.join(page.getPagePath('cache', use_underlay=0, check_create=1), '__taglock__')
cdd4e9418547 Added locking to the PickleTagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1047
diff changeset
451 self.rlock = lock.ReadLock(lock_dir, 60.0)
cdd4e9418547 Added locking to the PickleTagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1047
diff changeset
452 self.wlock = lock.WriteLock(lock_dir, 60.0)
1022
4e65c6eabe9b Forgot to add the wikisync.py file containing the Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
453
1087
cdd4e9418547 Added locking to the PickleTagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1047
diff changeset
454 if not self.rlock.acquire(3.0):
cdd4e9418547 Added locking to the PickleTagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1047
diff changeset
455 raise EnvironmentError("Could not lock in PickleTagStore")
1026
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
456 try:
1295
9608758dca9a Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1272
diff changeset
457 self.load()
1087
cdd4e9418547 Added locking to the PickleTagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1047
diff changeset
458 finally:
cdd4e9418547 Added locking to the PickleTagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1047
diff changeset
459 self.rlock.release()
1295
9608758dca9a Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1272
diff changeset
460
9608758dca9a Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1272
diff changeset
461 def load(self):
9608758dca9a Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1272
diff changeset
462 """ Loads the tags from the data file. """
9608758dca9a Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1272
diff changeset
463 try:
9608758dca9a Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1272
diff changeset
464 datafile = file(self.filename, "rb")
1300
59dca7bc1d0f Fixed IOError in the TagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1296
diff changeset
465 self.tags = pickle.load(datafile)
1301
c53381d8527f Fixed EOFError in the TagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1300
diff changeset
466 except (IOError, EOFError):
1295
9608758dca9a Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1272
diff changeset
467 self.tags = []
9608758dca9a Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1272
diff changeset
468 else:
9608758dca9a Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1272
diff changeset
469 datafile.close()
1344
564cc2b53ea9 Reworded a docstring in SyncPages.sync, whitespace cleanup.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1343
diff changeset
470
1026
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
471 def commit(self):
1036
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
472 """ Writes the memory contents to the data file. """
1295
9608758dca9a Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1272
diff changeset
473 datafile = file(self.filename, "wb")
1302
7e0faeed44bc Fixed another Python 2.3 incompatibility.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1301
diff changeset
474 pickle.dump(self.tags, datafile, pickle.HIGHEST_PROTOCOL)
1295
9608758dca9a Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1272
diff changeset
475 datafile.close()
9608758dca9a Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1272
diff changeset
476
9608758dca9a Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1272
diff changeset
477 # public methods ---------------------------------------------------
9608758dca9a Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1272
diff changeset
478 def add(self, **kwargs):
1087
cdd4e9418547 Added locking to the PickleTagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1047
diff changeset
479 if not self.wlock.acquire(3.0):
cdd4e9418547 Added locking to the PickleTagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1047
diff changeset
480 raise EnvironmentError("Could not lock in PickleTagStore")
cdd4e9418547 Added locking to the PickleTagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1047
diff changeset
481 try:
1295
9608758dca9a Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1272
diff changeset
482 self.load()
9608758dca9a Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1272
diff changeset
483 self.tags.append(Tag(**kwargs))
9608758dca9a Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1272
diff changeset
484 self.commit()
1087
cdd4e9418547 Added locking to the PickleTagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1047
diff changeset
485 finally:
cdd4e9418547 Added locking to the PickleTagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1047
diff changeset
486 self.wlock.release()
1026
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
487
1036
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
488 def get_all_tags(self):
1304
f103cf7c371e Detect renamed pages. Changed the getDiff interface.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1303
diff changeset
489 return self.tags[:]
f103cf7c371e Detect renamed pages. Changed the getDiff interface.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1303
diff changeset
490
f103cf7c371e Detect renamed pages. Changed the getDiff interface.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1303
diff changeset
491 def get_last_tag(self):
f103cf7c371e Detect renamed pages. Changed the getDiff interface.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1303
diff changeset
492 temp = self.tags[:]
f103cf7c371e Detect renamed pages. Changed the getDiff interface.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1303
diff changeset
493 temp.sort()
f103cf7c371e Detect renamed pages. Changed the getDiff interface.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1303
diff changeset
494 if not temp:
f103cf7c371e Detect renamed pages. Changed the getDiff interface.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1303
diff changeset
495 return None
f103cf7c371e Detect renamed pages. Changed the getDiff interface.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1303
diff changeset
496 return temp[-1]
1026
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
497
1047
51086fe55b58 Added clearing to the TagStore, use it in the test.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1036
diff changeset
498 def clear(self):
51086fe55b58 Added clearing to the TagStore, use it in the test.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1036
diff changeset
499 self.tags = []
1295
9608758dca9a Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1272
diff changeset
500 if not self.wlock.acquire(3.0):
9608758dca9a Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1272
diff changeset
501 raise EnvironmentError("Could not lock in PickleTagStore")
9608758dca9a Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1272
diff changeset
502 try:
9608758dca9a Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1272
diff changeset
503 self.commit()
9608758dca9a Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1272
diff changeset
504 finally:
9608758dca9a Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1272
diff changeset
505 self.wlock.release()
1036
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
506
1267
eb9e5e21b0e5 Implemented the DOWN direction, refactored direction handling. The synctags of older syncs are invalid now, you have to delete them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1266
diff changeset
507 def fetch(self, iwid_full, direction=None):
1261
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
508 iwid_full = unpackLine(iwid_full)
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
509 matching_tags = []
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
510 for t in self.tags:
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
511 t_iwid_full = unpackLine(t.remote_wiki)
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
512 if ((t_iwid_full[0] == iwid_full[0]) # either match IWID or IW name
1267
eb9e5e21b0e5 Implemented the DOWN direction, refactored direction handling. The synctags of older syncs are invalid now, you have to delete them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1266
diff changeset
513 or (len(t_iwid_full) == 2 and len(iwid_full) == 2 and t_iwid_full[1] == iwid_full[1])
eb9e5e21b0e5 Implemented the DOWN direction, refactored direction handling. The synctags of older syncs are invalid now, you have to delete them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1266
diff changeset
514 ) and (direction is None or t.direction == direction):
1261
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
515 matching_tags.append(t)
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
516 return matching_tags
1136
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1087
diff changeset
517
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1087
diff changeset
518
1036
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
519 # currently we just have one implementation, so we do not need
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
520 # a factory method
1261
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
521 TagStore = PickleTagStore
1344
564cc2b53ea9 Reworded a docstring in SyncPages.sync, whitespace cleanup.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1343
diff changeset
522