/[gzz]/gzz/gzz/slices/YAMLVersionFormatter.py
ViewVC logotype

Diff of /gzz/gzz/slices/YAMLVersionFormatter.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.13 by benja, Wed Jan 1 12:31:45 2003 UTC revision 1.14 by benja, Thu Jan 9 01:59:44 2003 UTC
# Line 16  Line 16 
16  #  #
17    
18    
 import yaml  
   
19  import gzz  import gzz
20    
21  from gzz.media import *  from gzz.media import *
# Line 49  class YAMLVersionFormat(VersionFormat): Line 47  class YAMLVersionFormat(VersionFormat):
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):

Legend:
Removed from v.1.13  
changed lines
  Added in v.1.14

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26