1 """
2 Note on events
3 ==============
4
5 The creation events emitted by a CAM package, in addition to the ones emitted by
6 a CORE package (see `advene.model.events`), include:!
7 * ``created::user-tag``
8 * ``created::annotation-type``
9 * ``created::relation-type``
10 * ``created::user-list``
11 * ``created::schema``
12 """
13
14 from advene.model.cam.consts import BOOTSTRAP_URI, CAMSYS_TYPE
15 from advene.model.cam.exceptions import UnsafeUseWarning, SemanticError
16 from advene.model.cam.group import CamGroupMixin
17 from advene.model.cam.media import Media
18 from advene.model.cam.annotation import Annotation
19 from advene.model.cam.relation import Relation
20 from advene.model.cam.view import View
21 from advene.model.cam.resource import Resource
22 from advene.model.cam.tag import Tag
23 from advene.model.cam.list import List
24 from advene.model.cam.query import Query
25 from advene.model.cam.import_ import Import
26 import advene.model.cam.util.bookkeeping as bk
27 from advene.model.consts import DC_NS_PREFIX, RDFS_NS_PREFIX
28 from advene.model.core.package import Package as CorePackage
29 from advene.model.core.all_group import AllGroup as CoreAllGroup
30 from advene.model.core.own_group import OwnGroup as CoreOwnGroup
31
32 from warnings import warn
33 from weakref import ref as wref
34
35 -class _AllGroup(CamGroupMixin, CoreAllGroup):
36
44
50
57
64
71
72 - def iter_lists(self, item=None, position=None, meta=None):
73 """
74 This method is inherited from CoreAllGroup but is unsafe on
75 cam.Package. Use instead `iter_user_lists`.
76 """
77 warn("use iter_user_lists instead", UnsafeUseWarning, 2)
78 return super(_AllGroup, self).iter_lists(item, position, meta)
79
81 """
82 Allows to call iter_lists internally without raising a warning.
83 """
84 return super(_AllGroup, self).iter_lists(item, position, meta)
85
92
93 - def iter_schemas(self, item=None, position=None, meta=None):
99
107
113
120
127
134
135 - def count_lists(self, item=None, position=None, meta=None):
136 """
137 This method is inherited from CoreAllGroup but is unsafe on
138 cam.Package. Use instead `count_user_lists`.
139 """
140 warn("use count_user_lists instead", UnsafeUseWarning, 2)
141 return super(_AllGroup, self).count_lists(item, position, meta)
142
144 """
145 Allows to call count_lists internally without raising a warning.
146 """
147 return super(_AllGroup, self).count_lists(item, position, meta)
148
155
162
163 -class _OwnGroup(CamGroupMixin, CoreOwnGroup):
171
177
183
189
195
197 """
198 This method is inherited from CoreOwnGroup but is unsafe on
199 cam.Package. Use instead `iter_user_lists`.
200 """
201 warn("use iter_user_lists instead", UnsafeUseWarning, 2)
202 return super(_OwnGroup, self).iter_lists(item, position)
203
205 """
206 Allows to call iter_lists internally without raising a warning.
207 """
208 return super(_OwnGroup, self).iter_lists(item, position)
209
215
221
229
235
240
245
250
252 """
253 This method is inherited from CoreOwnGroup but is unsafe on
254 cam.Package. Use instead `count_user_lists`.
255 """
256 warn("use count_user_lists instead", UnsafeUseWarning, 2)
257 return super(_OwnGroup, self).count_lists(item=item, position=position)
258
260 """
261 Allows to call count_lists internally without raising a warning.
262 """
263 return super(_OwnGroup, self).count_lists(item=item, position=position)
264
269
274
276
277
278 annotation_factory = Annotation
279 all_factory = _AllGroup
280 import_factory = Import
281 list_factory = List
282 media_factory = Media
283 relation_factory = Relation
284 resource_factory = Resource
285 own_factory = _OwnGroup
286 query_factory = Query
287 tag_factory = Tag
288 view_factory = View
289
290 - def __init__(self, url, create=False, readonly=False, force=False):
291 CorePackage.__init__(self, url, create, readonly, force)
292 if self.url != BOOTSTRAP_URI and self.uri != BOOTSTRAP_URI \
293 and self.own.count_imports(uri=BOOTSTRAP_URI) == 0:
294 global _bootstrap_ref
295 b = _bootstrap_ref()
296 if b is None:
297 b = Package(BOOTSTRAP_URI, readonly=True)
298 _bootstrap_ref = wref(b)
299 self.create_import("cam", b)
300
301 ns = self._get_namespaces_as_dict()
302 ns.setdefault(DC_NS_PREFIX, "dc")
303 self._set_namespaces_with_dict(ns)
304 if create:
305 bk.init(self, self)
306 self.connect("modified-meta", bk.update)
307 self.connect("created", bk.init)
308 self.connect("tag::added", bk.update)
309 self.connect("tag::removed", bk.update)
310 self.connect("created::annotation-type", self._create_type_constraint)
311 self.connect("created::relation-type", self._create_type_constraint)
312
314 """
315 This method is inherited from core.Package but is unsafe on
316 cam.Package. Use instead `create_user_tag`.
317
318 :see: `create_user_tag`, `create_annotation_type`,
319 `create_relation_type`
320 """
321 warn("use create_user_tag instead", UnsafeUseWarning, 2)
322 return super(Package, self).create_tag(id)
323
325 """FIXME: missing docstring.
326 """
327 t = super(Package, self).create_tag(id)
328 self.emit("created::user-type", t)
329 return t
330
352
374
375 - def create_annotation(self, id, media, begin, end,
376 mimetype, model=None, url="", type=None):
377 """FIXME: missing docstring.
378 """
379 assert type is None or hasattr(type, "ADVENE_TYPE") \
380 or type.find(":") > 0
381
382
383
384 self.enter_no_event_section()
385 try:
386 a = super(Package, self).create_annotation(id, media, begin, end,
387 mimetype, model, url)
388 finally:
389 self.exit_no_event_section()
390
391 if type:
392 type_is_element = hasattr(type, "ADVENE_TYPE")
393 a.enter_no_event_section()
394 if type_is_element: type.enter_no_event_section()
395 try:
396 a.type = type
397 finally:
398 if type_is_element: type.exit_no_event_section()
399 a.exit_no_event_section()
400
401 self.emit("created::annotation", a)
402 return a
403
404 - def create_relation(self, id, mimetype="x-advene/none", model=None,
405 url="", members=(), type=None):
432
434 """
435 This method is inherited from core.Package but is unsafe on
436 cam.Package. Use instead `create_user_list`.
437
438 :see: `create_user_list`, `create_schema`
439 """
440 warn("use create_user_list instead", UnsafeUseWarning, 2)
441 return super(Package, self).create_list(id, items)
442
449
470
472 """
473 This method is inherited from core.Package but is unsafe on
474 cam.Package. Use instead `associate_user_tag`.
475 """
476 warn("use associate_user_tag instead", UnsafeUseWarning, 2)
477 super(Package, self).associate_tag(element, tag)
478
484
485
487 """
488 This method is inherited from core.Package but is unsafe on
489 cam.Package. Use instead `dissociate_user_tag`.
490 """
491 warn("use associate_user_tag instead", UnsafeUseWarning, 2)
492 super(Package, self).dissociate_tag(element, tag)
493
499
513
522
537
538
539
540
541 @property
544
545 @property
548
549 @property
552
553 @property
556
557 @property
560
561 _bootstrap_ref = lambda: None
562
563 Package.make_metadata_property(bk.CREATOR, default="")
564 Package.make_metadata_property(bk.CONTRIBUTOR, default="")
565 Package.make_metadata_property(bk.CREATED, default="")
566 Package.make_metadata_property(bk.MODIFIED, default="")
567
568 Package.make_metadata_property(DC_NS_PREFIX + "title", default="")
569 Package.make_metadata_property(DC_NS_PREFIX + "description", default="")
570
571 Package.make_metadata_property(RDFS_NS_PREFIX + "seeAlso", default=None)
572