Exemple #1
0
def fill_package_step_by_step(p, empty=False):
    if empty:
        yield "empty"
    p3 = Package("urn:xyz", create=True)
    m3 = p3.create_media("m3", "http://example.com/m3.ogm")
    a3 = p3.create_annotation("a3", m3, 123, 456, "text/plain")
    r3 = p3.create_relation("r3", "text/plain", members=[a3,])
    L3 = p3.create_list("L3", items=[a3, m3, r3,])
    t3 = p3.create_tag("t3")
    v3 = p3.create_view("v3", "text/html+tag")
    q3 = p3.create_query("q3", "x-advene/rules")
    R3 = p3.create_resource("R3", "text/css")

    p.uri = "http://example.com/my-package"; yield 1
    i = p.create_import("i", p3); yield 2
    m = p.create_media("m", "http://example.com/m.ogm"); yield 3
    m.set_meta(rdfs_seeAlso, m3); yield 4
    Rb = p.create_resource("Rb", "x-advene/regexp"); yield 5
    Rb.content_data = "g.*g"; yield 6
    a = p.create_annotation("a", m, 123, 456, "text/plain", Rb); yield 7
    a.content_data = "goog moaning"; yield 8
    r = p.create_relation("r", members=[a, a3]); yield 9
    r2 = p.create_relation("r2", "text/plain"); yield 10
    L = p.create_list("L", items=[a, m, r, m3]); yield 11
    t = p.create_tag("t"); yield 12
    v = p.create_view("v", "text/html+tag"); yield 13
    v.content_url = "http://example.com/a-tal-view.html"; yield 14
    q = p.create_query("q", "text/x-python"); yield 15
    q.content_url = "file:%s" % pathname2url(__file__); yield 16
    Ra = p.create_resource("Ra", "text/css"); yield 17
    sorted_p_own = list(p.own); sorted_p_own.sort(key=lambda x: x._id)
    for e in sorted_p_own:
        e.set_meta(dc_creator, "pchampin"); yield 18, e.id
        p.associate_tag(e, t); yield 19, e.id
        p.associate_tag(e, t3); yield 20, e.id
    sorted_p3_own = list(p3.own); sorted_p3_own.sort(key=lambda x: x._id)
    for e in sorted_p3_own:
        p.associate_tag(e, t); yield 21, e.id
        p.associate_tag(e, t3); yield 22, e.id
    p.set_meta(dc_creator, "John Doe"); yield 23
    p.set_meta(dc_description, "a package used for testing diff"); yield 24
    p.set_meta(PARSER_META_PREFIX+"namespaces",
               "dc http://purl.org/dc/elements/1.1/")
    yield "done"
Exemple #2
0
    t3 = p3.create_tag("t3")
    t4 = p4.create_tag("t4")
    t6 = p6.create_tag("t6")
    p3.associate_tag(a5, t4)
    p3.associate_tag(a5, t3)
    p3.associate_tag(a3, t3)
    p5.associate_tag(a3, t6)
    p5.associate_tag(a5, t6)
    p1.associate_tag(a3, t2)

    m3 = p3.create_media("m3", "urn:xyz")
    r3 = p3.create_relation("r3", members=[a5, a3])
    L3 = p3.create_list("L3", items=[a5, r3, a3])
    v3 = p3.create_view("v3", "text/plain")
    q3 = p3.create_query("q3", "text/plain")
    R3 = p3.create_resource("R3", "text/plain")

    print
    print [i.id for i in p3.own.annotations]
    print [i.id for i in p4.own.medias]
    print [i.id for i in p5.own.annotations]
    print [i.id for i in p6.own.medias]
    print
    print [i.id for i in p3.all.medias]
    print [i.id for i in p3.all.annotations]
    print [i.id for i in p5.all.medias]
    print [i.id for i in p5.all.annotations]
    print [i.id for i in p1.all.medias]
    print [i.id for i in p1.all.annotations]
    print
    print [t.id for t in a3.iter_my_tags(p5)]
Exemple #3
0
    print "about to re-load package"
    p = Package(package_filename)
    # ensure that backend has changed
    assert p._backend is not bw()
    print "package loaded"
    #trace_wrap_all (p._backend)

    l = list (p.own.annotations)
    #print [a._id for a in p.own.annotations]
    a1 = p.get_element ("a1")
    a2 = p.get_element ("a2")
    print id(a1) == id(p.get_element ("a1"))
    print a1.content_data
    print p.meta[dc_creator]
    print p.get_meta(advene_ns % "meta/main_media")
    print a1.begin, a1.duration, a1.end
    print a1.meta[dc_creator]
    print a2.meta[advene_ns % "meta/created_from"]
    a2.del_meta(advene_ns % "meta/foo")
    print list(a2.iter_meta())
    p.create_resource("eraseme", "text/plain").delete()
    print list(p.own.resources)

    fname=join(base, 'test1.bxp')
    print "Saving as ", fname
    if exists (fname): unlink (fname)
    p.save_as(fname)

    l = None; a1 = None; a2 = None; p.close(); p = None

Exemple #4
0
class TestEvents(TestCase):
    def setUp(self):
        self.dirname = mkdtemp()
        self.db = join(self.dirname, "db")
        self.url = "sqlite:%s" % pathname2url(self.db)
        self.p1 = Package(self.url+";p1", create=True)
        self.p2 = Package(self.url+";p2", create=True)
        self.p3 = Package(self.url+";p3", create=True)
        self.buf = []
        self.callback_errors = []

    def tearDown(self):
        try:
            if self.p1 and not self.p1.closed: self.p1.close()
            if self.p2 and not self.p2.closed: self.p2.close()
            if self.p3 and not self.p3.closed: self.p3.close()
        except ValueError:
            pass
        unlink(self.db)
        rmdir(self.dirname)

    def default_handler(self, *args):
        self.buf.append(args)

    def attr_handler(self, obj, attr, val, pre=None):
        actual_val = getattr(obj, attr)
        if pre:
            if actual_val == val:
                self.callback_errors.append("%s should not be %r yet" %
                                            (attr, val))
        else:
            if actual_val != val:
                self.callback_errors.append("%s = %r, should be %r" %
                                            (attr, actual_val, val))
        self.default_handler(obj, attr, val)

    def meta_handler(self, obj, key, val, pre=None):
        actual_val = obj.get_meta(key, None)
        if pre:
            if actual_val == val:
                self.callback_errors.append("%s should not be %r yet" %
                                            (key, val))
        else:
            if actual_val != val:
                self.callback_errors.append("%s : %r, should be %r" %
                                            (key, actual_val, val))
        self.default_handler(obj, key, val)

    def elt_handler(self, pkg, elt, signal, params):
        self.default_handler(pkg, elt, signal, params)

    def test_create_media(self):
        hid = self.p1.connect("created::media", self.default_handler)
        m = self.p2.create_media("m", "file:/tmp/foo.avi")
        self.assertEqual(self.buf, [])
        a = self.p2.create_annotation("a", m, 10, 20, "text/plain")
        self.assertEqual(self.buf, [])
        m = self.p1.create_media("m", "file:/tmp/foo.avi")
        self.assertEqual(self.buf, [(self.p1, m,),])
        del self.buf[:]
        self.p1.disconnect(hid)
        m = self.p1.create_media("m2", "file:/tmp/foo.avi")
        self.assertEqual(self.buf, [])

    def test_create_annotation(self):
        hid = self.p1.connect("created::annotation", self.default_handler)
        m = self.p2.create_media("m", "file:/tmp/foo.avi")
        self.assertEqual(self.buf, [])
        a = self.p2.create_annotation("a", m, 10, 20, "text/plain")
        self.assertEqual(self.buf, [])
        m = self.p1.create_media("m", "file:/tmp/foo.avi")
        self.assertEqual(self.buf, [])
        a = self.p1.create_annotation("a", m, 10, 20, "text/plain")
        self.assertEqual(self.buf, [(self.p1, a,),])
        del self.buf[:]
        self.p1.disconnect(hid)
        a = self.p1.create_annotation("a2", m, 10, 20, "text/plain")
        self.assertEqual(self.buf, [])

    def test_create_relation(self):
        hid = self.p1.connect("created::relation", self.default_handler)
        r = self.p2.create_relation("r")
        self.assertEqual(self.buf, [])
        m = self.p1.create_media("m", "file:/tmp/foo.avi")
        self.assertEqual(self.buf, [])
        r = self.p1.create_relation("r")
        self.assertEqual(self.buf, [(self.p1, r,),])
        del self.buf[:]
        self.p1.disconnect(hid)
        r = self.p1.create_relation("r2")
        self.assertEqual(self.buf, [])

    def test_create_list(self):
        hid = self.p1.connect("created::list", self.default_handler)
        L = self.p2.create_list("L")
        self.assertEqual(self.buf, [])
        m = self.p1.create_media("m", "file:/tmp/foo.avi")
        self.assertEqual(self.buf, [])
        L = self.p1.create_list("L")
        self.assertEqual(self.buf, [(self.p1, L,),])
        del self.buf[:]
        self.p1.disconnect(hid)
        r = self.p1.create_relation("L2")
        self.assertEqual(self.buf, [])

    def test_create_tag(self):
        hid = self.p1.connect("created::tag", self.default_handler)
        t = self.p2.create_tag("t")
        self.assertEqual(self.buf, [])
        m = self.p1.create_media("m", "file:/tmp/foo.avi")
        self.assertEqual(self.buf, [])
        t = self.p1.create_tag("t")
        self.assertEqual(self.buf, [(self.p1, t,),])
        del self.buf[:]
        self.p1.disconnect(hid)
        t = self.p1.create_tag("t2")
        self.assertEqual(self.buf, [])

    def test_create_query(self):
        hid = self.p1.connect("created::query", self.default_handler)
        q = self.p2.create_query("q", "text/plain")
        self.assertEqual(self.buf, [])
        m = self.p1.create_media("m", "file:/tmp/foo.avi")
        self.assertEqual(self.buf, [])
        q = self.p1.create_query("q", "text/plain")
        self.assertEqual(self.buf, [(self.p1, q,),])
        del self.buf[:]
        self.p1.disconnect(hid)
        q = self.p1.create_query("q2", "text/plain")
        self.assertEqual(self.buf, [])

    def test_create_view(self):
        hid = self.p1.connect("created::view", self.default_handler)
        v = self.p2.create_view("v", "text/plain")
        self.assertEqual(self.buf, [])
        m = self.p1.create_media("m", "file:/tmp/foo.avi")
        self.assertEqual(self.buf, [])
        v = self.p1.create_view("v", "text/plain")
        self.assertEqual(self.buf, [(self.p1, v,),])
        del self.buf[:]
        self.p1.disconnect(hid)
        v = self.p1.create_view("v2", "text/plain")
        self.assertEqual(self.buf, [])

    def test_create_resource(self):
        hid = self.p1.connect("created::resource", self.default_handler)
        r = self.p2.create_resource("r", "text/plain")
        self.assertEqual(self.buf, [])
        m = self.p1.create_media("m", "file:/tmp/foo.avi")
        self.assertEqual(self.buf, [])
        r = self.p1.create_resource("r", "text/plain")
        self.assertEqual(self.buf, [(self.p1, r,),])
        del self.buf[:]
        self.p1.disconnect(hid)
        r = self.p1.create_resource("r2", "text/plain")
        self.assertEqual(self.buf, [])

    def test_create_import(self):
        hid = self.p1.connect("created::import", self.default_handler)
        i = self.p2.create_import("i", self.p1)
        self.assertEqual(self.buf, [])
        m = self.p1.create_media("m", "file:/tmp/foo.avi")
        self.assertEqual(self.buf, [])
        i = self.p1.create_import("i", self.p2)
        self.assertEqual(self.buf, [(self.p1, i,),])
        del self.buf[:]
        self.p1.disconnect(hid)
        i = self.p1.create_import("i2", self.p3)
        self.assertEqual(self.buf, [])

    def test_create_any(self):
        self.p1.connect("created", self.default_handler)
        m = self.p2.create_media("m", "file:/tmp/foo.avi")
        self.assertEqual(self.buf, [])
        a = self.p2.create_annotation("a", m, 10, 20, "text/plain")
        self.assertEqual(self.buf, [])
        r = self.p2.create_relation("r")
        self.assertEqual(self.buf, [])
        L = self.p2.create_list("L")
        self.assertEqual(self.buf, [])
        t = self.p2.create_tag("t")
        self.assertEqual(self.buf, [])
        q = self.p2.create_query("q", "text/plain")
        self.assertEqual(self.buf, [])
        v = self.p2.create_view("v", "text/plain")
        self.assertEqual(self.buf, [])
        R = self.p2.create_resource("R", "text/plain")
        self.assertEqual(self.buf, [])
        i = self.p2.create_import("i", self.p1)
        self.assertEqual(self.buf, [])

        ref = []
        m = self.p1.create_media("m", "file:/tmp/foo.avi")
        ref += [(self.p1, m),]
        self.assertEqual(self.buf, ref)
        a = self.p1.create_annotation("a", m, 10, 20, "text/plain")
        ref += [(self.p1, a),]
        self.assertEqual(self.buf, ref)
        r = self.p1.create_relation("r")
        ref += [(self.p1, r),]
        self.assertEqual(self.buf, ref)
        L = self.p1.create_list("L")
        ref += [(self.p1, L),]
        self.assertEqual(self.buf, ref)
        t = self.p1.create_tag("t")
        ref += [(self.p1, t),]
        self.assertEqual(self.buf, ref)
        q = self.p1.create_query("q", "text/plain")
        ref += [(self.p1, q),]
        self.assertEqual(self.buf, ref)
        v = self.p1.create_view("v", "text/plain")
        ref += [(self.p1, v),]
        self.assertEqual(self.buf, ref)
        R = self.p1.create_resource("R", "text/plain")
        ref += [(self.p1, R),]
        self.assertEqual(self.buf, ref)
        i = self.p1.create_import("i", self.p2)
        ref += [(self.p1, i),]
        self.assertEqual(self.buf, ref)

    def test_closed(self):
        self.p1.connect("package-closed", self.default_handler)
        self.p2.close()
        self.assertEqual(self.buf, [])
        ref = [(self.p1, self.p1.url, self.p1.uri)]
        self.p1.close()
        self.assertEqual(self.buf, ref)

    def test_closed_disconnected(self):
        hid = self.p1.connect("package-closed", self.default_handler)
        self.p1.disconnect(hid)
        self.p1.close()
        self.assertEqual(self.buf, [])

    def test_modified_uri(self):
        hid1 = self.p1.connect("modified::uri", self.attr_handler)
        hid2 = self.p1.connect("pre-modified::uri", self.attr_handler, "pre")
        self.p2.uri = "urn:12345"
        self.assertEqual(self.buf, [])
        self.p1.uri = "urn:67890"
        self.assertEqual(self.buf, [(self.p1, "uri", "urn:67890"),]*2)
        self.assertEqual(self.callback_errors, [])
        del self.buf[:]
        self.p1.disconnect(hid1)
        self.p1.disconnect(hid2)
        self.p1.uri = "urn:abcdef"
        self.assertEqual(self.buf, [])

    def test_modified_any(self):
        hid1 = self.p1.connect("modified", self.attr_handler)
        hid2 = self.p1.connect("pre-modified", self.attr_handler, "pre")
        self.p2.uri = "urn:12345"
        self.assertEqual(self.buf, [])
        self.p1.uri = "urn:67890"
        self.assertEqual(self.buf, [(self.p1, "uri", "urn:67890"),]*2)
        self.assertEqual(self.callback_errors, [])
        del self.buf[:]
        self.p1.disconnect(hid1)
        self.p1.disconnect(hid2)
        self.p1.uri = "urn:abcdef"
        self.assertEqual(self.buf, [])

    def test_modified_meta(self):
        k = DC_NS_PREFIX + "creator"
        k2 = DC_NS_PREFIX + "title"
        hid1 = self.p1.connect("modified-meta::" + k, self.meta_handler)
        hid2 = self.p1.connect("pre-modified-meta::" + k, self.meta_handler, 1)
        self.p1.set_meta(k2, "hello world")
        self.assertEqual(self.buf, [])
        self.p2.set_meta(k, "pchampin")
        self.assertEqual(self.buf, [])
        self.p1.set_meta(k, "pchampin")
        self.assertEqual(self.buf, [(self.p1, k, "pchampin"),]*2)
        self.assertEqual(self.callback_errors, [])
        del self.buf[:]
        self.p1.del_meta(k2)
        self.assertEqual(self.buf, [])
        self.p2.del_meta(k)
        self.assertEqual(self.buf, [])
        self.p1.del_meta(k)
        self.assertEqual(self.buf, [(self.p1, k, None)]*2)
        self.assertEqual(self.callback_errors, [])
        del self.buf[:]
        self.p1.disconnect(hid1)
        self.p1.disconnect(hid2)
        self.p1.set_meta(k, "oaubert")
        self.assertEqual(self.buf, [])

    def test_modified_meta_any(self):
        k = DC_NS_PREFIX + "creator"
        hid1 = self.p1.connect("modified-meta", self.meta_handler)
        hid2 = self.p1.connect("pre-modified-meta", self.meta_handler, "pre")
        self.p2.set_meta(k, "pchampin")
        self.assertEqual(self.buf, [])
        self.p1.set_meta(k, "pchampin")
        self.assertEqual(self.buf, [(self.p1, k, "pchampin"),]*2)
        self.assertEqual(self.callback_errors, [])
        del self.buf[:]
        self.p2.del_meta(k)
        self.assertEqual(self.buf, [])
        self.p1.del_meta(k)
        self.assertEqual(self.buf, [(self.p1, k, None)]*2)
        self.assertEqual(self.callback_errors, [])
        del self.buf[:]
        self.p1.disconnect(hid1)
        self.p1.disconnect(hid2)
        self.p1.set_meta(k, "oaubert")
        self.assertEqual(self.buf, [])

    def test_modify_media(self):
        k = DC_NS_PREFIX + "creator"
        hid = self.p1.connect("media::modified", self.elt_handler)
        m = self.p1.create_media("m", "file:/tmp/foo.avi")
        m2 = self.p2.create_media("m", "file:/tmp/foo.avi")
        a = self.p1.create_annotation("a", m, 10, 20, "text/plain")
        self.assertEqual(self.buf, [])
        def do_changes(_=[1]):
            i = _[0] = _[0] + 1
            m.url = "file:/tmp/foo%s.avi" % i
            m2.url = "file:/tmp/foo%s.avi" % i
            m.set_meta(k, "creator%s" % i)
            a.end = 100 + i
            a.set_meta(k, "creator%s" % i)

        do_changes()
        self.assertEqual(self.buf, [(self.p1, m, "modified", ("url", m.url,)),])
        del self.buf[:]
        self.p1.disconnect(hid)

        hid = self.p1.connect("media::pre-modified", self.elt_handler)
        do_changes()
        self.assertEqual(self.buf,
                         [(self.p1, m, "pre-modified", ("url", m.url,)),])
        del self.buf[:]
        self.p1.disconnect(hid)

        hid = self.p1.connect("media::modified-meta", self.elt_handler)
        do_changes()
        self.assertEqual(self.buf,
                         [(self.p1, m, "modified-meta", (k, m.get_meta(k))),])
        del self.buf[:]
        self.p1.disconnect(hid)

        hid = self.p1.connect("media::pre-modified-meta", self.elt_handler)
        do_changes()
        self.assertEqual(self.buf,
            [(self.p1, m, "pre-modified-meta", (k, m.get_meta(k))),])
        del self.buf[:]
        self.p1.disconnect(hid)

        do_changes()
        self.assertEqual(self.buf, [])

    def test_modify_annotation(self):
        k = DC_NS_PREFIX + "creator"
        hid = self.p1.connect("annotation::modified", self.elt_handler)
        m = self.p1.create_media("m", "file:/tmp/foo.avi")
        m2 = self.p2.create_media("m", "file:/tmp/foo.avi")
        a = self.p1.create_annotation("a", m, 10, 20, "text/plain")
        a2 = self.p2.create_annotation("a", m2, 10, 20, "text/plain")
        self.assertEqual(self.buf, [])
        def do_changes(_=[1]):
            i = _[0] = _[0] + 1
            m.url = "file:/tmp/foo%s.avi" % i
            m2.url = "file:/tmp/foo%s.avi" % i
            m.set_meta(k, "creator%s" % i)
            a.end = 100 + i
            a.set_meta(k, "creator%s" % i)

        do_changes()
        self.assertEqual(self.buf, [(self.p1, a, "modified", ("end", a.end,)),])
        del self.buf[:]
        self.p1.disconnect(hid)

        hid = self.p1.connect("annotation::pre-modified", self.elt_handler)
        do_changes()
        self.assertEqual(self.buf,
                         [(self.p1, a, "pre-modified", ("end", a.end,)),])
        del self.buf[:]
        self.p1.disconnect(hid)

        hid = self.p1.connect("annotation::modified-meta", self.elt_handler)
        do_changes()
        self.assertEqual(self.buf,
                         [(self.p1, a, "modified-meta", (k, a.get_meta(k))),])
        del self.buf[:]
        self.p1.disconnect(hid)

        hid = self.p1.connect("annotation::pre-modified-meta", self.elt_handler)
        do_changes()
        self.assertEqual(self.buf,
            [(self.p1, a, "pre-modified-meta", (k, a.get_meta(k))),])
        del self.buf[:]
        self.p1.disconnect(hid)

        do_changes()
        self.assertEqual(self.buf, [])

    def test_modify_relation(self):
        k = DC_NS_PREFIX + "creator"
        hid = self.p1.connect("relation::modified-items", self.elt_handler)
        m = self.p1.create_media("m", "file:/tmp/foo.avi")
        m2 = self.p2.create_media("m", "file:/tmp/foo.avi")
        a = self.p1.create_annotation("a", m, 10, 20, "text/plain")
        a2 = self.p2.create_annotation("a", m2, 10, 20, "text/plain")
        r = self.p1.create_relation("r", members=[a, a,])
        r2 = self.p2.create_relation("r", members=[a2,])
        self.assertEqual(len(self.buf), 2) # initial members cause changes
        del self.buf[:]
        def do_changes(_=[1]):
            i = _[0] = _[0] + 1
            m.url = "file:/tmp/foo%s.avi" % i
            m2.url = "file:/tmp/foo%s.avi" % i
            m.set_meta(k, "creator%s" % i)
            a.end = 100 + i
            a.set_meta(k, "creator%s" % i)
            r.append(a)
            r2.append(a2)
            r.set_meta(k, "creator%s" % i)
            r2.set_meta(k, "creator%s" % i)

        do_changes()
        self.assertEqual(self.buf,
                         [(self.p1, r, "modified-items", (slice(2,2), [a,])),])
        del self.buf[:]
        self.p1.disconnect(hid)

        hid = self.p1.connect("relation::pre-modified-items", self.elt_handler)
        do_changes()
        self.assertEqual(self.buf,
            [(self.p1, r, "pre-modified-items",(slice(3,3), [a,])),])
        del self.buf[:]
        self.p1.disconnect(hid)

        hid = self.p1.connect("relation::modified-meta", self.elt_handler)
        do_changes()
        self.assertEqual(self.buf,
            [(self.p1, r, "modified-meta", (k, r.get_meta(k))),])
        del self.buf[:]
        self.p1.disconnect(hid)

        hid = self.p1.connect("relation::pre-modified-meta", self.elt_handler)
        do_changes()
        self.assertEqual(self.buf,
            [(self.p1, r, "pre-modified-meta", (k, r.get_meta(k))),])
        del self.buf[:]
        self.p1.disconnect(hid)

        do_changes()
        self.assertEqual(self.buf, [])

    def test_modify_list(self):
        k = DC_NS_PREFIX + "creator"
        hid = self.p1.connect("list::modified-items", self.elt_handler)
        m = self.p1.create_media("m", "file:/tmp/foo.avi")
        m2 = self.p2.create_media("m", "file:/tmp/foo.avi")
        a = self.p1.create_annotation("a", m, 10, 20, "text/plain")
        a2 = self.p2.create_annotation("a", m2, 10, 20, "text/plain")
        L = self.p1.create_list("L", items=[a, m,])
        L2 = self.p2.create_list("L", items=[m2, a2,])
        self.assertEqual(len(self.buf), 2) # initial members cause changes
        del self.buf[:]
        def do_changes(_=[1]):
            i = _[0] = _[0] + 1
            m.url = "file:/tmp/foo%s.avi" % i
            m2.url = "file:/tmp/foo%s.avi" % i
            m.set_meta(k, "creator%s" % i)
            a.end = 100 + i
            a.set_meta(k, "creator%s" % i)
            L.append(a)
            L2.append(a2)
            L.set_meta(k, "creator%s" % i)
            L2.set_meta(k, "creator%s" % i)

        do_changes()
        self.assertEqual(self.buf,
                         [(self.p1, L, "modified-items", (slice(2,2), [a,])),])
        del self.buf[:]
        self.p1.disconnect(hid)

        hid = self.p1.connect("list::pre-modified-items", self.elt_handler)
        do_changes()
        self.assertEqual(self.buf,
            [(self.p1, L, "pre-modified-items",(slice(3,3), [a,])),])
        del self.buf[:]
        self.p1.disconnect(hid)

        hid = self.p1.connect("list::modified-meta", self.elt_handler)
        do_changes()
        self.assertEqual(self.buf,
            [(self.p1, L, "modified-meta", (k, L.get_meta(k))),])
        del self.buf[:]
        self.p1.disconnect(hid)

        hid = self.p1.connect("list::pre-modified-meta", self.elt_handler)
        do_changes()
        self.assertEqual(self.buf,
            [(self.p1, L, "pre-modified-meta", (k, L.get_meta(k))),])
        del self.buf[:]
        self.p1.disconnect(hid)

        do_changes()
        self.assertEqual(self.buf, [])
Exemple #5
0
from libadvene.model.core.package import Package
from libadvene.model.core.media import FOREF_PREFIX

frame_of_reference = FOREF_PREFIX + "ms;o=0"

# This demonstrates how to create and save a package

# create a package with a relative URL
# NB: this is a *URL*, not a filename (that could be http://...)
# so use "/" as a separator, even in MS Windows
p = Package("examples/example1.bxp", create=True)

# add a resource to that package,
# the content is given by a URL, relative to the package's URL
r = p.create_resource("r", "text/x-python", url="example1.py")

# we save the current state of our package to another file
# NB: this is a filename, the separator is OS dependant
p.save_as("examples/example1-sav.bxp", erase=True)

# we now add a media
m = p.create_media("m", "dvd://", frame_of_reference)
p.save()

# we now save under a new name, and work on the new file
p.save_as("examples/example1-new.bxp", erase=True, change_url=True)
a = p.create_annotation("a", m, 0, 60, "text/plain")
p.save()

# Don't forget to close your package once you are done
p.close()
Exemple #6
0
            z.write(abspath, path.join(base, f).encode('utf-8'))


if __name__ == "__main__":
    # example of using ZIP serialization and parsing
    from libadvene.model.core.package import Package
    p = Package("file:/tmp/foo.bzp", create=True)

    # prepare directories
    if not exists("/tmp/foo"): mkdir("/tmp/foo")
    if not exists("/tmp/foo/data"): mkdir("/tmp/foo/data")

    # it is now safe to define the packaged-root of the package...
    p.set_meta(PACKAGED_ROOT, "/tmp/foo")
    # ... and to create packaged contents
    r = p.create_resource("R1", "text/plain", None, "packaged:/data/R1.txt")
    # this actually writes in /tmp/foo/data/R1.txt
    r.content_data = "good moaning\n"

    # let us serialize it...
    f = open("/tmp/foo.bzp", "w")
    serialize_to(p, f)
    f.close()
    # ... and parse it again
    q = Package("file:/tmp/foo.bzp")

    # note that advene_xml is smart enough to set the packaged-root if
    # needed, so as to allow to open manually-unzipped packages
    r = Package("file:/tmp/foo/content.xml")
    print r.get_meta(PACKAGED_ROOT)