154
168
self.zg.log(event)
170
def log_udf_deleted(self, volume):
171
"""Log the udf deleted event."""
172
folder = Subject.new_for_values(
173
uri=URI_PROTOCOL_U1 + str(volume.node_id),
174
interpretation=Interpretation.FOLDER,
175
manifestation=Manifestation.DELETED_RESOURCE,
176
origin="file:///" + volume.path,
177
mimetype=DIRECTORY_MIMETYPE,
178
storage=STORAGE_DELETED)
180
event = Event.new_for_values(
181
interpretation=EVENT_INTERPRETATION_U1_UDF_DELETED,
182
manifestation=Manifestation.USER_ACTIVITY,
183
actor=ACTOR_UBUNTUONE,
156
188
def handle_VM_VOLUME_DELETED(self, volume):
157
189
"""Log the share/UDF unaccepted event."""
158
190
if isinstance(volume, Share):
159
191
self.log_share_unaccepted(volume)
192
if isinstance(volume, UDF):
193
self.log_udf_deleted(volume)
195
def handle_VM_UDF_CREATED(self, udf):
196
"""An udf was created. Log it into Zeitgeist."""
197
folder = Subject.new_for_values(
198
uri=URI_PROTOCOL_U1 + str(udf.node_id),
199
interpretation=Interpretation.FOLDER,
200
manifestation=Manifestation.REMOTE_DATA_OBJECT,
201
origin="file:///" + udf.path,
202
mimetype=DIRECTORY_MIMETYPE,
203
storage=STORAGE_NETWORK)
205
event = Event.new_for_values(
206
interpretation=EVENT_INTERPRETATION_U1_UDF_CREATED,
207
manifestation=Manifestation.USER_ACTIVITY,
208
actor=ACTOR_UBUNTUONE,
213
def handle_VM_UDF_SUBSCRIBED(self, udf):
214
"""An udf was subscribed."""
216
folder = Subject.new_for_values(
217
uri="file:///" + udf.path,
218
interpretation=Interpretation.FOLDER,
219
manifestation=Manifestation.FILE_DATA_OBJECT,
220
origin=URI_PROTOCOL_U1 + str(udf.node_id),
221
mimetype=DIRECTORY_MIMETYPE,
222
storage=STORAGE_LOCAL)
224
event = Event.new_for_values(
225
interpretation=EVENT_INTERPRETATION_U1_UDF_SUBSCRIBED,
226
manifestation=Manifestation.USER_ACTIVITY,
227
actor=ACTOR_UBUNTUONE,
232
def handle_VM_UDF_UNSUBSCRIBED(self, udf):
233
"""An udf was unsubscribed."""
235
folder = Subject.new_for_values(
236
uri="file:///" + udf.path,
237
interpretation=Interpretation.FOLDER,
238
manifestation=Manifestation.DELETED_RESOURCE,
239
origin=URI_PROTOCOL_U1 + str(udf.node_id),
240
mimetype=DIRECTORY_MIMETYPE,
241
storage=STORAGE_DELETED)
243
event = Event.new_for_values(
244
interpretation=EVENT_INTERPRETATION_U1_UDF_UNSUBSCRIBED,
245
manifestation=Manifestation.USER_ACTIVITY,
246
actor=ACTOR_UBUNTUONE,
251
def handle_AQ_FILE_NEW_OK(self, volume_id, marker, new_id, new_generation):
252
"""A new file was created on server. Store and wait till it uploads."""
253
self.newly_created_server_files.add((volume_id, new_id))
255
def get_mime_and_interpretation_for_filepath(self, filepath):
256
"""Try to guess the mime and the interpretation from the path."""
257
mime, encoding = mimetypes.guess_type(filepath)
259
return DEFAULT_MIME, DEFAULT_INTERPRETATION
260
interpret = get_interpretation_for_mimetype(mime)
261
if interpret is None:
262
return DEFAULT_MIME, Interpretation.DOCUMENT
263
return mime, interpret
265
def handle_AQ_UPLOAD_FINISHED(self, share_id, node_id, hash,
267
"""A file finished uploading to the server."""
269
mdo = self.fsm.get_by_node_id(share_id, node_id)
270
path = self.fsm.get_abspath(share_id, mdo.path)
272
if (share_id, node_id) in self.newly_created_server_files:
273
self.newly_created_server_files.remove((share_id, node_id))
274
event_interpretation = Interpretation.CREATE_EVENT
276
event_interpretation = Interpretation.MODIFY_EVENT
278
mime, interp = self.get_mime_and_interpretation_for_filepath(path)
280
file_subject = Subject.new_for_values(
281
uri=URI_PROTOCOL_U1 + str(node_id),
282
interpretation=interp,
283
manifestation=Manifestation.REMOTE_DATA_OBJECT,
284
origin="file:///" + path,
286
storage=STORAGE_NETWORK)
288
event = Event.new_for_values(
289
interpretation=event_interpretation,
290
manifestation=Manifestation.SCHEDULED_ACTIVITY,
291
actor=ACTOR_UBUNTUONE,
292
subjects=[file_subject])
296
def handle_AQ_DIR_NEW_OK(self, volume_id, marker, new_id, new_generation):
297
"""A dir was created on the server."""
299
mdo = self.fsm.get_by_node_id(volume_id, new_id)
300
path = self.fsm.get_abspath(volume_id, mdo.path)
302
file_subject = Subject.new_for_values(
303
uri=URI_PROTOCOL_U1 + str(new_id),
304
interpretation=Interpretation.FOLDER,
305
manifestation=Manifestation.REMOTE_DATA_OBJECT,
306
origin="file:///" + path,
307
mimetype=DIRECTORY_MIMETYPE,
308
storage=STORAGE_NETWORK)
310
event = Event.new_for_values(
311
interpretation=Interpretation.CREATE_EVENT,
312
manifestation=Manifestation.SCHEDULED_ACTIVITY,
313
actor=ACTOR_UBUNTUONE,
314
subjects=[file_subject])
318
def handle_SV_FILE_NEW(self, volume_id, node_id, parent_id, name):
319
"""A file was created locally by Syncdaemon."""
320
self.newly_created_local_files.add((volume_id, node_id))
322
def handle_AQ_DOWNLOAD_FINISHED(self, share_id, node_id, server_hash):
323
"""A file finished downloading from the server."""
325
mdo = self.fsm.get_by_node_id(share_id, node_id)
326
path = self.fsm.get_abspath(share_id, mdo.path)
328
if (share_id, node_id) in self.newly_created_local_files:
329
self.newly_created_local_files.remove((share_id, node_id))
330
event_interpretation = Interpretation.CREATE_EVENT
332
event_interpretation = Interpretation.MODIFY_EVENT
334
mime, interp = self.get_mime_and_interpretation_for_filepath(path)
336
file_subject = Subject.new_for_values(
337
uri="file:///" + path,
338
interpretation=interp,
339
manifestation=Manifestation.FILE_DATA_OBJECT,
340
origin=URI_PROTOCOL_U1 + str(node_id),
342
storage=STORAGE_LOCAL)
344
event = Event.new_for_values(
345
interpretation=event_interpretation,
346
manifestation=Manifestation.WORLD_ACTIVITY,
347
actor=ACTOR_UBUNTUONE,
348
subjects=[file_subject])
352
def handle_SV_DIR_NEW(self, volume_id, node_id, parent_id, name):
353
"""A file finished downloading from the server."""
355
mdo = self.fsm.get_by_node_id(volume_id, node_id)
356
path = self.fsm.get_abspath(volume_id, mdo.path)
358
file_subject = Subject.new_for_values(
359
uri="file:///" + path,
360
interpretation=Interpretation.FOLDER,
361
manifestation=Manifestation.FILE_DATA_OBJECT,
362
origin=URI_PROTOCOL_U1 + str(node_id),
363
mimetype=DIRECTORY_MIMETYPE,
364
storage=STORAGE_LOCAL)
366
event = Event.new_for_values(
367
interpretation=Interpretation.CREATE_EVENT,
368
manifestation=Manifestation.WORLD_ACTIVITY,
369
actor=ACTOR_UBUNTUONE,
370
subjects=[file_subject])
374
def handle_SV_FILE_DELETED(self, volume_id, node_id, is_dir):
375
"""A file or folder was deleted locally by Syncdaemon."""
376
mdo = self.fsm.get_by_node_id(volume_id, node_id)
377
path = self.fsm.get_abspath(volume_id, mdo.path)
380
mime, interp = DIRECTORY_MIMETYPE, Interpretation.FOLDER
382
mime, interp = self.get_mime_and_interpretation_for_filepath(path)
384
file_subject = Subject.new_for_values(
385
uri="file:///" + path,
386
interpretation=interp,
387
manifestation=Manifestation.DELETED_RESOURCE,
388
origin=URI_PROTOCOL_U1 + str(node_id),
390
storage=STORAGE_DELETED)
392
event = Event.new_for_values(
393
interpretation=Interpretation.DELETE_EVENT,
394
manifestation=Manifestation.WORLD_ACTIVITY,
395
actor=ACTOR_UBUNTUONE,
396
subjects=[file_subject])
400
def handle_AQ_UNLINK_OK(self, share_id, parent_id, node_id,
402
"""A file or folder was deleted on the server by Syncdaemon,"""
403
mdo = self.fsm.get_by_node_id(share_id, node_id)
404
path = self.fsm.get_abspath(share_id, mdo.path)
407
mime, interp = DIRECTORY_MIMETYPE, Interpretation.FOLDER
409
mime, interp = self.get_mime_and_interpretation_for_filepath(path)
411
file_subject = Subject.new_for_values(
412
uri=URI_PROTOCOL_U1 + str(node_id),
413
interpretation=interp,
414
manifestation=Manifestation.DELETED_RESOURCE,
415
origin="file:///" + path,
417
storage=STORAGE_DELETED)
419
event = Event.new_for_values(
420
interpretation=Interpretation.DELETE_EVENT,
421
manifestation=Manifestation.SCHEDULED_ACTIVITY,
422
actor=ACTOR_UBUNTUONE,
423
subjects=[file_subject])
427
def handle_FSM_FILE_CONFLICT(self, old_name, new_name):
428
"""A file was renamed because of conflict."""
429
mime, interp = self.get_mime_and_interpretation_for_filepath(old_name)
431
file_subject = Subject.new_for_values(
432
uri="file:///" + new_name,
433
interpretation=interp,
434
manifestation=Manifestation.FILE_DATA_OBJECT,
435
origin="file:///" + old_name,
437
storage=STORAGE_LOCAL)
439
event = Event.new_for_values(
440
interpretation=EVENT_INTERPRETATION_U1_CONFLICT_RENAME,
441
manifestation=Manifestation.WORLD_ACTIVITY,
442
actor=ACTOR_UBUNTUONE,
443
subjects=[file_subject])
447
def handle_FSM_DIR_CONFLICT(self, old_name, new_name):
448
"""A dir was renamed because of conflict."""
449
folder_subject = Subject.new_for_values(
450
uri="file:///" + new_name,
451
interpretation=Interpretation.FOLDER,
452
manifestation=Manifestation.FILE_DATA_OBJECT,
453
origin="file:///" + old_name,
454
mimetype=DIRECTORY_MIMETYPE,
455
storage=STORAGE_LOCAL)
457
event = Event.new_for_values(
458
interpretation=EVENT_INTERPRETATION_U1_CONFLICT_RENAME,
459
manifestation=Manifestation.WORLD_ACTIVITY,
460
actor=ACTOR_UBUNTUONE,
461
subjects=[folder_subject])
465
def handle_AQ_CHANGE_PUBLIC_ACCESS_OK(self, share_id, node_id, is_public,
467
"""The status of a published resource changed. Log it!"""
469
self.log_publishing(share_id, node_id, is_public, public_url)
471
self.log_unpublishing(share_id, node_id, is_public, public_url)
473
def log_publishing(self, share_id, node_id, is_public, public_url):
474
"""Log the publishing of a resource."""
475
mime, interp = self.get_mime_and_interpretation_for_filepath(
478
origin = "" if node_id is None else URI_PROTOCOL_U1 + str(node_id)
480
public_file = Subject.new_for_values(
482
interpretation=interp,
483
manifestation=Manifestation.REMOTE_DATA_OBJECT,
486
storage=STORAGE_NETWORK)
488
event = Event.new_for_values(
489
interpretation=Interpretation.CREATE_EVENT,
490
manifestation=Manifestation.USER_ACTIVITY,
491
actor=ACTOR_UBUNTUONE,
492
subjects=[public_file])
496
def log_unpublishing(self, share_id, node_id, is_public, public_url):
497
"""Log the unpublishing of a resource."""
498
mime, interp = self.get_mime_and_interpretation_for_filepath(
501
origin = "" if node_id is None else URI_PROTOCOL_U1 + str(node_id)
503
public_file = Subject.new_for_values(
505
interpretation=interp,
506
manifestation=Manifestation.DELETED_RESOURCE,
509
storage=STORAGE_DELETED)
511
event = Event.new_for_values(
512
interpretation=Interpretation.DELETE_EVENT,
513
manifestation=Manifestation.USER_ACTIVITY,
514
actor=ACTOR_UBUNTUONE,
515
subjects=[public_file])