本文整理匯總了Python中zeitgeist.datamodel.Subject類的典型用法代碼示例。如果您正苦於以下問題:Python Subject類的具體用法?Python Subject怎麽用?Python Subject使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Subject類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: handle_VM_SHARE_CREATED
def handle_VM_SHARE_CREATED(self, share_id):
"""Log the share accepted event."""
share = self.vm.shares[share_id]
folder = Subject.new_for_values(
uri=URI_PROTOCOL_U1 + str(share.node_id),
interpretation=Interpretation.FOLDER,
manifestation=Manifestation.REMOTE_DATA_OBJECT,
origin="file:///" + share.path,
text=basename(share.path),
mimetype=DIRECTORY_MIMETYPE,
storage=STORAGE_NETWORK)
other_username = share.other_username
other_user = Subject.new_for_values(
uri="mailto:" + other_username,
interpretation=INTERPRETATION_U1_CONTACT,
text=other_username,
manifestation=MANIFESTATION_U1_CONTACT_DATA_OBJECT)
event = Event.new_for_values(
interpretation=EVENT_INTERPRETATION_U1_SHARE_ACCEPTED,
manifestation=Manifestation.USER_ACTIVITY,
actor=ACTOR_UBUNTUONE,
subjects=[folder, other_user])
self.zg.log(event)
示例2: log_folder_shared
def log_folder_shared(self, share, share_id):
"""Log the 'directory shared' event."""
fullpath = share.path
folder_name = basename(fullpath)
folder = Subject.new_for_values(
uri=URI_PROTOCOL_U1 + str(share.node_id),
interpretation=Interpretation.FOLDER,
manifestation=Manifestation.REMOTE_DATA_OBJECT,
origin="file:///" + fullpath,
text=folder_name,
mimetype=DIRECTORY_MIMETYPE,
storage=STORAGE_NETWORK)
other_username = share.other_username
other_user = Subject.new_for_values(
uri="mailto:" + other_username,
interpretation=INTERPRETATION_U1_CONTACT,
text=other_username,
manifestation=MANIFESTATION_U1_CONTACT_DATA_OBJECT)
event = Event.new_for_values(
interpretation=EVENT_INTERPRETATION_U1_FOLDER_SHARED,
manifestation=Manifestation.USER_ACTIVITY,
actor=ACTOR_UBUNTUONE,
subjects=[folder, other_user])
self.zg.log(event)
示例3: register_message_event
def register_message_event(self, ac_id, who, msg, event_info):
subject = Subject.new_for_values(
uri="pidgin://%s/%s" % (ac_id, who),
interpretation=unicode(Interpretation.IMMESSAGE),
manifestation=unicode(Manifestation.SOFTWARE_SERVICE),
origin="pidgin://%s" % (ac_id,),
mimetype="text/plain",
storage="local",
text="%s" % (self._strip_tags(msg)))
subjects = [subject]
uris = URIS.findall(self._strip_tags(msg))
for link in uris:
if uris.count(link) == 1:
subject = Subject.new_for_values(
uri=link,
interpretation=unicode(Interpretation.WEBSITE),
manifestation=unicode(#WEB if match http
Manifestation.WEB_DATA_OBJECT if HTTP.match(link)\
#File if match file
else Manifestation.FILE_DATA_OBJECT if FILE.match(link)\
#something else
else Manifestation.FILE_DATA_OBJECT.REMOTE_DATA_OBJECT
),
origin=origin_from_uri(link),
storage=storage_from_uri(link),
text=link)
subjects.append(subject)
else:
uris.remove(link)
event_info['subjects'] = subjects
event_info['timestamp'] = int(time.time() * 1000)
event_info['actor'] = 'application://pidgin.desktop'
self.zclient.insert_event_for_values(**event_info)
self.event_sent(ac_id, who, msg, event_info)
示例4: _on_view_pages
def _on_view_pages(self, widget):
self.home.reset()
uris = []
for pIndex in xrange(self.pages.get_n_pages()):
self.pages.set_current_page(pIndex)
page = self.pages.get_nth_page(pIndex)
overviewPage = PageOverviewWidget(page)
overviewPage.connect("clicked", self._on_page_clicked)
self.home.add_page(overviewPage)
uris.append(page.webview.get_uri())
self.home.show_all()
self.box.set_current_page(0)
def callback(events):
self.home.recentDashboard.recentPages.reset()
for event in events:
page = PageButton(event.subjects[0])
print event.subjects[0].uri
self.home.recentDashboard.recentPages.add_page(page)
self.home.show_all()
event = Event()
event.actor = "application://web.desktop"
event.subjects = []
for uri in uris:
if uri:
subject = Subject()
subject.uri = "!"+uri
event.subjects.append(subject)
print event
ZG.find_events_for_template(event, callback, result_type=2)
示例5: testFindEventIdsWithMultipleSubjects
def testFindEventIdsWithMultipleSubjects(self):
subj1 = Subject.new_for_values(uri="file:///tmp/foo.txt")
subj2 = Subject.new_for_values(uri="file:///tmp/loo.txt")
event = new_event(subjects=[subj1, subj2])
orig_ids = self.insertEventsAndWait([event])
result_ids = self.findEventIdsAndWait([Event()], num_events=0,
result_type=ResultType.LeastRecentEvents)
self.assertEquals(orig_ids, list(result_ids))
示例6: testFindMultipleEvents
def testFindMultipleEvents(self):
import_events("test/data/five_events.js", self)
subj1 = Subject.new_for_values(uri="file:///home/foo.txt")
event_template1 = Event.new_for_values(subjects=[subj1])
subj2 = Subject.new_for_values(uri="file:///tmp/foo.txt")
event_template2 = Event.new_for_values(subjects=[subj2])
result = self.findEventIdsAndWait([event_template1, event_template2], num_events=0, result_type=4)
self.assertEquals(2, len(result))
events = self.getEventsAndWait(result)
示例7: _get_base_template
def _get_base_template(self):
base_template = Event()
if self.has_uri:
subj = Subject()
subj.set_uri(self.uri+"/*")
base_template.set_subjects([subj])
else:
base_template.set_actor(self.uri)
return base_template
示例8: testGetWithMultipleSubjects
def testGetWithMultipleSubjects(self):
subj1 = Subject.new_for_values(uri="file:///tmp/foo.txt")
subj2 = Subject.new_for_values(uri="file:///tmp/loo.txt")
event = new_event(subjects=[subj1, subj2])
result = self.insertEventsAndWait([event])
events = self.getEventsAndWait(result)
self.assertEquals(2, len(events[0].subjects))
self.assertEquals("file:///tmp/foo.txt", events[0].subjects[0].uri)
self.assertEquals("file:///tmp/loo.txt", events[0].subjects[1].uri)
示例9: handle_recent
def handle_recent(results):
self.recent = []
for event in results:
if exists(event.subjects[0].uri):
self.recent.append([event.subjects[0].uri, event.subjects[0].text])
subj = Subject()
subj.uri = "!"+event.subjects[0].uri
template.subjects.append(subj)
if len(self.recent) >= 5:
break
CLIENT.find_events_for_templates([template], handle_most, num_events = 1000, result_type = 4)
示例10: send_to_zeitgeist
def send_to_zeitgeist(self, db, entry, event_type):
song = self.get_song_info(db, entry)
if self.__manual_switch:
manifest = Manifestation.USER_ACTIVITY
else:
manifest = Manifestation.SCHEDULED_ACTIVITY
subject = Subject.new_for_values(
uri=song["location"],
interpretation=unicode(Interpretation.AUDIO),
manifestation=unicode(Manifestation.FILE_DATA_OBJECT),
#~ origin="", #TBD
mimetype=song["mimetype"],
text=" - ".join([song["title"], song["artist"], song["album"]])
)
event = Event.new_for_values(
timestamp=int(time.time()*1000),
interpretation=unicode(event_type),
manifestation=unicode(manifest),
actor="application://rhythmbox.desktop",
subjects=[subject,]
)
#print event
IFACE.insert_event(event)
示例11: handle_AQ_UNLINK_OK
def handle_AQ_UNLINK_OK(self, share_id, parent_id, node_id,
new_generation, was_dir, old_path):
"""A file or folder was deleted on the server by Syncdaemon,"""
if was_dir:
mime, interp = DIRECTORY_MIMETYPE, Interpretation.FOLDER
else:
mime, interp = self.get_mime_and_interpretation_for_filepath(
old_path)
file_subject = Subject.new_for_values(
uri=URI_PROTOCOL_U1 + str(node_id),
interpretation=interp,
manifestation=Manifestation.DELETED_RESOURCE,
origin="file:///" + old_path,
text=basename(old_path),
mimetype=mime,
storage=STORAGE_DELETED)
event = Event.new_for_values(
interpretation=Interpretation.DELETE_EVENT,
manifestation=Manifestation.SCHEDULED_ACTIVITY,
actor=ACTOR_UBUNTUONE,
subjects=[file_subject])
self.zg.log(event)
示例12: buildQuery
def buildQuery(chromosome):
storage = StorageState.Any
numResults = 10
if chromosome[0] == 0 or chromosome[1] == 0:
timerange = TimeRange.always()
else:
timerange = (chromosome[0]*60*60*24, chromosome[1]*60*60*24)
if timerange[0] > timerange[1]:
timerange = (timerange[1], timerange[0])
searchType = chromosome[2]%30
eventTemplate = {}
subjectTemplate = {}
if chromosome[3]%2 == 0:
subjectTemplate['interpretation'] = random.choice(list(Interpretation.EVENT_INTERPRETATION.get_children()))
if chromosome[4]%2 == 0:
subjectTemplate['manifestation'] = random.choice(list(Manifestation.EVENT_MANIFESTATION.get_children()))
if chromosome[5]%2 == 0:
eventTemplate['actor'] = "application://google-chrome.desktop"
if chromosome[6]%2 == 0:
subjectTemplate['origin'] = "http://google.com"
if chromosome[7]%2 == 0:
subjectTemplate['uri'] = "http://google.com"
if chromosome[8]%2 == 0:
subjectTemplate['mimetype'] = "text/html"
if chromosome[9]%2 == 0:
subjectTemplate['text'] = "fish"
if chromosome[10]%2 == 0:
eventTemplate['manifestation'] = random.choice(list(Manifestation.EVENT_MANIFESTATION.get_children()))
if chromosome[11]%2 == 0:
eventTemplate['interpretation'] = random.choice(list(Interpretation.EVENT_INTERPRETATION.get_children()))
templates = [Event.new_for_values(subjects=[Subject.new_for_values(**subjectTemplate)], **eventTemplate)]
return (timerange, templates, storage, numResults, searchType)
示例13: onNewTrack
def onNewTrack(self, track):
""" Send track information to Zeitgeist """
import mimetypes, os.path
from zeitgeist.datamodel import Event, Subject, Interpretation, Manifestation
mime, encoding = mimetypes.guess_type(track.getFilePath(), strict=False)
subject = Subject.new_for_values(
uri = os.path.dirname(track.getURI()),
text = track.getTitle() + ' - ' + track.getArtist() + ' - ' + track.getExtendedAlbum(),
mimetype = mime,
manifestation = unicode(Manifestation.FILE),
interpretation = unicode(Interpretation.AUDIO),
)
if hasattr(Interpretation, 'ACCESS_EVENT'):
eventType = Interpretation.ACCESS_EVENT
else:
eventType = Interpretation.OPEN_EVENT
event = Event.new_for_values(
actor = "application://decibel-audio-player.desktop",
subjects = [subject,],
interpretation = eventType,
)
self.client.insert_event(event)
示例14: create_and_send_event
def create_and_send_event(self, page, event_type):
if not self.zeitgeist_client:
return
if not hasattr(page, 'source') \
or not isinstance(page.source, File):
return
uri = page.source.uri
origin = gio.File(uri).get_parent().get_uri()
text = _('Wiki page: %s') % page.name
# T: label for how zim pages show up in the recent files menu, %s is the page name
subject = Subject.new_for_values(mimetype='text/x-zim-wiki',
uri=uri,
origin=origin,
interpretation=Interpretation.TEXT_DOCUMENT,
manifestation=Manifestation.FILE_DATA_OBJECT,
text=text)
event = Event.new_for_values(actor='application://zim.desktop',
interpretation=event_type,
manifestation=Manifestation.USER_ACTIVITY,
subjects=[subject,])
self.zeitgeist_client.insert_event(event)
示例15: testUnicodeEventInsert
def testUnicodeEventInsert(self):
# Insert and get a unicode event
ids = import_events("test/data/unicode_event.js", self)
self.assertEquals(len(ids), 1)
result = self.getEventsAndWait(ids)
self.assertEquals(1, len(result))
event = result[0]
self.assertEquals(1, len(event.subjects))
self.assertEquals(u"hällö, I'm gürmen - åge drikker øl - ☠", event.subjects[0].text)
self.assertEquals(u"http://live.gnome.org/☠", event.subjects[0].uri)
# Update the event we got from the DB's timestamp and insert
# it again, we want to to test some ping-pong back and forth
event[0][Event.Id] = ""
event.timestamp = "243"
ids = self.insertEventsAndWait([event])
result = self.getEventsAndWait(ids)
self.assertEquals(1, len(result))
event = result[0]
self.assertEquals(1, len(event.subjects))
self.assertEquals(u"hällö, I'm gürmen - åge drikker øl - ☠", event.subjects[0].text)
self.assertEquals(u"http://live.gnome.org/☠", event.subjects[0].uri)
# Try and find a unicode event
subj = Subject.new_for_values(text="hällö, I'm gürmen - åge drikker øl - ☠",
origin="file:///åges_øl í", uri=u"http://live.gnome.org/☠")
event_template = Event.new_for_values(subjects=[subj,])
result = self.findEventIdsAndWait([event_template],
timerange=(0,200), num_events=100, result_type=0)
self.assertEquals(len(result), 1)