예제 #1
0
    def _actionGenericFormPost(self, sMode, fnLogicAction, oDataType, oFormType, sRedirectTo, fStrict = True):
        """
        Generic POST request handling from a WuiFormContentBase child.

        oDataType is a ModelDataBase child class.
        oFormType is a WuiFormContentBase child class.
        fnLogicAction is a method taking a oDataType instance and uidAuthor as arguments.
        """
        assert issubclass(oDataType, ModelDataBase);
        from testmanager.webui.wuicontentbase import WuiFormContentBase;
        assert issubclass(oFormType, WuiFormContentBase);

        #
        # Read and validate parameters.
        #
        oData = oDataType().initFromParams(oDisp = self, fStrict = fStrict);
        sRedirectTo = self.getRedirectToParameter(sRedirectTo);
        self._checkForUnknownParameters();
        self._assertPostRequest();
        if sMode == WuiFormContentBase.ksMode_Add and  getattr(oData, 'kfIdAttrIsForForeign', False):
            enmValidateFor = oData.ksValidateFor_AddForeignId;
        elif sMode == WuiFormContentBase.ksMode_Add:
            enmValidateFor = oData.ksValidateFor_Add;
        else:
            enmValidateFor = oData.ksValidateFor_Edit;
        dErrors = oData.validateAndConvert(self._oDb, enmValidateFor);

        # Check that the user can do this.
        sErrorMsg = None;
        assert self._oCurUser is not None;
        if self.isReadOnlyUser():
            sErrorMsg = 'User %s is not allowed to modify anything!' % (self._oCurUser.sUsername,)

        if not dErrors and not sErrorMsg:
            oData.convertFromParamNull();

            #
            # Try do the job.
            #
            try:
                fnLogicAction(oData, self._oCurUser.uid, fCommit = True);
            except Exception as oXcpt:
                self._oDb.rollback();
                oForm = oFormType(oData, sMode, oDisp = self);
                oForm.setRedirectTo(sRedirectTo);
                sErrorMsg = str(oXcpt) if not config.g_kfDebugDbXcpt else '\n'.join(utils.getXcptInfo(4));
                (self._sPageTitle, self._sPageBody) = oForm.showForm(sErrorMsg = sErrorMsg);
            else:
                #
                # Worked, redirect to the specified page.
                #
                self._sPageTitle  = None;
                self._sPageBody   = None;
                self._sRedirectTo = sRedirectTo;
        else:
            oForm = oFormType(oData, sMode, oDisp = self);
            oForm.setRedirectTo(sRedirectTo);
            (self._sPageTitle, self._sPageBody) = oForm.showForm(dErrors = dErrors, sErrorMsg = sErrorMsg);
        return True;
    def _actionGenericFormPost(self, sMode, fnLogicAction, oDataType, oFormType, sRedirectTo, fStrict = True):
        """
        Generic POST request handling from a WuiFormContentBase child.

        oDataType is a ModelDataBase child class.
        oFormType is a WuiFormContentBase child class.
        fnLogicAction is a method taking a oDataType instance and uidAuthor as arguments.
        """
        assert issubclass(oDataType, ModelDataBase);
        from testmanager.webui.wuicontentbase import WuiFormContentBase;
        assert issubclass(oFormType, WuiFormContentBase);

        #
        # Read and validate parameters.
        #
        oData = oDataType().initFromParams(oDisp = self, fStrict = fStrict);
        sRedirectTo = self.getRedirectToParameter(sRedirectTo);
        self._checkForUnknownParameters();
        self._assertPostRequest();
        if sMode == WuiFormContentBase.ksMode_Add and  getattr(oData, 'kfIdAttrIsForForeign', False):
            enmValidateFor = oData.ksValidateFor_AddForeignId;
        elif sMode == WuiFormContentBase.ksMode_Add:
            enmValidateFor = oData.ksValidateFor_Add;
        else:
            enmValidateFor = oData.ksValidateFor_Edit;
        dErrors = oData.validateAndConvert(self._oDb, enmValidateFor);

        # Check that the user can do this.
        sErrorMsg = None;
        assert self._oCurUser is not None;
        if self.isReadOnlyUser():
            sErrorMsg = 'User %s is not allowed to modify anything!' % (self._oCurUser.sUsername,)

        if not dErrors and not sErrorMsg:
            oData.convertFromParamNull();

            #
            # Try do the job.
            #
            try:
                fnLogicAction(oData, self._oCurUser.uid, fCommit = True);
            except Exception as oXcpt:
                self._oDb.rollback();
                oForm = oFormType(oData, sMode, oDisp = self);
                oForm.setRedirectTo(sRedirectTo);
                sErrorMsg = str(oXcpt) if not config.g_kfDebugDbXcpt else '\n'.join(utils.getXcptInfo(4));
                (self._sPageTitle, self._sPageBody) = oForm.showForm(sErrorMsg = sErrorMsg);
            else:
                #
                # Worked, redirect to the specified page.
                #
                self._sPageTitle  = None;
                self._sPageBody   = None;
                self._sRedirectTo = sRedirectTo;
        else:
            oForm = oFormType(oData, sMode, oDisp = self);
            oForm.setRedirectTo(sRedirectTo);
            (self._sPageTitle, self._sPageBody) = oForm.showForm(dErrors = dErrors, sErrorMsg = sErrorMsg);
        return True;
예제 #3
0
    def _actionGenericFormPost(self,
                               sMode,
                               fnLogicAction,
                               oDataType,
                               oFormType,
                               sRedirectTo,
                               fStrict=True):
        """
        Generic POST request handling from a WuiFormContentBase child.

        oDataType is a ModelDataBase child class.
        oFormType is a WuiFormContentBase child class.
        fnLogicAction is a method taking a oDataType instance and uidAuthor as arguments.
        """
        #
        # Read and validate parameters.
        #
        oData = oDataType().initFromParams(oDisp=self, fStrict=fStrict)
        self._checkForUnknownParameters()
        self._assertPostRequest()
        dErrors = oData.validateAndConvert(self._oDb)
        if len(dErrors) == 0:
            oData.convertFromParamNull()

            #
            # Try do the job.
            #
            try:
                fnLogicAction(oData, self._oCurUser.uid, fCommit=True)
            except Exception as oXcpt:
                self._oDb.rollback()
                oForm = oFormType(oData, sMode, oDisp=self)
                sErrorMsg = str(
                    oXcpt) if not config.g_kfDebugDbXcpt else '\n'.join(
                        utils.getXcptInfo(4))
                (self._sPageTitle,
                 self._sPageBody) = oForm.showForm(sErrorMsg=sErrorMsg)
            else:
                #
                # Worked, redirect to the specified page.
                #
                self._sPageTitle = None
                self._sPageBody = None
                self._sRedirectTo = sRedirectTo
        else:
            oForm = oFormType(oData, sMode, oDisp=self)
            (self._sPageTitle,
             self._sPageBody) = oForm.showForm(dErrors=dErrors)
        return True
예제 #4
0
파일: wuibase.py 프로젝트: mcenirm/vbox
    def _actionGenericFormPost(self, sMode, fnLogicAction, oDataType, oFormType, sRedirectTo, fStrict=True):
        """
        Generic POST request handling from a WuiFormContentBase child.

        oDataType is a ModelDataBase child class.
        oFormType is a WuiFormContentBase child class.
        fnLogicAction is a method taking a oDataType instance and uidAuthor as arguments.
        """
        #
        # Read and validate parameters.
        #
        oData = oDataType().initFromParams(oDisp = self, fStrict = fStrict);
        self._checkForUnknownParameters();
        self._assertPostRequest();
        dErrors = oData.validateAndConvert(self._oDb);
        if len(dErrors) == 0:
            oData.convertFromParamNull();

            #
            # Try do the job.
            #
            try:
                fnLogicAction(oData, self._oCurUser.uid, fCommit = True);
            except Exception as oXcpt:
                self._oDb.rollback();
                oForm = oFormType(oData, sMode, oDisp = self);
                sErrorMsg = str(oXcpt) if not config.g_kfDebugDbXcpt else '\n'.join(utils.getXcptInfo(4));
                (self._sPageTitle, self._sPageBody) = oForm.showForm(sErrorMsg = sErrorMsg);
            else:
                #
                # Worked, redirect to the specified page.
                #
                self._sPageTitle  = None;
                self._sPageBody   = None;
                self._sRedirectTo = sRedirectTo;
        else:
            oForm = oFormType(oData, sMode, oDisp = self);
            (self._sPageTitle, self._sPageBody) = oForm.showForm(dErrors = dErrors);
        return True;
예제 #5
0
    def processDir(self, sCurDir):
        """
        Process the given directory (relative to sSrcDir and sDstDir).
        Returns success indicator.
        """
        if self.fVerbose:
            self.dprint('processDir: %s' % (sCurDir, ))

        #
        # Sift thought the directory content, collecting subdirectories and
        # sort relevant files by test set.
        # Generally there will either be subdirs or there will be files.
        #
        asSubDirs = []
        dTestSets = {}
        sCurPath = os.path.abspath(os.path.join(self.sSrcDir, sCurDir))
        for sFile in os.listdir(sCurPath):
            if os.path.isdir(os.path.join(sCurPath, sFile)):
                if sFile not in ['.', '..']:
                    asSubDirs.append(sFile)
            elif sFile.startswith('TestSet-'):
                # Parse the file name. ASSUMES 'TestSet-%d-filename' format.
                iSlash1 = sFile.find('-')
                iSlash2 = sFile.find('-', iSlash1 + 1)
                if iSlash2 <= iSlash1:
                    self.warning('Bad filename (1): "%s"' % (sFile, ))
                    continue

                try:
                    idTestSet = int(sFile[(iSlash1 + 1):iSlash2])
                except:
                    self.warning('Bad filename (2): "%s"' % (sFile, ))
                    if self.fVerbose:
                        self.dprint('\n'.join(utils.getXcptInfo(4)))
                    continue

                if idTestSet <= 0:
                    self.warning('Bad filename (3): "%s"' % (sFile, ))
                    continue

                if iSlash2 + 2 >= len(sFile):
                    self.warning('Bad filename (4): "%s"' % (sFile, ))
                    continue
                sName = sFile[(iSlash2 + 1):]

                # Add it.
                if idTestSet not in dTestSets:
                    dTestSets[idTestSet] = []
                asTestSet = dTestSets[idTestSet]
                asTestSet.append(sName)

        #
        # Test sets.
        #
        fRc = True
        for idTestSet in dTestSets:
            try:
                if self._processTestSet(idTestSet, dTestSets[idTestSet],
                                        sCurDir) is not True:
                    fRc = False
            except:
                self.warning('TestSet %d: Exception in _processTestSet:\n%s' %
                             (
                                 idTestSet,
                                 '\n'.join(utils.getXcptInfo()),
                             ))
                fRc = False

        #
        # Sub dirs.
        #
        for sSubDir in asSubDirs:
            if self.processDir(os.path.join(sCurDir, sSubDir)) is not True:
                fRc = False

        #
        # Try Remove the directory iff it's not '.' and it's been unmodified
        # for the last 24h (race protection).
        #
        if sCurDir != '.':
            try:
                fpModTime = float(os.path.getmtime(sCurPath))
                if fpModTime + (24 * 3600) <= time.time():
                    if utils.noxcptRmDir(sCurPath) is True:
                        self.dprint('Removed "%s".' % (sCurPath, ))
            except:
                pass

        return fRc
예제 #6
0
    def _actionGenericFormPost(self,
                               sMode,
                               fnLogicAction,
                               oDataType,
                               oFormType,
                               sRedirectTo,
                               fStrict=True):
        """
        Generic POST request handling from a WuiFormContentBase child.

        oDataType is a ModelDataBase child class.
        oFormType is a WuiFormContentBase child class.
        fnLogicAction is a method taking a oDataType instance and uidAuthor as arguments.
        """
        assert issubclass(oDataType, ModelDataBase)
        from testmanager.webui.wuicontentbase import WuiFormContentBase
        assert issubclass(oFormType, WuiFormContentBase)

        #
        # Read and validate parameters.
        #
        oData = oDataType().initFromParams(oDisp=self, fStrict=fStrict)
        sRedirectTo = self.getRedirectToParameter(sRedirectTo)
        self._checkForUnknownParameters()
        self._assertPostRequest()
        if sMode == WuiFormContentBase.ksMode_Add and getattr(
                oData, 'kfIdAttrIsForForeign', False):
            enmValidateFor = oData.ksValidateFor_AddForeignId
        elif sMode == WuiFormContentBase.ksMode_Add:
            enmValidateFor = oData.ksValidateFor_Add
        else:
            enmValidateFor = oData.ksValidateFor_Edit
        dErrors = oData.validateAndConvert(self._oDb, enmValidateFor)
        if len(dErrors) == 0:
            oData.convertFromParamNull()

            #
            # Try do the job.
            #
            try:
                fnLogicAction(oData, self._oCurUser.uid, fCommit=True)
            except Exception as oXcpt:
                self._oDb.rollback()
                oForm = oFormType(oData, sMode, oDisp=self)
                oForm.setRedirectTo(sRedirectTo)
                sErrorMsg = str(
                    oXcpt) if not config.g_kfDebugDbXcpt else '\n'.join(
                        utils.getXcptInfo(4))
                (self._sPageTitle,
                 self._sPageBody) = oForm.showForm(sErrorMsg=sErrorMsg)
            else:
                #
                # Worked, redirect to the specified page.
                #
                self._sPageTitle = None
                self._sPageBody = None
                self._sRedirectTo = sRedirectTo
        else:
            oForm = oFormType(oData, sMode, oDisp=self)
            oForm.setRedirectTo(sRedirectTo)
            (self._sPageTitle,
             self._sPageBody) = oForm.showForm(dErrors=dErrors)
        return True
    def processDir(self, sCurDir):
        """
        Process the given directory (relative to sSrcDir and sDstDir).
        Returns success indicator.
        """
        if self.fVerbose:
            self.dprint('processDir: %s' % (sCurDir,));

        #
        # Sift thought the directory content, collecting subdirectories and
        # sort relevant files by test set.
        # Generally there will either be subdirs or there will be files.
        #
        asSubDirs = [];
        dTestSets = {};
        sCurPath = os.path.abspath(os.path.join(self.sSrcDir, sCurDir));
        for sFile in os.listdir(sCurPath):
            if os.path.isdir(os.path.join(sCurPath, sFile)):
                if sFile not in [ '.', '..' ]:
                    asSubDirs.append(sFile);
            elif sFile.startswith('TestSet-'):
                # Parse the file name. ASSUMES 'TestSet-%d-filename' format.
                iSlash1 = sFile.find('-');
                iSlash2 = sFile.find('-', iSlash1 + 1);
                if iSlash2 <= iSlash1:
                    self.warning('Bad filename (1): "%s"' % (sFile,));
                    continue;

                try:    idTestSet = int(sFile[(iSlash1 + 1):iSlash2]);
                except:
                    self.warning('Bad filename (2): "%s"' % (sFile,));
                    if self.fVerbose:
                        self.dprint('\n'.join(utils.getXcptInfo(4)));
                    continue;

                if idTestSet <= 0:
                    self.warning('Bad filename (3): "%s"' % (sFile,));
                    continue;

                if iSlash2 + 2 >= len(sFile):
                    self.warning('Bad filename (4): "%s"' % (sFile,));
                    continue;
                sName = sFile[(iSlash2 + 1):];

                # Add it.
                if idTestSet not in dTestSets:
                    dTestSets[idTestSet] = [];
                asTestSet = dTestSets[idTestSet];
                asTestSet.append(sName);

        #
        # Test sets.
        #
        fRc = True;
        for idTestSet in dTestSets:
            try:
                if self._processTestSet(idTestSet, dTestSets[idTestSet], sCurDir) is not True:
                    fRc = False;
            except:
                self.warning('TestSet %d: Exception in _processTestSet:\n%s' % (idTestSet, '\n'.join(utils.getXcptInfo()),));
                fRc = False;

        #
        # Sub dirs.
        #
        for sSubDir in asSubDirs:
            if self.processDir(os.path.join(sCurDir, sSubDir)) is not True:
                fRc = False;

        #
        # Try Remove the directory iff it's not '.' and it's been unmodified
        # for the last 24h (race protection).
        #
        if sCurDir != '.':
            try:
                fpModTime = float(os.path.getmtime(sCurPath));
                if fpModTime + (24*3600) <= time.time():
                    if utils.noxcptRmDir(sCurPath) is True:
                        self.dprint('Removed "%s".' % (sCurPath,));
            except:
                pass;

        return fRc;