Beispiel #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
Beispiel #2
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
Beispiel #3
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
Beispiel #4
0
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
Beispiel #5
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
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