def _openRepository(self, ramdb=True): self.rep = DBRepository(os.path.join(self.testdir, '__repository__')) self.rep.create(ramdb=self.ramdb, refcounted=True) self.rep.logger.setLevel(self.logLevel) self.view = view = self.rep.createView("Test") view.commit()
def _reopenRepository(self): view = self.view view.commit() if self.ramdb: view.closeView() view.openView() else: dbHome = self.rep.dbHome self.rep.close() self.rep = DBRepository(dbHome) self.rep.open() self.view = view = self.rep.createView("Test")
def setUp(self): self.chandlerDir = os.environ['CHANDLERHOME'] self.repoDir = os.path.join(self.chandlerDir, '__repository__') rep = DBRepository(self.repoDir) rep.create(create=True, refcounted=True, ramdb=True) view = rep.createView() if view.getRoot("Schema") is None: view.loadPack('packs/schema.pack', package='chandlerdb') view.loadPack(os.path.join(self.chandlerDir, 'repository', 'packs', 'chandler.pack')) self.view = view self.trash = schema.ns('osaf.pim', view).trashCollection
def makeUncompressedBackup(options, masterPassword=False): """Create a backup directory, return the path to the backup. Falls back to using the repository directory if backup fails. """ from chandlerdb.persistence.DBRepository import DBRepository repoDir = locateRepositoryDirectory(options.profileDir, options) try: repository = DBRepository(repoDir) # use logged=True to prevent repo from setting up stderr logging repository.open(recover=True, exclusive=False, logged=True) view = repository.createView() if masterPassword: try: MasterPassword.beforeBackup(view, self) except: wx.MessageBox(_(u'Failed to encrypt passwords.'), _(u'Password Protection Failed'), parent=self) repoDir = repository.backup( os.path.join(options.profileDir, '__repository__.backup')) repository.close() except: # if repoDir is unchanged, the original is taken instead pass if isinstance(repoDir, unicode): repoDir = repoDir.encode(sys.getfilesystemencoding()) return repoDir
def setUp(self): self.chandlerDir = os.environ['CHANDLERHOME'] self.repoDir = os.path.join(self.chandlerDir, '__repository__') rep = DBRepository(self.repoDir) rep.create(create=True, refcounted=True, ramdb=True) view = rep.createView() if view.getRoot("Schema") is None: view.loadPack('packs/schema.pack', package='chandlerdb') view.loadPack( os.path.join(self.chandlerDir, 'repository', 'packs', 'chandler.pack')) self.view = view self.trash = schema.ns('osaf.pim', view).trashCollection
def makeUncompressedBackup(options, masterPassword=False): """Create a backup directory, return the path to the backup. Falls back to using the repository directory if backup fails. """ from chandlerdb.persistence.DBRepository import DBRepository repoDir = locateRepositoryDirectory(options.profileDir, options) try: repository = DBRepository(repoDir) # use logged=True to prevent repo from setting up stderr logging repository.open(recover=True, exclusive=False, logged=True) view = repository.createView() if masterPassword: try: MasterPassword.beforeBackup(view, self) except: wx.MessageBox(_(u'Failed to encrypt passwords.'), _(u'Password Protection Failed'), parent=self) repoDir = repository.backup(os.path.join(options.profileDir, '__repository__.backup')) repository.close() except: # if repoDir is unchanged, the original is taken instead pass if isinstance(repoDir, unicode): repoDir = repoDir.encode(sys.getfilesystemencoding()) return repoDir
def _openRepository(self, ramdb=True): self.rep = DBRepository(os.path.join(self.testdir, "__repository__")) self.rep.create(ramdb=self.ramdb, refcounted=True) self.rep.logger.setLevel(self.logLevel) self.view = view = self.rep.createView("Test") view.commit()
def initRepository(directory, options, allowSchemaView=False): from chandlerdb.persistence.DBRepository import DBRepository if options.uuids: input = file(options.uuids) loadUUIDs([UUID(uuid.strip()) for uuid in input if len(uuid) > 1]) input.close() if options.checkpoints == 'none': options.checkpoints = None else: options.checkpoints = int(options.checkpoints) # minutes repository = DBRepository(directory) kwds = { 'stderr': options.stderr, 'ramdb': options.ramdb, 'create': True, 'recover': options.recover, 'forceplatform': options.forceplatform, 'exclusive': not options.nonexclusive, 'memorylog': options.memorylog, 'mvcc': options.mvcc and not options.nomvcc, 'prune': int(options.prune), 'logdir': options.logdir, 'datadir': options.datadir, 'nodeferdelete': options.nodeferdelete, 'refcounted': True, 'checkpoints': options.checkpoints, 'logged': not not options.logging, 'timezone': options.timezone or ICUtzinfo.default, 'ontzchange': lambda view, newtz: view.logger.warning("%s: timezone changed to %s", view, newtz), 'verify': options.verify or __debug__ } if options.restore: kwds['restore'] = options.restore while True: try: if options.encrypt: kwds['password'] = options.getPassword else: kwds.pop('password', None) if options.create: repository.create(**kwds) else: repository.open(**kwds) except RepositoryPasswordError, e: options.encrypt = e.args[0] continue except RepositoryVersionError: repository.close() raise
def _reopenRepository(self): view = self.view view.commit() if self.ramdb: view.closeView() view.openView() else: dbHome = self.rep.dbHome self.rep.close() self.rep = DBRepository(dbHome) self.rep.open() self.view = view = self.rep.createView("Test")
class RepositoryTestCase(TestCase): logLevel = logging.WARNING # a nice quiet default def _openRepository(self, ramdb=True): self.rep = DBRepository(os.path.join(self.testdir, '__repository__')) self.rep.create(ramdb=self.ramdb, refcounted=True) self.rep.logger.setLevel(self.logLevel) self.view = view = self.rep.createView("Test") view.commit() def setUp(self, ramdb=True, testdir='tests'): self.ramdb = ramdb self.testdir = testdir self._openRepository(ramdb) def tearDown(self): self.rep.close() self.rep.logger.debug('RAMDB = %s', self.ramdb) if not self.ramdb: self.rep.delete() def _reopenRepository(self): view = self.view view.commit() if self.ramdb: view.closeView() view.openView() else: dbHome = self.rep.dbHome self.rep.close() self.rep = DBRepository(dbHome) self.rep.open() self.view = view = self.rep.createView("Test") def loadCineguide(self, view, commit=True): view.loadPack('data/packs/cineguide.pack', package='tests') if commit: view.commit() def loadCollections(self, view, commit=True): view.loadPack('data/packs/collections.pack', package='tests') if commit: view.commit() _KIND_KIND = Path("//Schema/Core/Kind") _ITEM_KIND = Path("//Schema/Core/Item") # Repository specific assertions def assertIsRoot(self, item): self.assert_(item in list(item.itsView.iterRoots())) def assertItemPathEqual(self, item, string): self.assertEqual(str(item.itsPath), string) def setLoggerLevel(self, level): current = self.rep.logger.level self.rep.logger.setLevel(level) return current
# Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from chandlerdb.persistence.DBRepository import DBRepository from chandlerdb.item.Sets import KindSet r = DBRepository('data') r.create() r = r.view r.setBackgroundIndexed(True) r.loadPack('repository/tests/data/packs/cineguide.pack') k = r.findPath('//CineGuide/KHepburn') k.movies.addIndex('n', 'numeric') k.movies.addIndex('t', 'value', attribute='title', ranges=[(0, 1)]) k.movies.addIndex('f', 'string', attributes=('frenchTitle', 'title'), locale='fr_FR') m1 = r.findPath('//CineGuide/KHepburn').movies.first() m1.director.itsKind.getAttribute('directed').type = m1.itsKind k.set = KindSet(m1.itsKind, True) k.set.addIndex('t', 'value', attribute='title', ranges=[(0, 1)])
def setUp(self): self.rootdir = '.' self.testdir = os.path.join(self.rootdir, 'tests') self.rep = DBRepository(os.path.join(self.testdir, '__repository__'))
class TestRepositoryBasic(TestCase): """ Very basic tests """ def _repositoryExists(self): try: self.rep.open() self.fail() except DBNoSuchFileError: pass except RepositoryOpenDeniedError: pass except RepositoryVersionError: pass def setUp(self): self.rootdir = '.' self.testdir = os.path.join(self.rootdir, 'tests') self.rep = DBRepository(os.path.join(self.testdir, '__repository__')) def testNonExistent(self): """ The repository should not exist at this point """ self.assert_(not self._repositoryExists()) def testCreate(self): """ Create a repository and make sure it is open """ self.rep.create() self.view = view = self.rep.createView() self.assert_(self.view.check()) self.assert_(self.rep.isOpen()) def testDestroy(self): """ Create and then delete a repository, verify it doesn't exist """ self.rep.create() self.rep.close() self.rep.delete() self.assert_(not self._repositoryExists()) def testLoadPack(self): """ Minimal test to ensure that we can load packs """ self.rep.create() view = self.rep.createView() self.assert_(view.check()) def tearDown(self): self.rep.close() self.rep.delete()
# Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from chandlerdb.persistence.DBRepository import DBRepository from chandlerdb.item.Sets import KindSet r = DBRepository('data') r.create() r = r.view r.setBackgroundIndexed(True) r.loadPack('repository/tests/data/packs/cineguide.pack') k = r.findPath('//CineGuide/KHepburn') k.movies.addIndex('n', 'numeric') k.movies.addIndex('t', 'value', attribute='title', ranges=[(0, 1)]) k.movies.addIndex('f', 'string', attributes=('frenchTitle', 'title'), locale='fr_FR') m1 = r.findPath('//CineGuide/KHepburn').movies.first() m1.director.itsKind.getAttribute('directed').type = m1.itsKind
def initRepository(directory, options, allowSchemaView=False): from chandlerdb.persistence.DBRepository import DBRepository if options.uuids: input = file(options.uuids) loadUUIDs([UUID(uuid.strip()) for uuid in input if len(uuid) > 1]) input.close() if options.checkpoints == 'none': options.checkpoints = None else: options.checkpoints = int(options.checkpoints) # minutes repository = DBRepository(directory) kwds = { 'stderr': options.stderr, 'ramdb': options.ramdb, 'create': True, 'recover': options.recover, 'forceplatform': options.forceplatform, 'exclusive': not options.nonexclusive, 'memorylog': options.memorylog, 'mvcc': options.mvcc and not options.nomvcc, 'prune': int(options.prune), 'logdir': options.logdir, 'datadir': options.datadir, 'nodeferdelete': options.nodeferdelete, 'refcounted': True, 'checkpoints': options.checkpoints, 'logged': not not options.logging, 'timezone': options.timezone or ICUtzinfo.default, 'ontzchange': lambda view, newtz: view.logger.warning("%s: timezone changed to %s", view, newtz), 'verify': options.verify or __debug__ } if options.restore: kwds['restore'] = options.restore while True: try: if options.encrypt: kwds['password'] = options.getPassword else: kwds.pop('password', None) if options.create: repository.create(**kwds) else: repository.open(**kwds) except RepositoryPasswordError, e: options.encrypt = e.args[0] continue except RepositoryVersionError: repository.close() raise
class TestRepositoryBasic(TestCase): """ Very basic tests """ def _repositoryExists(self): try: self.rep.open() self.fail() except DBNoSuchFileError: pass except RepositoryOpenDeniedError: pass except RepositoryVersionError: pass def setUp(self): self.rootdir = '.' self.testdir = os.path.join(self.rootdir, 'tests') self.rep = DBRepository(os.path.join(self.testdir, '__repository__')) def testNonExistent(self): """ The repository should not exist at this point """ self.assert_(not self._repositoryExists()) def testCreate(self): """ Create a repository and make sure it is open """ self.rep.create() self.view = view = self.rep.createView() self.assert_(self.view.check()) self.assert_(self.rep.isOpen()) def testDestroy(self): """ Create and then delete a repository, verify it doesn't exist """ self.rep.create() self.rep.close() self.rep.delete() self.assert_(not self._repositoryExists()) def testLoadPack(self): """ Minimal test to ensure that we can load packs """ self.rep.create() view = self.rep.createView() self.assert_(view.check()) def tearDown(self): self.rep.close() self.rep.delete()
class RepositoryTestCase(TestCase): logLevel = logging.WARNING # a nice quiet default def _openRepository(self, ramdb=True): self.rep = DBRepository(os.path.join(self.testdir, "__repository__")) self.rep.create(ramdb=self.ramdb, refcounted=True) self.rep.logger.setLevel(self.logLevel) self.view = view = self.rep.createView("Test") view.commit() def setUp(self, ramdb=True, testdir="tests"): self.ramdb = ramdb self.testdir = testdir self._openRepository(ramdb) def tearDown(self): self.rep.close() self.rep.logger.debug("RAMDB = %s", self.ramdb) if not self.ramdb: self.rep.delete() def _reopenRepository(self): view = self.view view.commit() if self.ramdb: view.closeView() view.openView() else: dbHome = self.rep.dbHome self.rep.close() self.rep = DBRepository(dbHome) self.rep.open() self.view = view = self.rep.createView("Test") def loadCineguide(self, view, commit=True): view.loadPack("data/packs/cineguide.pack", package="tests") if commit: view.commit() def loadCollections(self, view, commit=True): view.loadPack("data/packs/collections.pack", package="tests") if commit: view.commit() _KIND_KIND = Path("//Schema/Core/Kind") _ITEM_KIND = Path("//Schema/Core/Item") # Repository specific assertions def assertIsRoot(self, item): self.assert_(item in list(item.itsView.iterRoots())) def assertItemPathEqual(self, item, string): self.assertEqual(str(item.itsPath), string) def setLoggerLevel(self, level): current = self.rep.logger.level self.rep.logger.setLevel(level) return current
def setUp(self): self.rootdir = '.' self.testdir = os.path.join(self.rootdir, 'tests') self.rep = DBRepository(os.path.join(self.testdir, '__repository__'))