85
87
Return the current time in milliseconds since the Unix Epoch.
87
89
return int(time.time() * 1000)
90
class enum_factory(object):
91
"""factory for enums"""
94
def __init__(self, doc):
96
self._id = enum_factory.counter
97
enum_factory.counter += 1
100
class EnumMeta(type):
101
"""Metaclass to register enums in correct order and assign interger
104
def __new__(cls, name, bases, attributes):
106
lambda x: isinstance(x[1], enum_factory), attributes.iteritems()
108
enums = sorted(enums, key=lambda x: x[1]._id)
109
for n, (key, value) in enumerate(enums):
110
attributes[key] = EnumValue(n, value.__doc__)
111
return super(EnumMeta, cls).__new__(cls, name, bases, attributes)
114
91
class EnumValue(int):
115
"""class which behaves like an int, but has an additional docstring"""
92
"""Class which behaves like an int, but has an additional docstring"""
116
94
def __new__(cls, value, doc=""):
117
95
obj = super(EnumValue, cls).__new__(EnumValue, value)
118
96
obj.__doc__ = "%s. ``(Integer value: %i)``" %(doc, obj)
124
def __init__(self, docstring):
125
self.__doc__ = str(docstring)
128
def __getattr__(self, name):
130
return self.__enums[name]
134
def register(self, value, name, docstring):
135
ids = map(int, self.__enums.values())
136
if value in ids or name in self.__enums:
138
self.__enums[name] = EnumValue(value, docstring)
141
99
def isCamelCase(text):
142
100
return text and text[0].isupper() and " " not in text
144
102
def get_name_or_str(obj):
146
104
return str(obj.name)
999
1003
deleted files, files on unplugged USB drives, files available only when
1000
1004
a network is available etc.
1002
__metaclass__ = EnumMeta
1004
NotAvailable = enum_factory(("The storage medium of the events "
1005
"subjects must not be available to the user"))
1006
Available = enum_factory(("The storage medium of all event subjects "
1007
"must be immediately available to the user"))
1008
Any = enum_factory("The event subjects may or may not be available")
1007
NotAvailable = EnumValue(0, "The storage medium of the events "
1008
"subjects must not be available to the user")
1009
Available = EnumValue(1, "The storage medium of all event subjects "
1010
"must be immediately available to the user")
1011
Any = EnumValue(2, "The event subjects may or may not be available")
1011
1013
class ResultType(object):
1013
1015
An enumeration class used to define how query results should be returned
1014
1016
from the Zeitgeist engine.
1016
__metaclass__ = EnumMeta
1018
MostRecentEvents = enum_factory("All events with the most recent events first")
1019
LeastRecentEvents = enum_factory("All events with the oldest ones first")
1020
MostRecentSubjects = enum_factory(("One event for each subject only, "
1021
"ordered with the most recent events first"))
1022
LeastRecentSubjects = enum_factory(("One event for each subject only, "
1023
"ordered with oldest events first"))
1024
MostPopularSubjects = enum_factory(("One event for each subject only, "
1025
"ordered by the popularity of the subject"))
1026
LeastPopularSubjects = enum_factory(("One event for each subject only, "
1027
"ordered ascendingly by popularity of the subject"))
1028
MostPopularActor = enum_factory(("The last event of each different actor,"
1029
"ordered by the popularity of the actor"))
1030
LeastPopularActor = enum_factory(("The last event of each different actor,"
1031
"ordered ascendingly by the popularity of the actor"))
1032
MostRecentActor = enum_factory(("The Actor that has been used to most recently"))
1033
LeastRecentActor = enum_factory(("The Actor that has been used to least recently"))
1034
MostRecentOrigin = enum_factory(("The last event of each different origin"))
1035
LeastRecentOrigin = enum_factory(("The first event of each different origin"))
1036
MostPopularOrigin = enum_factory(("The last event of each different origin,"
1037
"ordered by the popularity of the origins"))
1038
LeastPopularOrigin = enum_factory(("The last event of each different origin,"
1039
"ordered ascendingly by the popularity of the origin"))
1040
OldestActor = enum_factory(("The first event of each different actor"))
1041
MostRecentSubjectInterpretation = enum_factory(("One event for each subject interpretation only, "
1042
"ordered with the most recent events first"))
1043
LeastRecentSubjectInterpretation = enum_factory(("One event for each subject interpretation only, "
1044
"ordered with the least recent events first"))
1045
MostPopularSubjectInterpretation = enum_factory(("One event for each subject interpretation only, "
1046
"ordered by the popularity of the subject interpretation"))
1047
LeastPopularSubjectInterpretation = enum_factory(("One event for each subject interpretation only, "
1048
"ordered ascendingly by popularity of the subject interpretation"))
1049
MostRecentMimeType = enum_factory(("One event for each mimetype only, "
1050
"ordered with the most recent events first"))
1051
LeastRecentMimeType = enum_factory(("One event for each mimetype only, "
1052
"ordered with the least recent events first"))
1053
MostPopularMimeType = enum_factory(("One event for each mimetype only, "
1054
"ordered by the popularity of the mimetype"))
1055
LeastPopularMimeType = enum_factory(("One event for each mimetype only, "
1056
"ordered ascendingly by popularity of the mimetype"))
1019
MostRecentEvents = EnumValue(0,
1020
"All events with the most recent events first")
1021
LeastRecentEvents = EnumValue(1, "All events with the oldest ones first")
1022
MostRecentSubjects = EnumValue(2, "One event for each subject only, "
1023
"ordered with the most recent events first")
1024
LeastRecentSubjects = EnumValue(3, "One event for each subject only, "
1025
"ordered with oldest events first")
1026
MostPopularSubjects = EnumValue(4, "One event for each subject only, "
1027
"ordered by the popularity of the subject")
1028
LeastPopularSubjects = EnumValue(5, "One event for each subject only, "
1029
"ordered ascendingly by popularity of the subject")
1030
MostPopularActor = EnumValue(6, "The last event of each different actor,"
1031
"ordered by the popularity of the actor")
1032
LeastPopularActor = EnumValue(7, "The last event of each different actor,"
1033
"ordered ascendingly by the popularity of the actor")
1034
MostRecentActor = EnumValue(8,
1035
"The Actor that has been used to most recently")
1036
LeastRecentActor = EnumValue(9,
1037
"The Actor that has been used to least recently")
1038
MostRecentOrigin = EnumValue(10,
1039
"The last event of each different subject origin")
1040
LeastRecentOrigin = EnumValue(11, "The last event of each different "
1041
"subject origin, ordered by least recently used first")
1042
MostPopularOrigin = EnumValue(12, "The last event of each different "
1043
"subject origin, ordered by the popularity of the origins")
1044
LeastPopularOrigin = EnumValue(13, "The last event of each different "
1045
"subject origin, ordered ascendingly by the popularity of the origin")
1046
OldestActor = EnumValue(14, "The first event of each different actor")
1047
MostRecentSubjectInterpretation = EnumValue(15, "One event for each "
1048
"subject interpretation only, ordered with the most recent "
1050
LeastRecentSubjectInterpretation = EnumValue(16, "One event for each "
1051
"subject interpretation only, ordered with the least recent "
1053
MostPopularSubjectInterpretation = EnumValue(17, "One event for each "
1054
"subject interpretation only, ordered by the popularity of the "
1055
"subject interpretation")
1056
LeastPopularSubjectInterpretation = EnumValue(18, "One event for each "
1057
"subject interpretation only, ordered ascendingly by popularity of "
1058
"the subject interpretation")
1059
MostRecentMimeType = EnumValue(19, "One event for each mimetype only, "
1060
"ordered with the most recent events first")
1061
LeastRecentMimeType = EnumValue(20, "One event for each mimetype only, "
1062
"ordered with the least recent events first")
1063
MostPopularMimeType = EnumValue(21, "One event for each mimetype only, "
1064
"ordered by the popularity of the mimetype")
1065
LeastPopularMimeType = EnumValue(22, "One event for each mimetype only, "
1066
"ordered ascendingly by popularity of the mimetype")
1067
MostRecentCurrentUri = EnumValue(23, "One event for each subject only "
1068
"(by current_uri instead of uri), "
1069
"ordered with the most recent events first")
1070
LeastRecentCurrentUri = EnumValue(24, "One event for each subject only "
1071
"(by current_uri instead of uri), "
1072
"ordered with oldest events first")
1073
MostPopularCurrentUri = EnumValue(25, "One event for each subject only "
1074
"(by current_uri instead of uri), "
1075
"ordered by the popularity of the subject")
1076
LeastPopularCurrentUri = EnumValue(26, "One event for each subject only "
1077
"(by current_uri instead of uri), "
1078
"ordered ascendingly by popularity of the subject")
1079
MostRecentEventOrigin = EnumValue(27,
1080
"The last event of each different origin")
1081
LeastRecentEventOrigin = EnumValue(28, "The last event of each "
1082
" different origin, ordered by least recently used first")
1083
MostPopularEventOrigin = EnumValue(29, "The last event of each "
1084
"different origin, ordered by the popularity of the origins")
1085
LeastPopularEventOrigin = EnumValue(30, "The last event of each "
1086
"different origin, ordered ascendingly by the popularity of the origin")
1088
# We should eventually migrate over to those names to disambiguate
1089
# subject origin and event origin:
1090
MostRecentSubjectOrigin = MostRecentOrigin
1091
LeastRecentSubjectOrigin = LeastRecentOrigin
1092
MostPopularSubjectOrigin = MostPopularOrigin
1093
LeastPopularSubjectOrigin = LeastPopularOrigin
1059
1095
INTERPRETATION_DOC = \
1060
1096
"""In general terms the *interpretation* of an event or subject is an abstract
1148
1184
print "Success"
1149
1185
end_symbols = time.time()
1150
1186
print >> sys.stderr, "Import time: %s" % (end_symbols - start_symbols)
1151
#~ x = len(Interpretation.get_all_children())
1152
#~ y = len(Manifestation.get_all_children())
1153
#~ print >> sys.stderr, \
1154
#~ ("Overall number of symbols: %i (man.: %i, int.: %i)" %(x+y, y, x))
1155
#~ print >> sys.stderr, ("Resolved %i symbols, needed %i iterations" %(initial_count, initial_count-c))
1156
#~ print >> sys.stderr, ("Loading symbols took %.4f seconds" %(end_symbols - start_symbols))
1159
#~ EventManifestation = Manifestation.EventManifestation
1160
#~ EventInterpretation = Interpretation.EventInterpretation
1162
#~ DataContainer = Interpretation.DataContainer
1165
#~ print dir(EventManifestation)
1166
#~ print dir(Manifestation)
1167
#~ print EventManifestation.UserActivity
1169
#~ print DataContainer
1170
#~ print DataContainer.Filesystem
1171
#~ print DataContainer.Filesystem.__doc__
1173
#~ print " OR ".join(DataContainer.get_all_children())
1174
#~ print " OR ".join(DataContainer.Filesystem.get_all_children())
1176
#~ print DataContainer.Boo
1178
#~ #Symbol("BOO", DataContainer) #must fail with ValueError
1179
#~ #Symbol("Boo", DataContainer) #must fail with ValueError
1180
#~ Symbol("Foo", set([DataContainer,]))
1181
#~ print DataContainer.Foo
1183
#~ #DataContainer._add_child("booo") #must fail with TypeError
1185
#~ print Interpretation
1186
#~ #print Interpretation.get_all_children()
1188
#~ pprint.pprint(Interpretation.Software.get_all_children())
1190
#~ print Interpretation["http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#MindMap"]