def _configDocChanged(self, pillow, doc):
        self._configDoc = doc
   
        if doc != None and doc.get("widgets." + self._template) == None:
            doc.set("widgets." + self._template, self._config)
            House.get("__CONFIG__").throw(Editor.Out.FieldChanged, "widgets." + self._template)

        self._configChanged(None, "widgets." + self._template)
    def registerConfigViewer(self):
        self._template = self.getWallabyTemplate()
        if self._template is None:
            self._template = unicode(self.objectName())

        if not self._configViewerRegistered:
            self._configViewerRegistered = True
            House.get("__CONFIG__").catch(Viewer.In.Refresh, self._configChanged)
            House.get("__CONFIG__").catch(Viewer.In.Document, self._configDocChanged)
    def __addPeer(self, room, name, config):
        if self._state not in ("Edit", "New", "Dirty"):
            from wallaby.qt_combat import QtGui
            import wallaby.FX as FX
            reply = QtGui.QMessageBox.question(FX.mainWindow, 'Edit configuration',
                "You must edit the configuration to add peers. Do you want to edit?", QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)

            if reply == QtGui.QMessageBox.Yes:
                from wallaby.pf.peer.editDocument import EditDocument
                self.throw(EditDocument.In.Edit, None)
            else:
                return

        from wallaby.pf.peer.documentChanger import DocumentChanger
        self.throw(DocumentChanger.In.InsertRow, ("rooms.*.Peers", {"name": name, "config": config}))

        from wallaby.pf.room import House

        observer = House.observer()
        cls = observer.peerClass(name)

        try:
            for dep in cls.Dependencies:
                observer = House.observer()
                cls2 = observer.peerClass(dep)

                config = {}
                try:
                    description = cls2.Description
                    if isinstance(description, (list, tuple)):
                        description, config = description
                except: pass

                print "Looking for", dep, "in", House.get(room).allPeers()
                if dep in House.get(room).allPeers():
                    continue

                found = False

                for peer in House.get(room).allPeers():
                    if dep == peer.__class__.__name__: 
                        found = True
                        break

                if found: continue

                self.__addPeer(room, dep, config)
        except: pass
    def __init__(self, srcRoom, dstRoom, pillow):
        Peer.__init__(self, srcRoom)
        
        from wallaby.pf.room import House
        self._dstRoom = House.get(dstRoom)

        self._catch(pillow, self._message)
    def __init__(self, room, dstRoom=None):
        Peer.__init__(self, room)
        self._document = None

        self._dstRoom = None

        if dstRoom != None:
            from wallaby.pf.room import House

            self._dstRoom = House.get(dstRoom)

        self._catch(DocumentChanger.In.Change, self._change)
        self._catch(DocumentChanger.In.Edit, self._edit)
        self._catch(DocumentChanger.In.Clone, self._clone)
        self._catch(DocumentChanger.In.SubClone, self._subClone)
        self._catch(DocumentChanger.In.Embed, self._embed)
        self._catch(Viewer.In.Document, self._setDocument)

        self._catch(DocumentChanger.In.InsertRow, self._insertRow)
        self._catch(DocumentChanger.In.RemoveRow, self._removeRow)

        self._catch(DocumentChanger.In.InsertKey, self._insertKey)
        self._catch(DocumentChanger.In.RemoveKey, self._removeKey)

        self._catch(DocumentChanger.In.MoveUp, self._up)
        self._catch(DocumentChanger.In.MoveDown, self._down)

        self._catch(DocumentChanger.In.Select, self._select)
Esempio n. 6
0
    def initialize(self):
        from wallaby.pf.room import House
        observer = House.observer()

        from wallaby.common.document import Document
        doc = Document()

        peerNames = sorted(observer.allPeers().keys())

        peers = []

        for peer in peerNames:
            ibp = observer.inBoundPillows(peer)
            obp = observer.outBoundPillows(peer)

            peers.append({
                "name": peer,
                "inBound": ibp,
                "outBound": obp
            })

        doc.set("peers", peers)
        self._throw(Viewer.In.Document, doc)
        
        # Wildcard credentials
        from credentials import Credentials
        self._throw(Credentials.Out.Credential, Document())
Esempio n. 7
0
    def test_02_view(self):
        global factory
        peers = ["ViewDocument", "DocumentCache", "DocumentDatabase", "CouchDB"]

        for p in peers:
            factory.peer(p, "room01")

        CredentialsParty()

        d = defer.Deferred()

        def callback(value):
            if value:
                d.callback(value)

        from wallaby.pf.peer.viewer import Viewer

        Viewer("room01", callback, "text")

        House.initializeAll()
        Peer.initializeAll()
        yield sleep(0.1)

        from wallaby.pf.peer.editDocument import EditDocument

        room = House.get("room01")
        room.throw(EditDocument.In.Load, self._docId)

        value = yield d
        self.assertEqual(value, "Hello World!")

        House.destroyRoom("room01")
        House.destroyRoom("__CREDENTIALS__")
Esempio n. 8
0
    def test_03_edit(self):
        global factory
        peers = ["EditDocument", "DocumentCache", "DocumentDatabase", "CouchDB"]

        for p in peers:
            factory.peer(p, "room01")

        CredentialsParty()

        valueDeferred = defer.Deferred()

        def valueCallback(value):
            if value == "Hello Jan":
                try:
                    valueDeferred.callback(value)
                except:
                    pass

        setRODeferred = defer.Deferred()

        def roCallback(readOnly):
            if not readOnly:
                try:
                    setRODeferred.callback(readOnly)
                except:
                    pass

        from wallaby.pf.peer.viewer import Viewer
        from wallaby.pf.peer.editor import Editor

        Viewer("room01", valueCallback, "text")
        editor = Editor("room01", path="text", setReadOnlyCallback=roCallback)

        House.initializeAll()
        Peer.initializeAll()
        yield sleep(0.1)

        from wallaby.pf.peer.editDocument import EditDocument

        room = House.get("room01")
        room.throw(EditDocument.In.LoadAndEdit, self._docId)

        yield setRODeferred
        editor.changeValue("Hello Jan")

        value = yield valueDeferred
        self.assertEqual(value, "Hello Jan")

        room.throw(EditDocument.In.Save, self._docId)

        from wallaby.pf.peer.database import Database

        docId = yield room.catchNow(Database.Out.DocumentSaved)
        self.assertEqual(docId, self._docId)

        doc = yield self._db.get(self._docId)
        self.assertEqual(doc["text"], "Hello Jan")

        House.destroyRoom("room01")
        House.destroyRoom("__CREDENTIALS__")
Esempio n. 9
0
    def __init__(self, srcRoom, dstRoom=None, viewIdentifier=None):
        Peer.__init__(self, srcRoom)

        from wallaby.pf.room import House
        self._dstRoom = House.get(dstRoom)

        self._viewIdentifier = viewIdentifier
        self._documentID = None
        self._queryDoc = None
        self._queryRoom = None

        self._catch(Viewer.In.Document, self._docChanged)
        self._catch(Relation.In.Add, self._add)
        self._catch(Relation.In.AddAndSave, self._addAndSave)

        if viewIdentifier != None:
            self._queryRoom = House.get(self._viewIdentifier.upper())

        if self._queryRoom:
            self._queryRoom.catch(Viewer.In.Document, self._queryDocChanged)
    def _configChanged(self, pillow, path):
        if not self._configDoc or not Viewer.matchPath("widgets." + self._template, path): return
        config = self._configDoc.get("widgets." + self._template)

        if config is not None:
            import json

            if self._lastConfig == None or json.dumps(self._lastConfig, sort_keys=True) != json.dumps(config, sort_keys=True):
                for k, v in config.items():
                    if k == "wallabyType" or (k in self.wallabyProperties and self.wallabyProperties[k].readOnly): 
                        continue
                    self._config[k] = v

                for k, v in self._config.items():
                    if k == "wallabyType" or (k in self.wallabyProperties and self.wallabyProperties[k].readOnly) or k not in config: 
                        config[k] = v

                self._lastConfig = copy.deepcopy(config)

                if self.room != None and len(self.room) > 0: House.get(self.room) # Implicit room creation...
                self.deregister()
                self.register()
Esempio n. 11
0
    def __init__(self, room, cb, feathers):
        Peer.__init__(self, room)
        self._cb = cb
        self._feathers = {}
        self._otherFeathers = {}

        self._enabled = {}

        self._negate = False
        self._negateOther = {}

        if feathers is None: return

        for p in feathers:
            if p is None: continue
            if ':' in p:
                room, p = p.split(':')
                if room not in self._otherFeathers: self._otherFeathers[room] = {}

                if p.startswith('!'):
                    p = p[1:]
                    self._negateOther[room] = True
                else:
                    self._negateOther[room] = False

                self._otherFeathers[room][p] = True
            else:
                if p.startswith('!'): 
                    p = p[1:]
                    self._negate = True

                self._feathers[p] = True

        if len(self._otherFeathers) > 0:
            if len(self._feathers) > 0:
                self._otherFeathers[self._roomName] = self._feathers
                self._negateOther[self._roomName] = self._negate

            i = 0
            for roomName in self._otherFeathers.keys():
                self._enabled[roomName] = False
                from wallaby.pf.room import House
                room = House.get(roomName)

                from functools import partial
                room.catch(Enabler.In.Enable, partial(self._enableOther, roomName))

        else:
            self._catch(Enabler.In.Enable, self._enable)
Esempio n. 12
0
    def test_01_database(self):
        global factory
        peers = ["CouchDB"]

        for p in peers:
            factory.peer(p, "room01")

        House.initializeAll()
        Peer.initializeAll()
        yield sleep(0.1)

        d = defer.Deferred()

        room = House.get("room01")

        from wallaby.pf.peer.database import Database

        room.catch(Database.Out.RequestedDocument, lambda *args: d.callback(args))
        room.throw(Database.In.RequestDocument, self._docId)

        pillow, doc = yield d
        self.assertEqual(doc.documentID, self._docId)

        House.destroyRoom("room01")
Esempio n. 13
0
    def __init__(self, roomName):
        if roomName == None: roomName = "None"

        self.initialized = False

        from wallaby.pf.room import House
        self.__room = House.get(roomName)
        Peer.peers.append(self)

        self._roomName = roomName

        self._routings = {}
        self._peers = []
        self._catchers = set()

        if 'Routings' in self.__class__.__dict__:
            for f, t in self.__class__.Routings:
                self._addRouting(f, t)

        self.destroyed = False
        self.__room.enter(self)

        from wallaby.pf.peer.viewer import Viewer
Esempio n. 14
0
# Copyright (c) by it's authors.
# Some rights reserved. See LICENSE, AUTHORS.

from twisted.internet import defer, reactor
from twisted.trial import unittest

from wallaby.pf.room import House
from wallaby.pf.peer.peer import Peer
from wallaby.pf.peer.credentialsParty import CredentialsParty

factory = House.observer()


def sleep(time):
    d = defer.Deferred()
    reactor.callLater(time, d.callback, None)
    return d


class WallabyCouchDBTest(unittest.TestCase):
    def setUp(self):
        self._dbName = "wallaby_test"
        self._docId = "testdoc"
        self.timeout = 1

        self._designDoc = {
            "_id": "_design/wallaby_test",
            "language": "javascript",
            "views": {"text": {"map": "function(doc) { if(doc.text)\n   emit(doc.text, null);\n}"}},
            "filters": {
                "typeB": 'function(doc, req) { if((doc.type && doc.type == "typeB") || doc.deleted) { return true; } return false;}'
    def _showConflictContextMenu(self, pos):
        globalPos = self.mapToGlobal(pos)

        if not self._hasConflict: 
            menuEntries = self.getMenuEntries()
            if menuEntries == None or len(menuEntries) == 0:
                return

            menu = QtGui.QMenu(self)
            for label, action in menuEntries.items():
                pillow = action
                feathers = None

                if isinstance(action, (list, tuple)): 
                    if len(action) == 2:
                        pillow, feathers = action
                    else:
                        pillow = action.pop(0)

                act = menu.addAction(label)
                act.pillow = pillow
                act.feathers = feathers

            action = menu.exec_(globalPos)
            if action != None:
                House.get(self.room).throw(action.pillow, act.feathers)

            return

        menu = QtGui.QMenu()
        if isinstance(self._currentValue, (list, dict)):
            mineAction = QtGui.QAction(FXUI.mineIcon, "use " + str(len(self._currentValue)) + " Item(s) (mine)", self)
        else:
            mineAction = QtGui.QAction(FXUI.mineIcon, "use >" + unicode(self._currentValue) + "< (mine)", self)

        menu.addAction(mineAction)

        mineAllAction = QtGui.QAction(FXUI.mineIcon, "use mine", self)
        menu.addAction(mineAllAction)

        theirsAction = []
        theirsAllAction = []
        
        for user, c in self._conflictValues:
            if user == None: user = "******"

            if isinstance(c, (list, dict)):
                act = QtGui.QAction(FXUI.theirsIcon, "use " + str(len(c)) + " Item(s) ("+user+")", self)
            else:
                act = QtGui.QAction(FXUI.theirsIcon, "use >" + unicode(c) + "< ("+user+")", self)
            theirsAction.append(act)
            menu.addAction(act)

            act = QtGui.QAction(FXUI.theirsIcon, "use theirs ("+user+")", self)
            theirsAllAction.append(act)
            menu.addAction(act)

        act = menu.exec_(globalPos)

        if act != None:
            if act == mineAllAction:
                self._resolve(self._currentValue, mine=True)
            elif act == mineAction:
                self._resolve(self._currentValue)
            else:
                if act in theirsAction:
                    idx = theirsAction.index(act)
                    self._resolve(self._conflictValues[idx][1])
                else:
                    idx = theirsAllAction.index(act)
                    self._resolve(self._conflictValues[idx][1], theirs=idx)

            self._conflict(False, self._currentValue, self._conflictValues)
 def _newSuggest(self, pillow, doc):
     self._suggests = doc
     House.get("__SUGGEST__").throw(Viewer.In.Document, doc)