Ejemplo n.º 1
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
Ejemplo n.º 2
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)