annotate MoinMoin/wikisync.py @ 6058:5fb9d0f4af89

decode some config default values for user profiles
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Fri, 12 Sep 2014 15:34:52 +0200
parents 4541d744d740
children
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
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
18
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
1303
a0b8e78621d0 Preliminary support for items of different mime types.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1302
diff changeset
20 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
21 # 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
22 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
23
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
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
25 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
26 """ 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
27 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
28 """
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 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
30 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
31 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
32 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
33 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
34 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
35 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
36
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
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
38 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
39 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
40
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
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
42 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
43 pass
1385
8bf6e48c6236 Added rollback and exception logging to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1344
diff changeset
44
8bf6e48c6236 Added rollback and exception logging to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1344
diff changeset
45
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
46 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
47 """ 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
48 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
49 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
50 """ 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
51 @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
52 @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
53 @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
54 @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
55 @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
56 """
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 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
58 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
59 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
60 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
61 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
62 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
63 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
64 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
65 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
66 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
67 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
68 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
69
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 def __repr__(self):
1335
2cd1b40ea3e7 Added support for deletion of local pages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1330
diff changeset
71 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
72
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 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
74 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
75
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 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
77 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
78
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 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
80 """ 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
81 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
82
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 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
84 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
85 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
86 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
87
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 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
89 """ 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
90 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
91 """
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 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
93 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
94 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
95 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
96 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
97 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
98 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
99 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
100
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 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
102
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 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
104 """ 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
105 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
106 """
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 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
108 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
109
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 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
111 """ 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
112 # 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
113 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
114 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
115 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
116 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
117 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
118 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
119 # 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
120 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
121 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
122 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
123 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
124
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 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
126 """ 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
127 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
128
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 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
130 """ 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
131 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
132
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 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
134 """ 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
135 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
136
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 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
139 """ 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
140 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
141
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 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
143 """ 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
144 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
145
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 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
147 """ 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
148 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
149
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 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
151 """ 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
152 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
153
1793
2a4caa295346 Eclipse PyDev Check: fixed lots of its errors and warnings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1792
diff changeset
154 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
155 """ 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
156 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
157
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 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
160 """ 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
161 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
162 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
163 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
164 self.pagelist = pagelist
1330
df88b475c1f0 Reworked debugging.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1329
diff changeset
165 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
166 _ = 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
167
2728
59b3d8b8971f remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2032
diff changeset
168 wikitag, wikiurl, wikitail, wikitag_bad = wikiutil.resolve_interwiki(self.request, interwikiname, '')
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
169 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
170 self.valid = not wikitag_bad
5885
4541d744d740 wikisync: fix unicode pagename sending for python 2.7 httplib
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4831
diff changeset
171 self.xmlrpc_url = str(self.wiki_url + "?action=xmlrpc2")
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
172 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
173 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
174 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
175
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 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
177
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 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
179 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
180 except socket.error:
1415
6c017035a7f2 Implemented a password dialog in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1407
diff changeset
181 raise UnsupportedWikiException(_("The wiki is currently not reachable."))
3091
7e710fa829d0 Fix wikisync error handling: show the real error (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2728
diff changeset
182 except xmlrpclib.Fault, err:
7e710fa829d0 Fix wikisync error handling: show the real error (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2728
diff changeset
183 raise UnsupportedWikiException("xmlrpclib.Fault: %s" % str(err))
1386
0559fa036536 Added authentication support, fixed a few messages (added pagename).
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1385
diff changeset
184
0559fa036536 Added authentication support, fixed a few messages (added pagename).
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1385
diff changeset
185 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
186 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
187 if token:
0559fa036536 Added authentication support, fixed a few messages (added pagename).
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1385
diff changeset
188 self.token = token
0559fa036536 Added authentication support, fixed a few messages (added pagename).
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1385
diff changeset
189 else:
0559fa036536 Added authentication support, fixed a few messages (added pagename).
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1385
diff changeset
190 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
191 else:
0559fa036536 Added authentication support, fixed a few messages (added pagename).
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1385
diff changeset
192 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
193
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 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
195 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
196 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
197 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
198 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
199 " 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
200 "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
201
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 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
203 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
204 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
205 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
206
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 def createConnection(self):
1330
df88b475c1f0 Reworked debugging.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1329
diff changeset
208 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
209
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 # 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
211 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
212 """ 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
213 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
214 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
215
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 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
217 """ 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
218 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
219 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
220 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
221 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
222 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
223 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
224
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 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
226 """ 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
227 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
228
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 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
230 """ 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
231 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
232 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
233 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
234 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
235 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
236
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
237 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
238 """ 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
239 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
240
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
241 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
242 """ 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
243 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
244 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
245 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
246 raise result
1343
144c3281e88f Now the deletion of remote pages is working.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1336
diff changeset
247 return ""
1335
2cd1b40ea3e7 Added support for deletion of local pages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1330
diff changeset
248
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
249 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
250 """ Generates an object that can be used like a MultiCall instance. """
4582
afc6264a134f raised requirement to Python 2.4, removing 2.3 support code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3416
diff changeset
251 return xmlrpclib.MultiCall(self.connection)
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
252
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
253 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
254 """ 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
255 @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
256 """
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 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
258 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
259 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
260
2032
cf883a6917ea better xmlrpc auth token handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1920
diff changeset
261 def delete_auth_token(self):
cf883a6917ea better xmlrpc auth token handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1920
diff changeset
262 if self.token:
cf883a6917ea better xmlrpc auth token handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1920
diff changeset
263 self.connection.deleteAuthToken(self.token)
cf883a6917ea better xmlrpc auth token handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1920
diff changeset
264 self.token = None
cf883a6917ea better xmlrpc auth token handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1920
diff changeset
265
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
266 # 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
267
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
268 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
269 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
270
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 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
272 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
273
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 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
275 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
276 "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
277 "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
278 "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
279 "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
280 "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
281 "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
282 if self.token:
4582
afc6264a134f raised requirement to Python 2.4, removing 2.3 support code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3416
diff changeset
283 m = xmlrpclib.MultiCall(self.connection)
1386
0559fa036536 Added authentication support, fixed a few messages (added pagename).
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1385
diff changeset
284 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
285 m.getAllPagesEx(options)
0559fa036536 Added authentication support, fixed a few messages (added pagename).
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1385
diff changeset
286 tokres, pages = m()
0559fa036536 Added authentication support, fixed a few messages (added pagename).
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1385
diff changeset
287 else:
0559fa036536 Added authentication support, fixed a few messages (added pagename).
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1385
diff changeset
288 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
289 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
290 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
291 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
292 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
293 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
294 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
295 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
296 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
297 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
298 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
299
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 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
301 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
302
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 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
305 """ 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
306 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
307 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
308 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
309 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
310
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 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
312 """ Returns all page names that are listed on the page 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 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
314 for group_pagename in group_list:
4831
af155b846cea Groups2009: wikidicts imports were removed from the SyncPages and wikisync.
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4582
diff changeset
315 pages.extend(request.groups.get(group_pagename, []))
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
316 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
317
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 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
319 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
320 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
321 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
322 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
323 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
324 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
325 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
326 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
327
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
328 # 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
329
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
330 # 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
331 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
332 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
333 try:
2cd1b40ea3e7 Added support for deletion of local pages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1330
diff changeset
334 page.deletePage(comment)
2cd1b40ea3e7 Added support for deletion of local pages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1330
diff changeset
335 except PageEditor.AccessDenied, (msg, ):
2cd1b40ea3e7 Added support for deletion of local pages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1330
diff changeset
336 return msg
2cd1b40ea3e7 Added support for deletion of local pages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1330
diff changeset
337 return ""
2cd1b40ea3e7 Added support for deletion of local pages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1330
diff changeset
338
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
339 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
340 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
341
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
342 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
343 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
344
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 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
346 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
347 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
348 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
349 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
350 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
351 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
352 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
353 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
354 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
355 else:
16bed977b054 Added support for underlay page ignore and prefix filtering in getAllPagesEx,
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1261
diff changeset
356 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
357 pages = []
1315
ed3baf538cd5 Added infrastructure support for deleted pages in the sync framework.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1304
diff changeset
358 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
359 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
360 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
361 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
362 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
363
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
364 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
365 return "<MoinLocalWiki>"
1087
cdd4e9418547 Added locking to the PickleTagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1047
diff changeset
366
1026
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
367
1344
564cc2b53ea9 Reworded a docstring in SyncPages.sync, whitespace cleanup.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1343
diff changeset
368 # ------------------ 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
369
16bed977b054 Added support for underlay page ignore and prefix filtering in getAllPagesEx,
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1261
diff changeset
370
1022
4e65c6eabe9b Forgot to add the wikisync.py file containing the Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
371 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
372 """ 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
373
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
374 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
375 """ 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
376
1036
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
377 @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
378 @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
379 @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
380 @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
381 """
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
382 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
383 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
384 and isinstance(normalised_name, basestring))
1026
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
385 self.remote_wiki = remote_wiki
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
386 self.remote_rev = remote_rev
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
387 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
388 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
389 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
390
1036
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
391 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
392 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
393
1136
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1087
diff changeset
394 def __cmp__(self, other):
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1087
diff changeset
395 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
396 return NotImplemented
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1087
diff changeset
397 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
398
1022
4e65c6eabe9b Forgot to add the wikisync.py file containing the Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
399
1026
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
400 class AbstractTagStore(object):
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
401 """ 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
402 that manage the storage of tags. """
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
403
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
404 def __init__(self, page):
1036
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
405 """ 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
406 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
407 pass
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
408
1258
adebc2c73ef7 Added dump method to the AbstractTagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1251
diff changeset
409 def dump(self):
adebc2c73ef7 Added dump method to the AbstractTagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1251
diff changeset
410 """ 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
411 return repr(self.get_all_tags())
adebc2c73ef7 Added dump method to the AbstractTagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1251
diff changeset
412
1026
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
413 def add(self, **kwargs):
1036
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
414 """ 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
415 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
416 return NotImplemented
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
417
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
418 def get_all_tags(self):
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
419 """ 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
420 return NotImplemented
1304
f103cf7c371e Detect renamed pages. Changed the getDiff interface.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1303
diff changeset
421
f103cf7c371e Detect renamed pages. Changed the getDiff interface.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1303
diff changeset
422 def get_last_tag(self):
f103cf7c371e Detect renamed pages. Changed the getDiff interface.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1303
diff changeset
423 """ Returns the newest tag. """
f103cf7c371e Detect renamed pages. Changed the getDiff interface.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1303
diff changeset
424 return NotImplemented
f103cf7c371e Detect renamed pages. Changed the getDiff interface.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1303
diff changeset
425
1047
51086fe55b58 Added clearing to the TagStore, use it in the test.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1036
diff changeset
426 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
427 """ 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
428 return NotImplemented
1026
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
429
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
430 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
431 """ 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
432 return NotImplemented
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1087
diff changeset
433
1026
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
434
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
435 class PickleTagStore(AbstractTagStore):
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
436 """ 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
437
4e65c6eabe9b Forgot to add the wikisync.py file containing the Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
438 def __init__(self, page):
1036
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
439 """ 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
440
1036
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
441 @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
442 """
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
443
1022
4e65c6eabe9b Forgot to add the wikisync.py file containing the Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
444 self.page = page
1026
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
445 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
446 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
447 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
448 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
449
1087
cdd4e9418547 Added locking to the PickleTagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1047
diff changeset
450 if not self.rlock.acquire(3.0):
cdd4e9418547 Added locking to the PickleTagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1047
diff changeset
451 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
452 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
453 self.load()
1087
cdd4e9418547 Added locking to the PickleTagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1047
diff changeset
454 finally:
cdd4e9418547 Added locking to the PickleTagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1047
diff changeset
455 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
456
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 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
458 """ 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
459 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
460 datafile = file(self.filename, "rb")
1300
59dca7bc1d0f Fixed IOError in the TagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1296
diff changeset
461 self.tags = pickle.load(datafile)
1301
c53381d8527f Fixed EOFError in the TagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1300
diff changeset
462 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
463 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
464 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
465 datafile.close()
1344
564cc2b53ea9 Reworded a docstring in SyncPages.sync, whitespace cleanup.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1343
diff changeset
466
1026
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
467 def commit(self):
1036
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
468 """ 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
469 datafile = file(self.filename, "wb")
1302
7e0faeed44bc Fixed another Python 2.3 incompatibility.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1301
diff changeset
470 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
471 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
472
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 # 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
474 def add(self, **kwargs):
1087
cdd4e9418547 Added locking to the PickleTagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1047
diff changeset
475 if not self.wlock.acquire(3.0):
cdd4e9418547 Added locking to the PickleTagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1047
diff changeset
476 raise EnvironmentError("Could not lock in PickleTagStore")
cdd4e9418547 Added locking to the PickleTagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1047
diff changeset
477 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
478 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
479 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
480 self.commit()
1087
cdd4e9418547 Added locking to the PickleTagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1047
diff changeset
481 finally:
cdd4e9418547 Added locking to the PickleTagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1047
diff changeset
482 self.wlock.release()
1026
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
483
1036
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
484 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
485 return self.tags[:]
f103cf7c371e Detect renamed pages. Changed the getDiff interface.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1303
diff changeset
486
f103cf7c371e Detect renamed pages. Changed the getDiff interface.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1303
diff changeset
487 def get_last_tag(self):
f103cf7c371e Detect renamed pages. Changed the getDiff interface.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1303
diff changeset
488 temp = self.tags[:]
f103cf7c371e Detect renamed pages. Changed the getDiff interface.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1303
diff changeset
489 temp.sort()
f103cf7c371e Detect renamed pages. Changed the getDiff interface.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1303
diff changeset
490 if not temp:
f103cf7c371e Detect renamed pages. Changed the getDiff interface.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1303
diff changeset
491 return None
f103cf7c371e Detect renamed pages. Changed the getDiff interface.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1303
diff changeset
492 return temp[-1]
1026
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
493
1047
51086fe55b58 Added clearing to the TagStore, use it in the test.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1036
diff changeset
494 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
495 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
496 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
497 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
498 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
499 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
500 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
501 self.wlock.release()
1036
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
502
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
503 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
504 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
505 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
506 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
507 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
508 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
509 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
510 ) 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
511 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
512 return matching_tags
1136
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1087
diff changeset
513
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1087
diff changeset
514
1036
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
515 # 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
516 # 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
517 TagStore = PickleTagStore
1344
564cc2b53ea9 Reworded a docstring in SyncPages.sync, whitespace cleanup.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1343
diff changeset
518