示例#1
0
    def run(self):
        """ Executes the analysis process, iterating through each of the analysis stages before
            cleaning up and exiting. """

        print('[OUTPUT PATH]: %s' % self.analysisRootPath)
        print(analysisStamp)
        print(tracksStamp)

        self._startTime = TimeUtils.getNowDatetime()

        myRootPath = self.getPath(isDir=True)
        if os.path.exists(myRootPath):
            FileUtils.emptyFolder(myRootPath)
        if not os.path.exists(myRootPath):
            os.makedirs(myRootPath)

        tempPath = self.tempPath
        if os.path.exists(tempPath):
            SystemUtils.remove(tempPath)
        os.makedirs(tempPath)

        if not self.logger.loggingPath:
            self.logger.loggingPath = myRootPath

        try:
            session = self.getAnalysisSession()
            self._preAnalyze()
            for stage in self._stages:
                self._currentStage = stage
                stage.analyze()
            self._currentStage = None
            self._postAnalyze()

            session.commit()
            session.close()
            self._success = True
        except Exception as err:
            session = self.getAnalysisSession()
            session.close()
            msg = [
                '[ERROR]: Failed to execute analysis',
                'STAGE: %s' % self._currentStage]
            self._errorMessage = Logger.createErrorMessage(msg, err)
            self.logger.writeError(msg, err)

        session = self.getTracksSession()
        session.close()

        self._cleanup()
        SystemUtils.remove(tempPath)

        self.logger.write('\n\n[%s]: %s (%s)' % (
            'SUCCESS' if self._success else 'FAILED',
            self.__class__.__name__,
            TimeUtils.toPrettyElapsedTime(self.elapsedTime)
        ), indent=False)