本文整理匯總了Python中zeitgeist.datamodel.Subject.new_for_values方法的典型用法代碼示例。如果您正苦於以下問題:Python Subject.new_for_values方法的具體用法?Python Subject.new_for_values怎麽用?Python Subject.new_for_values使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類zeitgeist.datamodel.Subject
的用法示例。
在下文中一共展示了Subject.new_for_values方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: log_folder_shared
# 需要導入模塊: from zeitgeist.datamodel import Subject [as 別名]
# 或者: from zeitgeist.datamodel.Subject import new_for_values [as 別名]
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)
示例2: handle_VM_SHARE_CREATED
# 需要導入模塊: from zeitgeist.datamodel import Subject [as 別名]
# 或者: from zeitgeist.datamodel.Subject import new_for_values [as 別名]
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)
示例3: register_message_event
# 需要導入模塊: from zeitgeist.datamodel import Subject [as 別名]
# 或者: from zeitgeist.datamodel.Subject import new_for_values [as 別名]
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: testFindEventIdsWithMultipleSubjects
# 需要導入模塊: from zeitgeist.datamodel import Subject [as 別名]
# 或者: from zeitgeist.datamodel.Subject import new_for_values [as 別名]
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))
示例5: testGetWithMultipleSubjects
# 需要導入模塊: from zeitgeist.datamodel import Subject [as 別名]
# 或者: from zeitgeist.datamodel.Subject import new_for_values [as 別名]
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)
示例6: testFindMultipleEvents
# 需要導入模塊: from zeitgeist.datamodel import Subject [as 別名]
# 或者: from zeitgeist.datamodel.Subject import new_for_values [as 別名]
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: main
# 需要導入模塊: from zeitgeist.datamodel import Subject [as 別名]
# 或者: from zeitgeist.datamodel.Subject import new_for_values [as 別名]
def main(argv):
interpretation = Interpretation.MODIFY_EVENT.uri
# FIXME: I'd be great if zeitgeist would allow for more detail:
# * branch
# * log summary (git log -1 --format=%s HEAD)
curdir = os.path.abspath(os.curdir).decode(sys.getfilesystemencoding())
uri = u"file://%s" % curdir
repo, origin = get_repo()
if not repo:
repo = unicode(curdir.rsplit('/', 1)[1])
origin = uri
subject = Subject.new_for_values(
uri=uri,
interpretation=Interpretation.DOCUMENT.TEXT_DOCUMENT.PLAIN_TEXT_DOCUMENT.SOURCE_CODE.uri,
manifestation=Manifestation.FILE_DATA_OBJECT.uri,
text=repo,
origin=origin)
event = Event.new_for_values(
timestamp=int(time.time() * 1000),
interpretation=interpretation,
manifestation=Manifestation.USER_ACTIVITY.uri,
actor="application://gitg.desktop",
subjects=[subject])
CLIENT.insert_event(event)
示例8: testUnicodeEventInsert
# 需要導入模塊: from zeitgeist.datamodel import Subject [as 別名]
# 或者: from zeitgeist.datamodel.Subject import new_for_values [as 別名]
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)
示例9: send_to_zeitgeist
# 需要導入模塊: from zeitgeist.datamodel import Subject [as 別名]
# 或者: from zeitgeist.datamodel.Subject import new_for_values [as 別名]
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)
示例10: onNewTrack
# 需要導入模塊: from zeitgeist.datamodel import Subject [as 別名]
# 或者: from zeitgeist.datamodel.Subject import new_for_values [as 別名]
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)
示例11: buildQuery
# 需要導入模塊: from zeitgeist.datamodel import Subject [as 別名]
# 或者: from zeitgeist.datamodel.Subject import new_for_values [as 別名]
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)
示例12: create_and_send_event
# 需要導入模塊: from zeitgeist.datamodel import Subject [as 別名]
# 或者: from zeitgeist.datamodel.Subject import new_for_values [as 別名]
def create_and_send_event(self, page, path, event_type):
if not self.zeitgeist_client:
return
#FIXME: Assumes file store
store = self.ui.notebook.get_store(page.name)
if path is not None:
fileobj = store._get_file(path)
else:
fileobj = store._get_file(page)
uri = fileobj.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)
示例13: create_and_send_event
# 需要導入模塊: from zeitgeist.datamodel import Subject [as 別名]
# 或者: from zeitgeist.datamodel.Subject import new_for_values [as 別名]
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)
示例14: handle_AQ_UNLINK_OK
# 需要導入模塊: from zeitgeist.datamodel import Subject [as 別名]
# 或者: from zeitgeist.datamodel.Subject import new_for_values [as 別名]
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)
示例15: handle_AQ_DOWNLOAD_FINISHED
# 需要導入模塊: from zeitgeist.datamodel import Subject [as 別名]
# 或者: from zeitgeist.datamodel.Subject import new_for_values [as 別名]
def handle_AQ_DOWNLOAD_FINISHED(self, share_id, node_id, server_hash):
"""A file finished downloading from the server."""
mdo = self.fsm.get_by_node_id(share_id, node_id)
path = self.fsm.get_abspath(share_id, mdo.path)
if (share_id, node_id) in self.newly_created_local_files:
self.newly_created_local_files.remove((share_id, node_id))
event_interpretation = Interpretation.CREATE_EVENT
else:
event_interpretation = Interpretation.MODIFY_EVENT
mime, interp = self.get_mime_and_interpretation_for_filepath(path)
file_subject = Subject.new_for_values(
uri="file:///" + path,
interpretation=interp,
manifestation=Manifestation.FILE_DATA_OBJECT,
origin=URI_PROTOCOL_U1 + str(node_id),
text=basename(path),
mimetype=mime,
storage=STORAGE_LOCAL)
event = Event.new_for_values(
interpretation=event_interpretation,
manifestation=Manifestation.WORLD_ACTIVITY,
actor=ACTOR_UBUNTUONE,
subjects=[file_subject])
self.zg.log(event)