Merge lp:~zeitgeist/zeitgeist/no-metaclasses into lp:zeitgeist/0.1

Proposed by Siegfried Gevatter
Status: Merged
Merged at revision: 1755
Proposed branch: lp:~zeitgeist/zeitgeist/no-metaclasses
Merge into: lp:zeitgeist/0.1
Diff against target: 251 lines (+91/-113)
1 file modified
zeitgeist/datamodel.py (+91/-113)
To merge this branch: bzr merge lp:~zeitgeist/zeitgeist/no-metaclasses
Reviewer Review Type Date Requested Status
Zeitgeist Framework Team Pending
Review via email: mp+60276@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Seif Lotfy (seif) wrote :
Download full text (14.4 KiB)

looks good

On Sat, May 7, 2011 at 3:57 PM, Siegfried Gevatter <email address hidden>wrote:

> Siegfried Gevatter has proposed merging
> lp:~zeitgeist/zeitgeist/no-metaclasses into lp:zeitgeist.
>
> Requested reviews:
> Zeitgeist Framework Team (zeitgeist)
>
> For more details, see:
> https://code.launchpad.net/~zeitgeist/zeitgeist/no-metaclasses/+merge/60276
> --
> https://code.launchpad.net/~zeitgeist/zeitgeist/no-metaclasses/+merge/60276
> You are subscribed to branch lp:zeitgeist.
>
> === modified file 'zeitgeist/datamodel.py'
> --- zeitgeist/datamodel.py 2011-05-07 13:14:19 +0000
> +++ zeitgeist/datamodel.py 2011-05-07 13:57:28 +0000
> @@ -87,29 +87,6 @@
> Return the current time in milliseconds since the Unix Epoch.
> """
> return int(time.time() * 1000)
> -
> -
> -class enum_factory(object):
> - """factory for enums"""
> - counter = 0
> -
> - def __init__(self, doc):
> - self.__doc__ = doc
> - self._id = enum_factory.counter
> - enum_factory.counter += 1
> -
> -class EnumMeta(type):
> - """Metaclass to register enums in correct order and assign interger
> - values to them
> - """
> - def __new__(cls, name, bases, attributes):
> - enums = filter(
> - lambda x: isinstance(x[1], enum_factory),
> attributes.iteritems()
> - )
> - enums = sorted(enums, key=lambda x: x[1]._id)
> - for n, (key, value) in enumerate(enums):
> - attributes[key] = EnumValue(n, value.__doc__)
> - return super(EnumMeta, cls).__new__(cls, name, bases,
> attributes)
>
> class EnumValue(int):
> """Class which behaves like an int, but has an additional
> docstring"""
> @@ -397,19 +374,8 @@
> result.end = time_range.end
>
> return result
> -
> -
> -class RelevantResultType(object):
> - """
> - An enumeration class used to define how query results should be
> returned
> - from the Zeitgeist engine.
> - """
> - __metaclass__ = EnumMeta
> -
> - Recent = enum_factory("All uris with the most recent uri first")
> - Related = enum_factory("All uris with the most related one first")
> -
> -
> +
> +
> class Subject(list):
> """
> Represents a subject of an :class:`Event`. This class is both used
> to
> @@ -1010,16 +976,23 @@
> def __repr__(self):
> return "%s: %s (%s)" % (self.__class__.__name__,
> self[self.UniqueId],
> self[self.Name])
> -
> -
> +
>
> NULL_EVENT = ([], [], [])
> """Minimal Event representation, a tuple containing three empty lists.
> This `NULL_EVENT` is used by the API to indicate a queried but not
> available (not found or blocked) Event.
> """
> -
> -
> +
> +class RelevantResultType(object):
> + """
> + An enumeration class used to define how query results should be
> returned
> + from the Zeitgeist engine.
> + """
> +
> + Recent = EnumValue(0, "All uris with the most recent uri first")
> + Related = EnumValue(1, "All uris with the most relat...

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'zeitgeist/datamodel.py'
2--- zeitgeist/datamodel.py 2011-05-07 13:14:19 +0000
3+++ zeitgeist/datamodel.py 2011-05-07 13:57:28 +0000
4@@ -87,29 +87,6 @@
5 Return the current time in milliseconds since the Unix Epoch.
6 """
7 return int(time.time() * 1000)
8-
9-
10-class enum_factory(object):
11- """factory for enums"""
12- counter = 0
13-
14- def __init__(self, doc):
15- self.__doc__ = doc
16- self._id = enum_factory.counter
17- enum_factory.counter += 1
18-
19-class EnumMeta(type):
20- """Metaclass to register enums in correct order and assign interger
21- values to them
22- """
23- def __new__(cls, name, bases, attributes):
24- enums = filter(
25- lambda x: isinstance(x[1], enum_factory), attributes.iteritems()
26- )
27- enums = sorted(enums, key=lambda x: x[1]._id)
28- for n, (key, value) in enumerate(enums):
29- attributes[key] = EnumValue(n, value.__doc__)
30- return super(EnumMeta, cls).__new__(cls, name, bases, attributes)
31
32 class EnumValue(int):
33 """Class which behaves like an int, but has an additional docstring"""
34@@ -397,19 +374,8 @@
35 result.end = time_range.end
36
37 return result
38-
39-
40-class RelevantResultType(object):
41- """
42- An enumeration class used to define how query results should be returned
43- from the Zeitgeist engine.
44- """
45- __metaclass__ = EnumMeta
46-
47- Recent = enum_factory("All uris with the most recent uri first")
48- Related = enum_factory("All uris with the most related one first")
49-
50-
51+
52+
53 class Subject(list):
54 """
55 Represents a subject of an :class:`Event`. This class is both used to
56@@ -1010,16 +976,23 @@
57 def __repr__(self):
58 return "%s: %s (%s)" % (self.__class__.__name__, self[self.UniqueId],
59 self[self.Name])
60-
61-
62+
63
64 NULL_EVENT = ([], [], [])
65 """Minimal Event representation, a tuple containing three empty lists.
66 This `NULL_EVENT` is used by the API to indicate a queried but not
67 available (not found or blocked) Event.
68 """
69-
70-
71+
72+class RelevantResultType(object):
73+ """
74+ An enumeration class used to define how query results should be returned
75+ from the Zeitgeist engine.
76+ """
77+
78+ Recent = EnumValue(0, "All uris with the most recent uri first")
79+ Related = EnumValue(1, "All uris with the most related one first")
80+
81 class StorageState(object):
82 """
83 Enumeration class defining the possible values for the storage state
84@@ -1030,89 +1003,94 @@
85 deleted files, files on unplugged USB drives, files available only when
86 a network is available etc.
87 """
88- __metaclass__ = EnumMeta
89
90- NotAvailable = enum_factory(("The storage medium of the events "
91- "subjects must not be available to the user"))
92- Available = enum_factory(("The storage medium of all event subjects "
93- "must be immediately available to the user"))
94- Any = enum_factory("The event subjects may or may not be available")
95-
96+ NotAvailable = EnumValue(0, "The storage medium of the events "
97+ "subjects must not be available to the user")
98+ Available = EnumValue(1, "The storage medium of all event subjects "
99+ "must be immediately available to the user")
100+ Any = EnumValue(2, "The event subjects may or may not be available")
101
102 class ResultType(object):
103 """
104 An enumeration class used to define how query results should be returned
105 from the Zeitgeist engine.
106 """
107- __metaclass__ = EnumMeta
108
109- MostRecentEvents = enum_factory("All events with the most recent events first")
110- LeastRecentEvents = enum_factory("All events with the oldest ones first")
111- MostRecentSubjects = enum_factory(("One event for each subject only, "
112- "ordered with the most recent events first"))
113- LeastRecentSubjects = enum_factory(("One event for each subject only, "
114- "ordered with oldest events first"))
115- MostPopularSubjects = enum_factory(("One event for each subject only, "
116- "ordered by the popularity of the subject"))
117- LeastPopularSubjects = enum_factory(("One event for each subject only, "
118- "ordered ascendingly by popularity of the subject"))
119- MostPopularActor = enum_factory(("The last event of each different actor,"
120- "ordered by the popularity of the actor"))
121- LeastPopularActor = enum_factory(("The last event of each different actor,"
122- "ordered ascendingly by the popularity of the actor"))
123- MostRecentActor = enum_factory(("The Actor that has been used to most recently"))
124- LeastRecentActor = enum_factory(("The Actor that has been used to least recently"))
125- MostRecentOrigin = enum_factory(("The last event of each different subject origin"))
126- LeastRecentOrigin = enum_factory(("The last event of each different subject "
127- "origin, ordered by least recently used first"))
128- MostPopularOrigin = enum_factory(("The last event of each different subject origin,"
129- "ordered by the popularity of the origins"))
130- LeastPopularOrigin = enum_factory(("The last event of each different subject origin,"
131- "ordered ascendingly by the popularity of the origin"))
132- OldestActor = enum_factory(("The first event of each different actor"))
133- MostRecentSubjectInterpretation = enum_factory(("One event for each subject interpretation only, "
134- "ordered with the most recent events first"))
135- LeastRecentSubjectInterpretation = enum_factory(("One event for each subject interpretation only, "
136- "ordered with the least recent events first"))
137- MostPopularSubjectInterpretation = enum_factory(("One event for each subject interpretation only, "
138- "ordered by the popularity of the subject interpretation"))
139- LeastPopularSubjectInterpretation = enum_factory(("One event for each subject interpretation only, "
140- "ordered ascendingly by popularity of the subject interpretation"))
141- MostRecentMimeType = enum_factory(("One event for each mimetype only, "
142- "ordered with the most recent events first"))
143- LeastRecentMimeType = enum_factory(("One event for each mimetype only, "
144- "ordered with the least recent events first"))
145- MostPopularMimeType = enum_factory(("One event for each mimetype only, "
146- "ordered by the popularity of the mimetype"))
147- LeastPopularMimeType = enum_factory(("One event for each mimetype only, "
148- "ordered ascendingly by popularity of the mimetype"))
149- MostRecentCurrentUri = enum_factory(("One event for each subject only "
150- "(by current_uri instead of uri), "
151- "ordered with the most recent events first"))
152- LeastRecentCurrentUri = enum_factory(("One event for each subject only "
153- "(by current_uri instead of uri), "
154- "ordered with oldest events first"))
155- MostPopularCurrentUri = enum_factory(("One event for each subject only "
156- "(by current_uri instead of uri), "
157- "ordered by the popularity of the subject"))
158- LeastPopularCurrentUri = enum_factory(("One event for each subject only "
159- "(by current_uri instead of uri), "
160- "ordered ascendingly by popularity of the subject"))
161- MostRecentEventOrigin = enum_factory(("The last event of each different origin"))
162- LeastRecentEventOrigin = enum_factory(("The last event of each different "
163- " origin, ordered by least recently used first"))
164- MostPopularEventOrigin = enum_factory(("The last event of each different origin,"
165- "ordered by the popularity of the origins"))
166- LeastPopularEventOrigin = enum_factory(("The last event of each different origin,"
167- "ordered ascendingly by the popularity of the origin"))
168+ MostRecentEvents = EnumValue(0,
169+ "All events with the most recent events first")
170+ LeastRecentEvents = EnumValue(1, "All events with the oldest ones first")
171+ MostRecentSubjects = EnumValue(2, "One event for each subject only, "
172+ "ordered with the most recent events first")
173+ LeastRecentSubjects = EnumValue(3, "One event for each subject only, "
174+ "ordered with oldest events first")
175+ MostPopularSubjects = EnumValue(4, "One event for each subject only, "
176+ "ordered by the popularity of the subject")
177+ LeastPopularSubjects = EnumValue(5, "One event for each subject only, "
178+ "ordered ascendingly by popularity of the subject")
179+ MostPopularActor = EnumValue(6, "The last event of each different actor,"
180+ "ordered by the popularity of the actor")
181+ LeastPopularActor = EnumValue(7, "The last event of each different actor,"
182+ "ordered ascendingly by the popularity of the actor")
183+ MostRecentActor = EnumValue(8,
184+ "The Actor that has been used to most recently")
185+ LeastRecentActor = EnumValue(9,
186+ "The Actor that has been used to least recently")
187+ MostRecentOrigin = EnumValue(10,
188+ "The last event of each different subject origin")
189+ LeastRecentOrigin = EnumValue(11, "The last event of each different "
190+ "subject origin, ordered by least recently used first")
191+ MostPopularOrigin = EnumValue(12, "The last event of each different "
192+ "subject origin, ordered by the popularity of the origins")
193+ LeastPopularOrigin = EnumValue(13, "The last event of each different "
194+ "subject origin, ordered ascendingly by the popularity of the origin")
195+ OldestActor = EnumValue(14, "The first event of each different actor")
196+ MostRecentSubjectInterpretation = EnumValue(15, "One event for each "
197+ "subject interpretation only, ordered with the most recent "
198+ "events first")
199+ LeastRecentSubjectInterpretation = EnumValue(16, "One event for each "
200+ "subject interpretation only, ordered with the least recent "
201+ "events first")
202+ MostPopularSubjectInterpretation = EnumValue(17, "One event for each "
203+ "subject interpretation only, ordered by the popularity of the "
204+ "subject interpretation")
205+ LeastPopularSubjectInterpretation = EnumValue(18, "One event for each "
206+ "subject interpretation only, ordered ascendingly by popularity of "
207+ "the subject interpretation")
208+ MostRecentMimeType = EnumValue(19, "One event for each mimetype only, "
209+ "ordered with the most recent events first")
210+ LeastRecentMimeType = EnumValue(20, "One event for each mimetype only, "
211+ "ordered with the least recent events first")
212+ MostPopularMimeType = EnumValue(21, "One event for each mimetype only, "
213+ "ordered by the popularity of the mimetype")
214+ LeastPopularMimeType = EnumValue(22, "One event for each mimetype only, "
215+ "ordered ascendingly by popularity of the mimetype")
216+ MostRecentCurrentUri = EnumValue(23, "One event for each subject only "
217+ "(by current_uri instead of uri), "
218+ "ordered with the most recent events first")
219+ LeastRecentCurrentUri = EnumValue(24, "One event for each subject only "
220+ "(by current_uri instead of uri), "
221+ "ordered with oldest events first")
222+ MostPopularCurrentUri = EnumValue(25, "One event for each subject only "
223+ "(by current_uri instead of uri), "
224+ "ordered by the popularity of the subject")
225+ LeastPopularCurrentUri = EnumValue(26, "One event for each subject only "
226+ "(by current_uri instead of uri), "
227+ "ordered ascendingly by popularity of the subject")
228+ MostRecentEventOrigin = EnumValue(27,
229+ "The last event of each different origin")
230+ LeastRecentEventOrigin = EnumValue(28, "The last event of each "
231+ " different origin, ordered by least recently used first")
232+ MostPopularEventOrigin = EnumValue(29, "The last event of each "
233+ "different origin, ordered by the popularity of the origins")
234+ LeastPopularEventOrigin = EnumValue(30, "The last event of each "
235+ "different origin, ordered ascendingly by the popularity of the origin")
236
237 # We should eventually migrate over to those names to disambiguate
238- # subject origin and event origin
239- # FIXME: this is breaking badly
240- #MostRecentSubjectOrigin = MostRecentOrigin
241- #LeastRecentSubjectOrigin = LeastRecentOrigin
242- #MostPopularSubjectOrigin = MostPopularOrigin
243- #LeastPopularSubjectOrigin = LeastPopularOrigin
244+ # subject origin and event origin:
245+ MostRecentSubjectOrigin = MostRecentOrigin
246+ LeastRecentSubjectOrigin = LeastRecentOrigin
247+ MostPopularSubjectOrigin = MostPopularOrigin
248+ LeastPopularSubjectOrigin = LeastPopularOrigin
249
250 INTERPRETATION_DOC = \
251 """In general terms the *interpretation* of an event or subject is an abstract