Beispiel #1
0
    def _reopenRepository(self):
        self.rep.commit()

        if self.ramdb:
            self.rep.closeView()
            self.rep.openView()
        else:
            self.rep.close()
            self.rep = DBRepository(
                os.path.join(self.testdir, '__repository__'))
            self.rep.open()

        self.manager = \
         ParcelManager.get(self.rep.view, \
         path=[os.path.join(self.rootdir, 'parcels')])
Beispiel #2
0
    def setUp(self):
        schema.reset()  # clear schema state before starting
        self.chandlerDir = os.environ['CHANDLERHOME']
        self.repoDir = os.path.join(self.chandlerDir, '__repository__')

        rep = DBRepository(self.repoDir)
        kwds = {'create': True, 'refcounted': True, 'ramdb': True}
        rep.create(**kwds)

        if rep.findPath("//Schema") is None:
            rep.loadPack(
                os.path.join(self.chandlerDir, 'repository', 'packs',
                             'schema.pack'))
            rep.loadPack(
                os.path.join(self.chandlerDir, 'repository', 'packs',
                             'chandler.pack'))
        self.view = rep.getCurrentView()
Beispiel #3
0
    def _openRepository(self, ramdb=True):
        preloadedRepositoryPath = os.path.join(self.testdir,
                                               '__preloaded_repository__')
        self.rep = DBRepository(os.path.join(self.testdir, '__repository__'))

        if os.path.exists(preloadedRepositoryPath):
            self.ramdb = False
            self.rep.open(ramdb=False,
                          restore=preloadedRepositoryPath,
                          refcounted=True)
            self.rep.logger.setLevel(self.logLevel)
            self.rep.logger.info('Using preloaded repository')
        else:
            self.rep.create(ramdb=self.ramdb, refcounted=True)
            self.rep.logger.setLevel(self.logLevel)
            self.rep.loadPack(self.chandlerPack)
            self.rep.commit()

        self.manager = \
         ParcelManager.get(self.rep.view, \
         path=[os.path.join(self.rootdir, 'parcels')])
    def _reopenRepository(self):
        self.rep.commit()

        if self.ramdb:
            self.rep.closeView()
            self.rep.openView()
        else:
            self.rep.close()
            self.rep = DBRepository(os.path.join(self.testdir,
                                                 '__repository__'))
            self.rep.open()

        self.manager = \
         ParcelManager.get(self.rep.view, \
         path=[os.path.join(self.rootdir, 'parcels')])
    def _openRepository(self, ramdb=True):
        preloadedRepositoryPath = os.path.join(self.testdir, '__preloaded_repository__')
        self.rep = DBRepository(os.path.join(self.testdir, '__repository__'))

        if os.path.exists(preloadedRepositoryPath):
            self.ramdb = False
            self.rep.open(ramdb=False,
                          restore=preloadedRepositoryPath,
                          refcounted=True)
            self.rep.logger.setLevel(self.logLevel)
            self.rep.logger.info('Using preloaded repository')
        else:
            self.rep.create(ramdb=self.ramdb,
                            refcounted=True)
            self.rep.logger.setLevel(self.logLevel)
            self.rep.loadPack(self.chandlerPack)
            self.rep.commit()

        self.manager = \
         ParcelManager.get(self.rep.view, \
         path=[os.path.join(self.rootdir, 'parcels')])
Beispiel #6
0
def initRepository(directory, options):

    repository = DBRepository(directory)

    kwds = {
        "stderr": options.stderr,
        "ramdb": options.ramdb,
        "create": True,
        "recover": options.recover,
        "exclusive": True,
        "refcounted": True,
    }

    if options.restore:
        kwds["restore"] = options.restore

    while True:
        try:
            if options.encrypt:
                from getpass import getpass

                kwds["password"] = getpass("password> ")

            if options.create:
                repository.create(**kwds)
            else:
                repository.open(**kwds)
        except RepositoryPasswordError, e:
            if options.encrypt:
                print e.args[0]
            else:
                options.encrypt = True
            continue
        except RepositoryVersionError:
            repository.close()
            raise
 def setUp(self):
     self.rootdir = os.environ['CHANDLERHOME']
     self.testdir = os.path.join(self.rootdir, 'repository',
                                 'tests')
     self.rep = DBRepository(os.path.join(self.testdir, '__repository__'))
class TestRepositoryBasic(unittest.TestCase):
    """ Very basic repository tests """

    def _repositoryExists(self):
        try:
            self.rep.open()
            self.fail()
        except DBNoSuchFileError:
            pass
        except RepositoryOpenDeniedError:
            pass

    def setUp(self):
        self.rootdir = os.environ['CHANDLERHOME']
        self.testdir = os.path.join(self.rootdir, 'repository',
                                    '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 """
        util.timing.reset()
        util.timing.begin("repository.TestRepositoryBasic.testCreate")
        self.rep.create()
        util.timing.end("repository.TestRepositoryBasic.testCreate")
        util.timing.results(verbose=False)
        self.assert_(self.rep.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
TODO is there more pack testing we need to do?
        """
        self.rep.create()
        self.assert_(self.rep.check())
        util.timing.reset()
        util.timing.begin("repository.TestRepositoryBasic.testLoadPack")
        self.rep.getCurrentView()
        util.timing.end("repository.TestRepositoryBasic.testLoadPack")
        util.timing.results(verbose=False)
        self.assert_(self.rep.check())
    
    def tearDown(self):
        self.rep.close()
        self.rep.delete()
class RepositoryTestCase(TestCase):

    logLevel = logging.WARNING      # a nice quiet default

    def _setup(self, ramdb=True):
        schema.reset()
        self.rootdir = os.environ['CHANDLERHOME']
        self.chandlerPack = os.path.join(self.rootdir, 'repository',
                                         'packs', 'chandler.pack')

        handler = \
         logging.FileHandler(os.path.join(self.rootdir,'chandler.log'))
        formatter = \
         logging.Formatter('%(asctime)s %(name)s %(levelname)s %(message)s')
        handler.setFormatter(formatter)
        root = logging.getLogger()
        root.addHandler(handler)

        self.ramdb = ramdb

    def _openRepository(self, ramdb=True):
        preloadedRepositoryPath = os.path.join(self.testdir, '__preloaded_repository__')
        self.rep = DBRepository(os.path.join(self.testdir, '__repository__'))

        if os.path.exists(preloadedRepositoryPath):
            self.ramdb = False
            self.rep.open(ramdb=False,
                          restore=preloadedRepositoryPath,
                          refcounted=True)
            self.rep.logger.setLevel(self.logLevel)
            self.rep.logger.info('Using preloaded repository')
        else:
            self.rep.create(ramdb=self.ramdb,
                            refcounted=True)
            self.rep.logger.setLevel(self.logLevel)
            self.rep.loadPack(self.chandlerPack)
            self.rep.commit()

        self.manager = \
         ParcelManager.get(self.rep.view, \
         path=[os.path.join(self.rootdir, 'parcels')])

    def setUp(self, ramdb=True):
        self._setup(ramdb)

        self.testdir = os.path.join(self.rootdir, 'repository',
                                    'tests')
        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):
        self.rep.commit()

        if self.ramdb:
            self.rep.closeView()
            self.rep.openView()
        else:
            self.rep.close()
            self.rep = DBRepository(os.path.join(self.testdir,
                                                 '__repository__'))
            self.rep.open()

        self.manager = \
         ParcelManager.get(self.rep.view, \
         path=[os.path.join(self.rootdir, 'parcels')])

    def _find(self, path):
        return self.rep.findPath(path)

    def loadParcel(self, namespace):
        self.loadParcels([namespace])

    def loadParcels(self, namespaces=None):

        self.manager.loadParcels(namespaces)
        if namespaces:
            for namespace in namespaces:
                parcelItem = self.manager.lookup(namespace)
                self.assert_(parcelItem)
                # print "Loaded namespace %s as item %s" % \
                # (namespace, parcelItem.itsPath)

    _KIND_KIND = Path("//Schema/Core/Kind")
    _ITEM_KIND = Path("//Schema/Core/Item")

    # Repository specific assertions
    def assertIsRoot(self, item):
        self.assert_(item in list(self.rep.iterRoots()))

    def assertItemPathEqual(self, item, string):
        self.assertEqual(str(item.itsPath), string)
 def setUp(self):
     self.rootdir = os.environ['CHANDLERHOME']
     self.testdir = os.path.join(self.rootdir, 'repository', 'tests')
     self.rep = DBRepository(os.path.join(self.testdir, '__repository__'))
class TestRepositoryBasic(unittest.TestCase):
    """ Very basic repository tests """
    def _repositoryExists(self):
        try:
            self.rep.open()
            self.fail()
        except DBNoSuchFileError:
            pass
        except RepositoryOpenDeniedError:
            pass

    def setUp(self):
        self.rootdir = os.environ['CHANDLERHOME']
        self.testdir = os.path.join(self.rootdir, 'repository', '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 """
        util.timing.reset()
        util.timing.begin("repository.TestRepositoryBasic.testCreate")
        self.rep.create()
        util.timing.end("repository.TestRepositoryBasic.testCreate")
        util.timing.results(verbose=False)
        self.assert_(self.rep.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
TODO is there more pack testing we need to do?
        """
        self.rep.create()
        self.assert_(self.rep.check())
        util.timing.reset()
        util.timing.begin("repository.TestRepositoryBasic.testLoadPack")
        self.rep.getCurrentView()
        util.timing.end("repository.TestRepositoryBasic.testLoadPack")
        util.timing.results(verbose=False)
        self.assert_(self.rep.check())

    def tearDown(self):
        self.rep.close()
        self.rep.delete()
Beispiel #12
0
def repository(directory, destroy=False):
    """
    Create an instance of a repository (or open one if existing)

    If the repository hasn't had its //Schema loaded, the schema.pack will
    get loaded.  Also the notification manager will be initialized.

    @param directory: The directory to use for the repository files
    @type directory: string
    @param destroy: If True, wipe out existing repository first (default=False)
    @type directory: boolean
    @return: the repository object
    """

    from repository.persistence.DBRepository import DBRepository
    rep = DBRepository(directory)

    kwds = { 'create' : True, 'recover' : True, 'refcounted' : True }
    if destroy:
        rep.create(**kwds)
    else:
        rep.open(**kwds)

    if rep.findPath("//Schema") is None:
        rep.loadPack(os.path.join(Globals.chandlerDirectory, 'repository',
         'packs', 'schema.pack'))
        rep.loadPack(os.path.join(Globals.chandlerDirectory, 'repository',
         'packs', 'chandler.pack'))

    return rep
Beispiel #13
0
class RepositoryTestCase(TestCase):

    logLevel = logging.WARNING  # a nice quiet default

    def _setup(self, ramdb=True):
        schema.reset()
        self.rootdir = os.environ['CHANDLERHOME']
        self.chandlerPack = os.path.join(self.rootdir, 'repository', 'packs',
                                         'chandler.pack')

        handler = \
         logging.FileHandler(os.path.join(self.rootdir,'chandler.log'))
        formatter = \
         logging.Formatter('%(asctime)s %(name)s %(levelname)s %(message)s')
        handler.setFormatter(formatter)
        root = logging.getLogger()
        root.addHandler(handler)

        self.ramdb = ramdb

    def _openRepository(self, ramdb=True):
        preloadedRepositoryPath = os.path.join(self.testdir,
                                               '__preloaded_repository__')
        self.rep = DBRepository(os.path.join(self.testdir, '__repository__'))

        if os.path.exists(preloadedRepositoryPath):
            self.ramdb = False
            self.rep.open(ramdb=False,
                          restore=preloadedRepositoryPath,
                          refcounted=True)
            self.rep.logger.setLevel(self.logLevel)
            self.rep.logger.info('Using preloaded repository')
        else:
            self.rep.create(ramdb=self.ramdb, refcounted=True)
            self.rep.logger.setLevel(self.logLevel)
            self.rep.loadPack(self.chandlerPack)
            self.rep.commit()

        self.manager = \
         ParcelManager.get(self.rep.view, \
         path=[os.path.join(self.rootdir, 'parcels')])

    def setUp(self, ramdb=True):
        self._setup(ramdb)

        self.testdir = os.path.join(self.rootdir, 'repository', 'tests')
        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):
        self.rep.commit()

        if self.ramdb:
            self.rep.closeView()
            self.rep.openView()
        else:
            self.rep.close()
            self.rep = DBRepository(
                os.path.join(self.testdir, '__repository__'))
            self.rep.open()

        self.manager = \
         ParcelManager.get(self.rep.view, \
         path=[os.path.join(self.rootdir, 'parcels')])

    def _find(self, path):
        return self.rep.findPath(path)

    def loadParcel(self, namespace):
        self.loadParcels([namespace])

    def loadParcels(self, namespaces=None):

        self.manager.loadParcels(namespaces)
        if namespaces:
            for namespace in namespaces:
                parcelItem = self.manager.lookup(namespace)
                self.assert_(parcelItem)
                # print "Loaded namespace %s as item %s" % \
                # (namespace, parcelItem.itsPath)

    _KIND_KIND = Path("//Schema/Core/Kind")
    _ITEM_KIND = Path("//Schema/Core/Item")

    # Repository specific assertions
    def assertIsRoot(self, item):
        self.assert_(item in list(self.rep.iterRoots()))

    def assertItemPathEqual(self, item, string):
        self.assertEqual(str(item.itsPath), string)