16 |
# |
# |
17 |
|
|
18 |
|
|
|
import yaml |
|
|
|
|
19 |
import gzz |
import gzz |
20 |
|
|
21 |
from gzz.media import * |
from gzz.media import * |
47 |
stream.close() |
stream.close() |
48 |
|
|
49 |
def readVersion(self, stream): |
def readVersion(self, stream): |
50 |
struct = yaml.load(str(String(CopyUtil.readBytes(stream))))[0] |
reader = gzz.slices.SliceVersionReader(stream, self.mediaserver, |
51 |
|
self.enfiladeMaker) |
52 |
|
return reader.readVersion() |
53 |
|
|
54 |
|
#struct = yaml.load(str(String(CopyUtil.readBytes(stream))))[0] |
55 |
#print struct |
#print struct |
56 |
return SliceVersion(*parseVersion(struct, self.mediaserver, self.enfiladeMaker)) |
#return SliceVersion(*parseVersion(struct, self.mediaserver, self.enfiladeMaker)) |
57 |
|
|
58 |
def readDiff(self, stream): |
def readDiff(self, stream): |
59 |
struct = yaml.load(str(String(CopyUtil.readBytes(stream))))[0] |
reader = gzz.slices.SliceVersionReader(stream, self.mediaserver, |
60 |
return SliceVersion.Diff(*parseDiff(struct, self.mediaserver, self.enfiladeMaker)) |
self.enfiladeMaker) |
61 |
|
return reader.readDiff() |
|
|
|
|
def parseVersion(struct, ms, maker): |
|
|
connections = HashSet() |
|
|
contents = HashMap() |
|
|
|
|
|
if(struct.has_key('Connections')): |
|
|
addConns(struct['Connections'], connections) |
|
|
|
|
|
if(struct.has_key('Content')): |
|
|
addContent(struct['Content'], contents, ms, maker) |
|
|
|
|
|
return (connections, contents) |
|
|
|
|
|
def parseDiff(struct, ms, maker): |
|
|
if(struct.has_key('Add')): |
|
|
connects, contents = parseVersion(struct['Add'], ms, maker) |
|
|
else: |
|
|
connects, contents = HashSet(), HashMap() |
|
|
|
|
|
if(struct.has_key('Remove')): |
|
|
disconnects, discontents = parseVersion(struct['Remove'], ms, maker) |
|
|
else: |
|
|
disconnects, discontents = HashSet(), HashMap() |
|
|
|
|
|
return (connects, disconnects, contents, discontents) |
|
|
|
|
|
def addConns(struct, into): |
|
|
for (dim, conns) in struct.items(): |
|
|
for (neg, pos) in conns: |
|
|
into.add(SliceVersion.Conn(dim, neg, pos)) |
|
|
|
|
|
def addContent(struct, into, ms, maker): |
|
|
for (cell, spanDefs) in struct.items(): |
|
|
spans = ArrayList() |
|
|
#if type(spanDefs) == type({}): |
|
|
# # work around a bug(?) in PyYAML |
|
|
# into.put(cell, maker.makeEnfilade()) |
|
|
# addContent(spanDefs, into, ms, maker) |
|
|
# continue |
|
|
|
|
|
for spanDef in spanDefs: |
|
|
t, id = spanDef[0:2] |
|
|
if not id.startswith("storm:block:"): |
|
|
raise IOException("Not a 'storm:block:' uri: %s" % (id,)) |
|
|
id = id[len("storm:block:"):] |
|
|
id = Mediaserver.Id(id) |
|
|
if t == 'TextSpan': |
|
|
block = ScrollBlockManager.getTextScrollBlock(ms, id) |
|
|
spans.add(block.getSpan(spanDef[2], |
|
|
spanDef[2] + spanDef[3])) |
|
|
elif t == 'ImageSpan' or t == 'PageSpan': |
|
|
spans.add(ScrollBlockManager.getSpan(ms, id, |
|
|
*spanDef[2:])) |
|
|
else: |
|
|
raise NotImplementedError("Unknown span type: %s" % (t,)) |
|
|
|
|
|
into.put(cell, maker.makeEnfilade(spans)) |
|
|
|
|
62 |
|
|
63 |
|
#struct = yaml.load(str(String(CopyUtil.readBytes(stream))))[0] |
64 |
|
#return SliceVersion.Diff(*parseDiff(struct, self.mediaserver, self.enfiladeMaker)) |
65 |
|
|
66 |
|
|
67 |
def dumpVersion(connections, content, ms): |
def dumpVersion(connections, content, ms): |