Exemplo n.º 1
0
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 _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 setUp(self):
     self.rootdir = '.'
     self.testdir = os.path.join(self.rootdir, 'tests')
     self.rep = DBRepository(os.path.join(self.testdir, '__repository__'))
Exemplo n.º 6
0
#   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
Exemplo n.º 7
0
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