How to use Persistence - 10 common examples

To help you get started, we’ve selected a few Persistence examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github infobyte / faraday / test_cases / persistence / db_connector.py View on Github external
def test_get_by_parent_and_type(self):
        couchConnector = CouchDbConnector(self.db)
        doc = {
            '_id': '123',
            'type': 'father',
            'parent': None,
        }
        couchConnector.saveDocument(doc)

        doc = {
            '_id': '456',
            'type': 'child',
            'parent': '123',
        }
        couchConnector.saveDocument(doc)

        doc = {
            '_id': '789',
github infobyte / faraday / test_cases / persistence / db_connector.py View on Github external
def test_save_Document(self):
        couchConnector = CouchDbConnector(self.db)
        doc = {
            '_id': '123',
            'data': 'some data'
        }
        couchConnector.saveDocument(doc)

        doc_from_db = self.db.get('123')

        self.assertNotEquals(
            doc_from_db,
            None,
            "Document should be retrieved")

        self.assertEquals(
            doc_from_db.get('data'),
            'some data',
github infobyte / faraday / test_cases / persistence / db_connector.py View on Github external
def test_get_Document(self):
        couchConnector = CouchDbConnector(self.db)
        doc = {
            '_id': '123',
            'data': 'some data'
        }
        couchConnector.saveDocument(doc)

        doc_retrieved = couchConnector.getDocument('123')

        self.assertNotEquals(
            doc_retrieved,
            None,
            "Document should be retrieved")

        self.assertEquals(
            doc_retrieved.get('data'),
            'some data',
github infobyte / faraday / test_cases / persistence / db_connector.py View on Github external
def test_remove_Document(self):
        couchConnector = CouchDbConnector(self.db)
        doc = {
            '_id': '123',
            'data': 'some data'
        }
        couchConnector.saveDocument(doc)

        couchConnector.remove('123')

        try:
            doc_from_db = self.db.get('123')
        except ResourceNotFound:
            doc_from_db = None

        self.assertEquals(
            doc_from_db,
            None,
github scanlime / picogui / apps / nifty / Nifty / Poing / db.py View on Github external
transaction.get_transaction().commit()
        print 'Poing db saved'

    save = commit

    def __getattr__(self, name):
        return self._r[name]

    def __setattr__(self, name, value):
        self._r[name] = value
        self.commit()

    def dir(self):
        return [(n, o) for n, o in self._r.items() if getattr(o, 'widget', None)]

class Container(persistence.Persistent):
    widget = Lister

    def dir(self):
        return [(n, o) for n, o in self.__dict__.items()
                if getattr(o, 'widget', None) and n[0] != '_']

    def save(self):
        transaction.get_transaction().commit()
        print 'Poing db saved'

class List(persistence.list.PersistentList):
    widget = Lister

    def save(self):
        transaction.get_transaction().commit()
        print 'Poing db saved'
github owenmorris / chandler / chandler / parcels / osaf / calendar / ColumnarSubView.py View on Github external
__copyright__ = "Copyright (c) 2002 Open Source Applications Foundation"
__license__ = "http://osafoundation.org/Chandler_0.1_license_terms.htm"

from wxPython.wx import *
from wxPython.xrc import *
from mx import DateTime

from application.Application import app
from application.SimpleCanvas import wxSimpleCanvas

from persistence import Persistent
from persistence.dict import PersistentDict

from OSAF.calendar.CalendarEvents import *

class ColumnarSubView (Persistent):
    def __init__(self, columnarView):
        self.columnarView = columnarView
        
        # Subclasses should set these attributes
        # self.xrcName = None
        # self.viewHeight = 0
        
    def SynchronizeView(self, view):
        view.OnInit(self)
    
    def getViewWidth(self):
        return self.columnarView.viewWidth
    
    def getDaysPerView(self):
        return self.columnarView.daysPerView
github owenmorris / chandler / chandler / parcels / osaf / calendar / MonthNavigator.py View on Github external
__revision__  = "$Revision$"
__date__      = "$Date$"
__copyright__ = "Copyright (c) 2002 Open Source Applications Foundation"
__license__ = "http://osafoundation.org/Chandler_0.1_license_terms.htm"

from wxPython.calendar import *
from wxPython.wx import *
from wxPython.xrc import *

from persistence import Persistent

from OSAF.calendar.CalendarEvents import *

from mx import DateTime

class MonthNavigator(Persistent):
    def __init__(self):
        pass
        
    def SynchronizeView(self, view):
        view.OnInit(self)
        

class wxMonthNavigator(wxCalendarCtrl):
    def __init__(self):
        value = wxPreCalendarCtrl()
        self.this = value.this
        self._setOORInfo(self)
        
    def OnInit(self, model):
        self.model = model
        self.SetWindowStyle(wxCAL_SUNDAY_FIRST |
github owenmorris / chandler / chandler / application / model_deprecated / LocalRepository.py View on Github external
_db = db.DB(_storage)
            _connection = _db.open()
            _dbroot = _connection.root()


            # begin {

            if _use_rap:
                hostname = "localhost"
                repname = "fs-trace-rep"
                _storage.setRepository(hostname, repname, _echo_rap)
            # } end


            if not _dbroot.has_key('classList'):
                _dbroot['classList'] = PersistentList()
            _local_shared_state['classList'] = _dbroot['classList']

            if not _dbroot.has_key('propertyList'):
                _dbroot['propertyList'] = PersistentList()
            _local_shared_state['propertyList'] = _dbroot['propertyList']

            if not _dbroot.has_key('objectList'):
                _dbroot['objectList'] = PersistentList()
            _local_shared_state['objectList'] = _dbroot['objectList']

            transaction.get_transaction().commit()

            # begin {
            if _displayRAPMessages:
                if _echo_rap:
                    if _use_rap:
github jpetazzo / griode / pickers.py View on Github external
[36, 35, None, None, 75, 56, None, 44],
    ],
)


class Melodic(enum.Enum):
    CHROMATIC = 1
    DIATONIC = 2
    MAGIC = 3


Drumkit = enum.Enum("Drumkit", list(DRUMKIT_MAPPINGS.keys()))



@persistent_attrs(root=48,
                  drumkit_mapping=Drumkit.FOUR_EIGHT,
                  melodic_mapping=Melodic.CHROMATIC)
class NotePicker(Gridget):

    def __init__(self, grid, channel):
        self.grid = grid
        self.surface = Surface(grid.surface)
        for button in "UP DOWN LEFT RIGHT".split():
            self.surface[button] = palette.CHANNEL[channel]
        self.channel = channel
        persistent_attrs_init(self, "{}__{}".format(self.grid.grid_name, channel))
        self.led2note = {}
        self.note2leds = collections.defaultdict(list)
        devicechain = self.grid.griode.devicechains[self.grid.channel]
        if devicechain.instrument.is_drumkit:
            self.mapping = self.drumkit_mapping
github jpetazzo / griode / griode.py View on Github external
from looper import Looper, LoopController
from gridgets import MENU, Menu
from mixer import Faders, Mixer
import notes
from palette import palette
from persistence import cache, persistent_attrs, persistent_attrs_init
from pickers import ColorPicker, InstrumentPicker, NotePicker, ScalePicker
import scales


log_format = "[%(levelname)s] %(filename)s:%(lineno)d %(funcName)s() -> %(message)s"
log_level = os.environ.get("LOG_LEVEL", "INFO").upper()
logging.basicConfig(level=log_level, format=log_format)


@persistent_attrs(key=notes.C, scale=scales.MAJOR)
class Griode(object):

    def __init__(self):
        persistent_attrs_init(self)
        self.synth = Fluidsynth()
        self.devicechains = [DeviceChain(self, i) for i in range(16)]
        self.grids = []
        self.cpu = CPU(self)
        self.clock = Clock(self)
        self.looper = Looper(self)
        self.mixer = Mixer(self)
        self.detect_devices()
        # FIXME: probably make this configurable somehow (env var...?)
        if False:
            from termpad import ASCIIGrid
            self.grids.append(ASCIIGrid(self, 0, 1))