1 import logging
2 log = logging.getLogger("datatypes.DataType")
3
4 import conduit.datatypes
5
6 CHANGE_UNMODIFIED = 0
7 CHANGE_ADDED = 1
8 CHANGE_MODIFIED = 2
9 CHANGE_DELETED = 3
10
12 """
13 Base DataType which represents any thing
14 which can be synchronized between two DataProviders
15
16 @cvar _name_: The name of the type
17 @type _name_: C{string}
18 @ivar URI: A URI which uniquely represents the location of the datatype.
19 @type URI: C{string}
20 @ivar UID: A Unique identifier for this type. This is particuarly
21 neccessary on types that are used in two-way sync.
22 @type UID: C{string}
23 """
24
25 _name_ = ""
26
28 self.change_type = CHANGE_UNMODIFIED
29
30 self._original_URI = None
31 self._mtime = None
32 self._UID = None
33 self._tags = ()
34
36 """
37 @returns: The type (name) of this datatype
38 @rtype: C{string}
39 """
40 return self._name_
41
43 """
44 Comparison function to be overridden by datatypes who support two
45 way synchronisation.
46
47 This funcion should compare self with B. All answers
48 are from the perspective of the me (the instance)
49
50 - C{conduit.datatypes.COMPARISON_NEWER} This means the I am newer than B
51 - C{conduit.datatypes.COMPARISON_EQUAL} This means the we are equal
52 - L{conduit.datatypes.COMPARISON_OLDER} This means the I am older than B
53 - L{conduit.datatypes.COMPARISON_UNKNOWN} This means we were unable to determine
54 which was newer than the other so its up to the user to decide
55 """
56 log.debug("COMPARE: %s <----> %s " % (self.get_UID(), B.get_UID()))
57
58 if self.get_rid() == B.get_rid():
59 return conduit.datatypes.COMPARISON_EQUAL
60
61 mtime1 = self.get_mtime()
62 mtime2 = B.get_mtime()
63
64 if mtime1 == None or mtime2 == None:
65 return conduit.datatypes.COMPARISON_UNKNOWN
66
67 if mtime1 > mtime2:
68 return conduit.datatypes.COMPARISON_NEWER
69 else:
70 return conduit.datatypes.COMPARISON_OLDER
71
73 raise NotImplementedError
74
76 """
77 Returns the UID of the datatype
78 """
79 return self._UID
80
82 """
83 Sets the UID of the datatype
84 @type UID: C{string}
85 """
86 self._UID = UID
87
89 """
90 Sets the modification time of the datatype.
91 @type mtime: C{datetime.datetime}
92 """
93 self._mtime = mtime
94
96 """
97 @returns: The file modification time (or None) as a python datetime object
98 @rtype: C{datetime.datetime}
99 """
100 return self._mtime
101
107
113
115 """
116 @returns: The URI that can be opened through gnome-open (or None)
117 """
118 return self._original_URI
119
121 """
122 Saves the URI that can be opened through gnome-open
123 """
124 self._original_URI = URI
125
127 """
128 Returns a small representation of the data that may be shown to the
129 user. Derived types may override this function.
130 """
131 s = ""
132 uri = self.get_open_URI()
133 mtime = self.get_mtime()
134
135 if uri != None:
136 s += "%s" % uri
137 if mtime != None:
138 s += " (%s)" % mtime.strftime("%c")
139
140 if s == "":
141 s += "%s" % str(self)
142 else:
143 s += "\n%s" % str(self)
144
145 return s
146
158
160 """
161 Store the object state in a dict for pickling
162 """
163 data = {}
164 data['mtime'] = self.get_mtime()
165 data['uid'] = self.get_UID()
166 data['open_uri'] = self.get_open_URI()
167 data['tags'] = self.get_tags()
168 return data
169
171 """
172 Set object state from dict (after unpickling)
173 """
174 self.set_mtime(data['mtime'])
175 self.set_UID(data['uid'])
176 self.set_open_URI(data['open_uri'])
177 self.set_tags(data['tags'])
178