Ejemplo n.º 1
0
    def setUp(self):
        self.repoBasePath = tests_context.TEST_REPO_BASE_PATH
        self.copyOfRepoBasePath = tests_context.COPY_OF_TEST_REPO_BASE_PATH

        if (os.path.exists(self.copyOfRepoBasePath)):
            shutil.rmtree(self.copyOfRepoBasePath)
        shutil.copytree(self.repoBasePath, self.copyOfRepoBasePath)

        self.repo = RepoMgr(self.copyOfRepoBasePath)
Ejemplo n.º 2
0
    def handle(self):
        try:
            action = self.sender()
            repoBasePath = action.repoBasePath

            currentUser = self._model.user
            assert currentUser is not None

            self._model.repo = RepoMgr(repoBasePath)

            try:
                self._model.loginUser(currentUser.login, currentUser.password)
                self._emitHandlerSignal(
                    HandlerSignals.STATUS_BAR_MESSAGE,
                    self.tr("Repository opened. Login succeded."),
                    STATUSBAR_TIMEOUT)

            except LoginError:
                self._model.user = None
                self._emitHandlerSignal(
                    HandlerSignals.STATUS_BAR_MESSAGE,
                    self.tr("Repository opened. Login failed."),
                    STATUSBAR_TIMEOUT)

            stats.sendEvent("main_window.open_favorite_repo")

        except Exception as ex:
            show_exc_info(self._model.gui, ex)
Ejemplo n.º 3
0
    def handle(self):
        try:
            dialogs = UserDialogsFacade()
            basePath = dialogs.getExistingDirectory(
                self._model.gui, self.tr("Choose a repository base path"))

            if not basePath:
                raise Exception(
                    self.
                    tr("You haven't chosen existent directory. Operation canceled."
                       ))

            #QFileDialog returns forward slashes in windows! Because of this path should be normalized
            basePath = os.path.normpath(basePath)
            self._model.repo = RepoMgr(basePath)
            self._model.user = None
            self._model.loginRecentUser()

            stats.sendEvent("main_window.open_repo")

        except LoginError:
            self.__letUserLoginByHimself()

        except Exception as ex:
            show_exc_info(self._model.gui, ex)
Ejemplo n.º 4
0
class AbstractTestCaseWithRepoAndSingleUOW(unittest.TestCase):

    def setUp(self):
        self.repoBasePath = tests_context.TEST_REPO_BASE_PATH
        self.copyOfRepoBasePath = tests_context.COPY_OF_TEST_REPO_BASE_PATH

        if (os.path.exists(self.copyOfRepoBasePath)):
            shutil.rmtree(self.copyOfRepoBasePath)
        shutil.copytree(self.repoBasePath, self.copyOfRepoBasePath)

        self.repo = RepoMgr(self.copyOfRepoBasePath)
        self.uow = self.repo.createUnitOfWork()

    def tearDown(self):
        self.uow.close()
        self.uow = None
        self.repo = None
        shutil.rmtree(self.copyOfRepoBasePath)
Ejemplo n.º 5
0
    def handle(self):
        try:
            dialogs = UserDialogsFacade()
            basePath = dialogs.getExistingDirectory(
                self._model.gui, self.tr("Choose a base path for new repository"))

            if not basePath:
                raise MsgException(
                    self.tr("You haven't chosen existent directory. Operation canceled."))

            # QFileDialog returns forward slashes in windows! Because of this
            # the path should be normalized
            basePath = os.path.normpath(basePath)
            self._model.repo = RepoMgr.createNewRepo(basePath)
            self._model.user = self.__createDefaultUser()

            stats.sendEvent("main_window.create_repo")

        except Exception as ex:
            show_exc_info(self._model.gui, ex)
Ejemplo n.º 6
0
    def handle(self):
        try:
            dialogs = UserDialogsFacade()
            basePath = dialogs.getExistingDirectory(
                self._model.gui,
                self.tr("Choose a base path for new repository"))

            if not basePath:
                raise MsgException(
                    self.
                    tr("You haven't chosen existent directory. Operation canceled."
                       ))

            # QFileDialog returns forward slashes in windows! Because of this
            # the path should be normalized
            basePath = os.path.normpath(basePath)
            self._model.repo = RepoMgr.createNewRepo(basePath)
            self._model.user = self.__createDefaultUser()

            stats.sendEvent("main_window.create_repo")

        except Exception as ex:
            show_exc_info(self._model.gui, ex)
Ejemplo n.º 7
0
class AbstractTestCaseWithRepo(unittest.TestCase):

    def setUp(self):
        self.repoBasePath = tests_context.TEST_REPO_BASE_PATH
        self.copyOfRepoBasePath = tests_context.COPY_OF_TEST_REPO_BASE_PATH

        if (os.path.exists(self.copyOfRepoBasePath)):
            shutil.rmtree(self.copyOfRepoBasePath)
        shutil.copytree(self.repoBasePath, self.copyOfRepoBasePath)

        self.repo = RepoMgr(self.copyOfRepoBasePath)

    def tearDown(self):
        self.repo = None
        shutil.rmtree(self.copyOfRepoBasePath)

    def getExistingItem(self, itemId):
        try:
            uow = self.repo.createUnitOfWork()
            item = uow.executeCommand(GetExpungedItemCommand(itemId))
            self.assertIsNotNone(item)
        finally:
            uow.close()
        return item

    def getDataRef(self, url):
        # In the case when this DataRef is a file, url should be a relative path
        try:
            uow = self.repo.createUnitOfWork()
            dataRef = uow._session.query(DataRef) \
                    .filter(DataRef.url_raw==helpers.to_db_format(url)).first()
            # NOTE: dataRef could be None
        finally:
            uow.close()
        return dataRef


    def getDataRefById(self, objId):
        '''
            Returns a DataRef object with given id or None, if DataRef object not found.
        '''
        try:
            uow = self.repo.createUnitOfWork()
            dataRef = uow._session.query(DataRef).filter(DataRef.id==objId).first()
        finally:
            uow.close()
        return dataRef

    
    def getDataRefsFromDir(self, dirRelPath):
        dataRefs = []
        try:
            uow = self.repo.createUnitOfWork()
            dataRefs = uow._session.query(DataRef).filter(
                DataRef.url_raw.like(helpers.to_db_format(dirRelPath) + "/%")).all()
        finally:
            uow.close()
        return dataRefs


    def updateExistingItem(self, detachedItem, newSrcAbsPath, newDstRelPath, user_login):
        item = None
        try:
            uow = self.repo.createUnitOfWork()
            cmd = UpdateExistingItemCommand(detachedItem, newSrcAbsPath, newDstRelPath, user_login)
            item = uow.executeCommand(cmd)
        finally:
            uow.close()
        return item