annotate MoinMoin/wikisync.py @ 1329:4a8c4849d162

Got syncing working with pages that are just in one wiki.
author Alexander Schremmer <alex AT alexanderweb DOT de>
date Sat, 19 Aug 2006 16:06:52 +0200
parents 0c3927a3b8a2
children df88b475c1f0
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
4e65c6eabe9b Forgot to add the wikisync.py file containing the Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
5 @copyright: 2006 by MoinMoin:AlexanderSchremmer
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
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
10 import xmlrpclib
1087
cdd4e9418547 Added locking to the PickleTagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1047
diff changeset
11
1026
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
12 try:
1036
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
13 import cPickle as pickle
1026
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
14 except ImportError:
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
15 import pickle
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
16
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
ae9eb32b6899 Refactored 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 from MoinMoin import wikiutil
1087
cdd4e9418547 Added locking to the PickleTagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1047
diff changeset
19 from MoinMoin.util import lock
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
20 from MoinMoin.Page import Page
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
21 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
22
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
23
1303
a0b8e78621d0 Preliminary support for items of different mime types.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1302
diff changeset
24 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
25 # 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
26 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
27
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
28
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
29 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
30 """ 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
31 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
32 """
ae9eb32b6899 Refactored 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 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
34 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
35 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
36 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
37 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
38 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
39 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
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
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
42 class UnsupportedWikiException(Exception): pass
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
43
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
44
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
45 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
46 """ 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
47 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
48 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
49 """ 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
50 @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
51 @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
52 @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
53 @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
54 @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
55 """
ae9eb32b6899 Refactored 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 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
57 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
58 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
59 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
60 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
61 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
62 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
63 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
64 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
65 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
66 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
67 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
68
ae9eb32b6899 Refactored 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 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
70 return repr("<Remote Page %r>" % 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
71
ae9eb32b6899 Refactored 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 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
73 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
74
ae9eb32b6899 Refactored 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 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
76 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
77
ae9eb32b6899 Refactored 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 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
79 """ 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
80 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
81
ae9eb32b6899 Refactored 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 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
83 if not isinstance(other, SyncPage):
ae9eb32b6899 Refactored 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 return false
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
85 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
86
ae9eb32b6899 Refactored 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 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
88 """ 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
89 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
90 """
ae9eb32b6899 Refactored 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 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
92 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
93 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
94 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
95 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
96 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
97 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
98 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
99
ae9eb32b6899 Refactored 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 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
101
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
102 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
103 """ 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
104 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
105 """
ae9eb32b6899 Refactored 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 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
107 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
108
ae9eb32b6899 Refactored 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 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
110 """ 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
111 # 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
112 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
113 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
114 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
115 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
116 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
117 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
118 # 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
119 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
120 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
121 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
122 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
123
ae9eb32b6899 Refactored 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 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
125 """ 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
126 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
127
ae9eb32b6899 Refactored 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 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
129 """ 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
130 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
131
ae9eb32b6899 Refactored 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 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
133 """ 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
134 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
135
ae9eb32b6899 Refactored 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 def iter_local_only(cls, sp_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
137 """ Iterates over all pages that are local only. """
ae9eb32b6899 Refactored 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 for x in sp_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
139 if x.is_only_local():
ae9eb32b6899 Refactored 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 yield x
ae9eb32b6899 Refactored 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 iter_local_only = classmethod(iter_local_only)
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
142
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
143 def iter_remote_only(cls, sp_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
144 """ Iterates over all pages that are remote only. """
ae9eb32b6899 Refactored 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 for x in sp_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
146 if x.is_only_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
147 yield x
ae9eb32b6899 Refactored 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 iter_remote_only = classmethod(iter_remote_only)
ae9eb32b6899 Refactored 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 iter_local_and_remote(cls, sp_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
151 """ Iterates over all pages that are local and 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
152 for x in sp_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
153 if x.is_local_and_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
154 yield x
ae9eb32b6899 Refactored 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 iter_local_and_remote = classmethod(iter_local_and_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
156
ae9eb32b6899 Refactored 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 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
158 """ 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
159 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
160
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
161 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
162 """ 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
163 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
164
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
165 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
166 """ 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
167 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
168
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
169 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
170 """ 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
171 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
172
ae9eb32b6899 Refactored 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 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
174 """ 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
175 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
176
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
177
ae9eb32b6899 Refactored 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 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
179 """ Used for MoinMoin wikis reachable via XMLRPC. """
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
180 def __init__(self, request, interwikiname, 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
181 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
182 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
183 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
184 _ = 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
185
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
186 wikitag, wikiurl, wikitail, wikitag_bad = wikiutil.resolve_wiki(self.request, '%s:""' % (interwikiname, ))
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
187 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
188 self.valid = not wikitag_bad
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
189 self.xmlrpc_url = self.wiki_url + "?action=xmlrpc2"
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
190 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
191 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
192 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
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.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
195
ae9eb32b6899 Refactored 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 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
197 iw_list = self.connection.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 except xmlrpclib.Fault, e:
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
199 raise UnsupportedWikiException(_("The remote version of MoinMoin is too old, the version 1.6 is required at least."))
ae9eb32b6899 Refactored 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
ae9eb32b6899 Refactored 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 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
202 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
203 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
204 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
205 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
206 " 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
207 "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
208
ae9eb32b6899 Refactored 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 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
210 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
211 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
212 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
213
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
214 def createConnection(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
215 return xmlrpclib.ServerProxy(self.xmlrpc_url, allow_none=True, verbose=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
216
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
217 # Public methods
1304
f103cf7c371e Detect renamed pages. Changed the getDiff interface.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1303
diff changeset
218 def get_diff(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
219 """ Returns the binary diff of the remote page named pagename, given
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
220 from_rev and to_rev. """
1304
f103cf7c371e Detect renamed pages. Changed the getDiff interface.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1303
diff changeset
221 try:
f103cf7c371e Detect renamed pages. Changed the getDiff interface.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1303
diff changeset
222 result = self.connection.getDiff(pagename, from_rev, to_rev, n_name)
f103cf7c371e Detect renamed pages. Changed the getDiff interface.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1303
diff changeset
223 except xmlrpclib.Fault, e:
f103cf7c371e Detect renamed pages. Changed the getDiff interface.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1303
diff changeset
224 if e.faultCode == "INVALID_TAG":
f103cf7c371e Detect renamed pages. Changed the getDiff interface.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1303
diff changeset
225 return None
f103cf7c371e Detect renamed pages. Changed the getDiff interface.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1303
diff changeset
226 raise
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
227 result["diff"] = str(result["diff"]) # unmarshal Binary 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
228 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
229
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
230 def merge_diff(self, pagename, diff, local_rev, delta_remote_rev, last_remote_rev, interwiki_name, 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
231 """ Merges the diff into the page on the remote side. """
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
232 result = self.connection.mergeDiff(pagename, xmlrpclib.Binary(diff), local_rev, delta_remote_rev, last_remote_rev, interwiki_name, 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
233 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
234
ae9eb32b6899 Refactored 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 # Methods implementing the RemoteWiki interface
ae9eb32b6899 Refactored 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 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
237 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
238
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
239 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
240 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
241
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
242 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
243 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
244 "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
245 "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
246 "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
247 "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
248 "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
249 "mark_deleted": True}
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
250 pages = self.connection.getAllPagesEx(options)
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
251 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
252 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
253 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
254 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
255 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
256 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
257 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
258 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
259 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
260 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
261
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
262 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
263 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
264
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
265
ae9eb32b6899 Refactored 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 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
267 """ 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
268 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
269 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
270 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
271 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
272
ae9eb32b6899 Refactored 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 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
274 """ 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
275 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
276 for group_pagename in group_list:
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
277 pages.extend(Group(self.request, group_pagename).members())
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
278 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
279
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
280 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
281 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
282 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
283 return None
1296
93ecff3f806f Check for local write permissions early, fixed Python 2.3 incompatiblity.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1295
diff changeset
284 if not self.request.user.may.write(normalised_name):
93ecff3f806f Check for local write permissions early, fixed Python 2.3 incompatiblity.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1295
diff changeset
285 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
286 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
287 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
288 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
289 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
290 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
291
ae9eb32b6899 Refactored 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 # 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
293
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
294 # Methods implementing the RemoteWiki interface
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
295 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
296 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
297
ae9eb32b6899 Refactored 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 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
299 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
300
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
301 def 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
302 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
303 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
304 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
305 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
306 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
307 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
308 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
309 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
310 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
311 else:
16bed977b054 Added support for underlay page ignore and prefix filtering in getAllPagesEx,
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1261
diff changeset
312 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
313 pages = []
1315
ed3baf538cd5 Added infrastructure support for deleted pages in the sync framework.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1304
diff changeset
314 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
315 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
316 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
317 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
318 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
319
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1258
diff changeset
320 def __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
321 return "<MoinLocalWiki>"
1087
cdd4e9418547 Added locking to the PickleTagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1047
diff changeset
322
1026
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
323
1262
16bed977b054 Added support for underlay page ignore and prefix filtering in getAllPagesEx,
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1261
diff changeset
324 # ------------------ Tags ------------------
16bed977b054 Added support for underlay page ignore and prefix filtering in getAllPagesEx,
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1261
diff changeset
325
16bed977b054 Added support for underlay page ignore and prefix filtering in getAllPagesEx,
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1261
diff changeset
326
1022
4e65c6eabe9b Forgot to add the wikisync.py file containing the Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
327 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
328 """ This class is used to store information about merging state. """
1026
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
329
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
330 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
331 """ Creates a new Tag.
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
332
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
333 @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
334 @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
335 @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
336 @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
337 """
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
338 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
339 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
340 and isinstance(normalised_name, basestring))
1026
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
341 self.remote_wiki = remote_wiki
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
342 self.remote_rev = remote_rev
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
343 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
344 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
345 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
346
1036
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
347 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
348 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
349
1136
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1087
diff changeset
350 def __cmp__(self, other):
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1087
diff changeset
351 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
352 return NotImplemented
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1087
diff changeset
353 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
354
1022
4e65c6eabe9b Forgot to add the wikisync.py file containing the Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
355
1026
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
356 class AbstractTagStore(object):
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
357 """ 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
358 that manage the storage of tags. """
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
359
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
360 def __init__(self, page):
1036
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
361 """ 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
362 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
363 pass
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
364
1258
adebc2c73ef7 Added dump method to the AbstractTagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1251
diff changeset
365 def dump(self):
adebc2c73ef7 Added dump method to the AbstractTagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1251
diff changeset
366 """ 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
367 return repr(self.get_all_tags())
adebc2c73ef7 Added dump method to the AbstractTagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1251
diff changeset
368
1026
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
369 def add(self, **kwargs):
1036
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
370 """ 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
371 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
372 return NotImplemented
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
373
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
374 def get_all_tags(self):
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
375 """ 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
376 return NotImplemented
1304
f103cf7c371e Detect renamed pages. Changed the getDiff interface.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1303
diff changeset
377
f103cf7c371e Detect renamed pages. Changed the getDiff interface.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1303
diff changeset
378 def get_last_tag(self):
f103cf7c371e Detect renamed pages. Changed the getDiff interface.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1303
diff changeset
379 """ Returns the newest tag. """
f103cf7c371e Detect renamed pages. Changed the getDiff interface.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1303
diff changeset
380 return NotImplemented
f103cf7c371e Detect renamed pages. Changed the getDiff interface.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1303
diff changeset
381
1047
51086fe55b58 Added clearing to the TagStore, use it in the test.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1036
diff changeset
382 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
383 """ 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
384 return NotImplemented
1026
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
385
1136
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1087
diff changeset
386 def fetch(self, iwid_full=None, iw_name=None):
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1087
diff changeset
387 """ 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
388 return NotImplemented
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1087
diff changeset
389
1026
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
390
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
391 class PickleTagStore(AbstractTagStore):
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
392 """ 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
393
4e65c6eabe9b Forgot to add the wikisync.py file containing the Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
394 def __init__(self, page):
1036
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
395 """ Creates a new TagStore that uses pickle files.
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
396
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
397 @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
398 """
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
399
1022
4e65c6eabe9b Forgot to add the wikisync.py file containing the Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
400 self.page = page
1026
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
401 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
402 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
403 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
404 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
405
1087
cdd4e9418547 Added locking to the PickleTagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1047
diff changeset
406 if not self.rlock.acquire(3.0):
cdd4e9418547 Added locking to the PickleTagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1047
diff changeset
407 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
408 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
409 self.load()
1087
cdd4e9418547 Added locking to the PickleTagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1047
diff changeset
410 finally:
cdd4e9418547 Added locking to the PickleTagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1047
diff changeset
411 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
412
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
413 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
414 """ 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
415 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
416 datafile = file(self.filename, "rb")
1300
59dca7bc1d0f Fixed IOError in the TagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1296
diff changeset
417 self.tags = pickle.load(datafile)
1301
c53381d8527f Fixed EOFError in the TagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1300
diff changeset
418 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
419 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
420 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
421 datafile.close()
1026
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
422
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
423 def commit(self):
1036
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
424 """ 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
425 datafile = file(self.filename, "wb")
1302
7e0faeed44bc Fixed another Python 2.3 incompatibility.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1301
diff changeset
426 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
427 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
428
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
429 # 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
430 def add(self, **kwargs):
1087
cdd4e9418547 Added locking to the PickleTagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1047
diff changeset
431 if not self.wlock.acquire(3.0):
cdd4e9418547 Added locking to the PickleTagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1047
diff changeset
432 raise EnvironmentError("Could not lock in PickleTagStore")
cdd4e9418547 Added locking to the PickleTagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1047
diff changeset
433 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
434 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
435 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
436 self.commit()
1087
cdd4e9418547 Added locking to the PickleTagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1047
diff changeset
437 finally:
cdd4e9418547 Added locking to the PickleTagStore.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1047
diff changeset
438 self.wlock.release()
1026
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
439
1036
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
440 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
441 return self.tags[:]
f103cf7c371e Detect renamed pages. Changed the getDiff interface.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1303
diff changeset
442
f103cf7c371e Detect renamed pages. Changed the getDiff interface.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1303
diff changeset
443 def get_last_tag(self):
f103cf7c371e Detect renamed pages. Changed the getDiff interface.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1303
diff changeset
444 temp = self.tags[:]
f103cf7c371e Detect renamed pages. Changed the getDiff interface.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1303
diff changeset
445 temp.sort()
f103cf7c371e Detect renamed pages. Changed the getDiff interface.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1303
diff changeset
446 if not temp:
f103cf7c371e Detect renamed pages. Changed the getDiff interface.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1303
diff changeset
447 return None
f103cf7c371e Detect renamed pages. Changed the getDiff interface.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1303
diff changeset
448 return temp[-1]
1026
fd0d86823c41 Added working TagStore and Tag classes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1022
diff changeset
449
1047
51086fe55b58 Added clearing to the TagStore, use it in the test.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1036
diff changeset
450 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
451 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
452 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
453 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
454 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
455 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
456 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
457 self.wlock.release()
1036
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
458
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
459 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
460 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
461 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
462 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
463 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
464 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
465 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
466 ) 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
467 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
468 return matching_tags
1136
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1087
diff changeset
469
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1087
diff changeset
470
1036
eac4ea43088e Documented code, fixed bugs.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1026
diff changeset
471 # 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
472 # 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
473 TagStore = PickleTagStore