def __init__(self, name):
        """
        Initialize 
        """
        log.debug(u"init " + repr(name))
        self._nextIdeviceId = 0
        self._nextNodeId    = 0
        # For looking up nodes by ids
        self._nodeIdDict    = {} 

        self._levelNames    = self.defaultLevelNames[:]
        self.name           = name
        self._title         = u''
        self._backgroundImg = u''
        self.backgroundImgTile = False

        # Empty if never saved/loaded
        self.filename      = u''

        self.root          = Node(self, None, _(u"Home"))
        self.currentNode   = self.root
        self.style         = u"default"
        self.isChanged     = False
        self.idevices      = []
        self.dublinCore    = DublinCore()
        self.scolinks      = False
        self.license       = "None"
        self.footer        = ""

        # Temporary directory to hold resources in
        self.resourceDir = TempDirPath()
        self.resources = {} # Checksum-[_Resource(),..]
    def upgradeToVersion1(self):
        """
        Called to upgrade from 0.3 release
        """
        self._nextNodeId = 0
        self._nodeIdDict = {}

        # Also upgrade all the nodes.
        # This needs to be done here so that draft gets id 0
        # If it's done in the nodes, the ids are assigned in reverse order
        draft = getattr(self, 'draft')
        draft._id = self._regNewNode(draft)
        draft._package = self
        setattr(self, 'editor', Node(self, None, _(u"iDevice Editor")))

        # Add a default idevice to the editor
        idevice = GenericIdevice("", "", "", "", "")
        editor = getattr(self, 'editor')
        idevice.parentNode = editor
        editor.addIdevice(idevice)
        def superReg(node):
            """Registers all our nodes
            because in v0 they were not registered
            in this way"""
            node._id = self._regNewNode(node)
            node._package = self
            for child in node.children:
                superReg(child)
        superReg(self.root)
Пример #3
0
    def testOutline(self):
        root = Node()
        root.title = "level 1 root"
        child1 = root.createChild()

        child1.title = "level 2 child 1"
        grandChild11 = child1.createChild()
        grandChild11.title = "level 3 child 11"
        grandChild12 = child1.createChild()
        grandChild12.title = "level 3 child 12"

        child2 = root.createChild()
        child2.title = "level 2 child 2"
        grandChild21 = child2.createChild()
        grandChild21.title = "level 3 child 21"
        grandChild22 = child2.createChild()
        grandChild22.title = "level 3 child 22"

        child3 = root.createChild()
        child3.title = "level 2 child 3"
        child4 = root.createChild()
        child4.title = "level 2 child 4"

        outlinePane = OutlinePaneForTest(root)
        #  print root.children
        #  print child2.id
        print outlinePane.render()
 def testDelete(self):
     parentNode = Node(self.package)
     idevice0 = Idevice("FirstIdevice", "", "", "", "")
     idevice0.setParentNode(parentNode)
     idevice1 = Idevice("SecondIdevice", "", "", "", "")
     idevice1.setParentNode(parentNode)
     idevice2 = Idevice("ThirdIdevice", "", "", "", "")
     idevice2.setParentNode(parentNode)
     idevice1.delete()
     if idevice1 in parentNode.idevices:
         print "delete failed"
    def testIsfirstAndIsLast(self):
        parentNode = Node(self.package)
        idevice0 = Idevice("FirstIdevice", "", "", "", "")
        idevice0.setParentNode(parentNode)
        idevice1 = Idevice("SecondIdevice", "", "", "", "")
        idevice1.setParentNode(parentNode)
        idevice2 = Idevice("ThirdIdevice", "", "", "", "")
        idevice2.setParentNode(parentNode)

        self.assert_(idevice0.isFirst)
        self.assert_(idevice2.isLast)
Пример #6
0
 def testOutline(self):
     root = Node()
     root.title = "level 1 root"
     child1 = root.createChild()
     
     child1.title = "level 2 child 1"
     grandChild11 = child1.createChild()
     grandChild11.title = "level 3 child 11"
     grandChild12 = child1.createChild()
     grandChild12.title = "level 3 child 12"
     
     child2 = root.createChild()
     child2.title = "level 2 child 2"
     grandChild21 = child2.createChild()
     grandChild21.title = "level 3 child 21"
     grandChild22 = child2.createChild()
     grandChild22.title = "level 3 child 22"
     
     child3 = root.createChild()
     child3.title = "level 2 child 3"
     child4 = root.createChild()
     child4.title = "level 2 child 4"
     
     outlinePane = OutlinePaneForTest(root)
   #  print root.children
   #  print child2.id
     print outlinePane.render()
Пример #7
0
    def _testNodeIds(self):
        package = self.package
        assert package._nextNodeId == 1, package._nextNodeId
        assert package.findNode(package.root.id) is package.root
        newNode = Node(package, package.root)
        assert package.findNode('123') is None
        assert package.findNode(newNode.id) is newNode
        # Save the package
        package.name = 'testing'
        package.save('testing.elp')
        # load the package
        package2 = package.load('testing.elp')

        def checkInst(inst1, inst2):
            d1 = inst1.__dict__
            d2 = inst2.__dict__
            for key, val in d1.items():
                val2 = d2.get(key)
                if key == 'parentNode' and isinstance(val, Node):
                    assert val2.title.title == val.title.title
                elif key == 'package':
                    assert val is package
                    assert val2 is package2
                elif isinstance(val, list):
                    assert len(val) == len(val2)
                    for i, i2 in zip(val, val2):
                        if isinstance(i, basestring):
                            assert (i == i2, '%s.%s: [%s/%s]' %
                                    (inst1.__class__.__name__, key, i2, i))
                        else:
                            checkInst(i, i2)
                elif key == '_nodeIdDict' and isinstance(val, dict):
                    assert len(val) == len(val2)
                    for nodeName in val:
                        assert val2.has_key(nodeName)
                elif isinstance(val, Node):
                    pass
                elif key in Package.nonpersistant:
                    # Non persistent should exist after load
                    # but not be the same
                    assert d2.has_key(key)
                elif key == 'dublinCore':
                    checkInst(val, val2)
                else:
                    # Everything else must match
                    self.assertEquals(val, val2)
                    assert val == val2, '%s.%s: %s/%s' % (
                        inst1.__class__.__name__, key, val2, val)

        checkInst(package, package2)
    def testMove(self):
        parentNode = Node(self.package)
        idevice0 = Idevice("FirstIdevice", "", "", "", "")
        idevice0.setParentNode(parentNode)
        idevice1 = Idevice("SecondIdevice", "", "", "", "")
        idevice1.setParentNode(parentNode)
        idevice2 = Idevice("ThirdIdevice", "", "", "", "")
        idevice2.setParentNode(parentNode)

        idevice0.moveNext()
        self.assertEquals(parentNode.idevices[1], idevice0)
        self.assertEquals(parentNode.idevices[0], idevice1)

        idevice2.movePrev()
        self.assertEquals(parentNode.idevices[1], idevice2)
        self.assertEquals(parentNode.idevices[2], idevice0)
 def testSetParentNode(self):
     parentNode = Node(self.package)
     idevice0 = Idevice("FirstIdevice", "", "", "", "")
     idevice0.setParentNode(parentNode)
     self.assert_(idevice0.parentNode is parentNode)