예제 #1
0
 def _changeDirToLocalAppPath(cls, localResourcesPath):
     """_changeDirToLocalAppPath doc..."""
     if not localResourcesPath:
         localResourcesPath = PyGlassEnvironment.getRootLocalResourcePath(isDir=True)
     lastDir = os.path.abspath(os.curdir)
     os.chdir(localResourcesPath)
     return lastDir
예제 #2
0
def getAnalysisSettings():
    """ Retrieves the analysis configuration settings file as a SettingsConfig
        instance that can be modified and saved as needed.
        @return: SettingsConfig """
    if not __LOCALS__.SETTINGS_CONFIG:
        __LOCALS__.SETTINGS_CONFIG = SettingsConfig(
            FileUtils.makeFilePath(
                PyGlassEnvironment.getRootLocalResourcePath(
                    'analysis', isDir=True),
                'analysis.json'), pretty=True)
    return __LOCALS__.SETTINGS_CONFIG
예제 #3
0
    def upgradeDatabase(cls, databaseUrl):
        """upgradeDatabase doc..."""
        from pyglass.alembic.AlembicUtils import AlembicUtils

        if not AlembicUtils.hasAlembic:
            return False

        AlembicUtils.upgradeDatabase(
            databaseUrl=databaseUrl,
            resourcesPath=PyGlassEnvironment.getRootResourcePath(isDir=True),
            localResourcesPath=PyGlassEnvironment.getRootLocalResourcePath(isDir=True),
        )
        return True
예제 #4
0
    def getPathFromDatabaseUrl(cls, databaseUrl):
        urlParts = databaseUrl.split(u'://')

        # Determine the sqlite database path
        if urlParts[0].lower() == u'shared':
            path = [u'shared', u'data']
        else:
            path = [u'apps', urlParts[0], u'data']

        path += urlParts[1].strip(u'/').split(u'/')
        if not path[-1].endswith(u'.vdb'):
            path[-1] += u'.vdb'

        return PyGlassEnvironment.getRootLocalResourcePath(*path)
예제 #5
0
    def getAppDatabaseItems(cls, appName, localResourcesPath =None):
        if not localResourcesPath:
            localResourcesPath = PyGlassEnvironment.getRootLocalResourcePath(isDir=True)

        databaseRoot = FileUtils.makeFolderPath(localResourcesPath, 'apps', appName, 'data')
        if not os.path.exists(databaseRoot):
            return []

        results = []
        FileUtils.walkPath(databaseRoot, cls._findAppDatabases, {
            'root':databaseRoot,
            'results':results,
            'appName':appName })

        return results
예제 #6
0
    def getPathFromDatabaseUrl(cls, databaseUrl, localResourcesPath=None):
        urlParts = databaseUrl.split("://")

        # Determine the sqlite database path
        if urlParts[0].lower() == "shared":
            path = ["shared", "data"]
        else:
            path = ["apps", urlParts[0], "data"]

        path += urlParts[1].strip("/").split("/")
        if not path[-1].endswith(".vdb"):
            path[-1] += ".vdb"

        if localResourcesPath:
            return FileUtils.makeFilePath(localResourcesPath, *path)

        return PyGlassEnvironment.getRootLocalResourcePath(*path, isFile=True)
예제 #7
0
    def __init__(self, **kwargs):
        """
        Creates a new instance of AnalyzerBase.

        [cacheData] ~ Object | CacheData
            A caching object on which to store data during analysis at the
            analyzer level, instead of the stage level.

        [logger] ~ Logger
            A logger object to use for logging within this analyzer. If no such
            logger exists, a new logger is created.

        [logFolderPath] ~ String
            If no logger was specified for the analyzer, this is the absolute
            path to the folder where the log file should be written. This
            value is ignored if you specify a logger.
        """

        self._tracksSession     = None
        self._analysisSession   = None
        self._cache             = ConfigsDict(kwargs.get('cacheData'))
        self._logger            = kwargs.get('logger')
        self._tempPath          = kwargs.get('tempPath')
        self._stages            = []
        self._sitemaps          = []
        self._trackways         = dict()
        self._seriesBundles     = dict()
        self._plotFigures       = dict()
        self._currentStage      = None
        self._success           = False
        self._errorMessage      = None
        self._startTime         = None

        if not self._logger:
            self._logger = Logger(
                name=self,
                logFolder=kwargs.get('logFolderPath'),
                printOut=True,
                headerless=True,
                removeIfExists=True,
                timestampFileSuffix=False)

        self._defaultRootPath = PyGlassEnvironment.getRootLocalResourcePath(
            'analysis', isDir=True)
        self._settings = DataLoadUtils.getAnalysisSettings()
예제 #8
0
    def run(self, appArgs =None, **kwargs):
        """Doc..."""
        try:
            if PyGlassEnvironment.isDeployed:
                logPath = PyGlassEnvironment.getRootLocalResourcePath('logs', isDir=True)
                if not os.path.exists(logPath):
                    os.makedirs(logPath)

                try:
                    sys.stdout.close()
                except Exception, err:
                    pass
                sys.stdout = open(logPath + 'out.log', 'w')

                try:
                    sys.stderr.close()
                except Exception, err:
                    pass
                sys.stderr = open(logPath + 'error.log', 'w')
예제 #9
0
    def redirectLogOutputs(self, prefix =None, logFolderPath =None):
        """ Sets a temporary standard out and error for deployed applications in a write allowed
            location to prevent failed write results. """

        if not PyGlassEnvironment.isDeployed:
            return

        if not prefix:
            prefix = self.appID

        if not prefix.endswith('_'):
            prefix += '_'

        if logFolderPath:
            logPath = logFolderPath
        elif PyGlassEnvironment.isInitialized:
            logPath = PyGlassEnvironment.getRootLocalResourcePath('logs', isDir=True)
        else:
            prefix += 'init_'
            if appdirs:
                logPath = appdirs.user_data_dir(self.appID, self.appGroupID)
            else:
                logPath = FileUtils.createPath(
                    os.path.expanduser('~'), '.pyglass', self.appGroupID, self.appID, isDir=True)

        FileUtils.getDirectoryOf(logPath, createIfMissing=True)
        try:
            sys.stdout.flush()
            sys.stdout.close()
        except Exception as err:
            pass
        sys.stdout = open(FileUtils.makeFilePath(logPath, prefix + 'out.log'), 'w+')

        try:
            sys.stderr.flush()
            sys.stderr.close()
        except Exception as err:
            pass
        sys.stderr = open(FileUtils.makeFilePath(logPath, prefix + 'error.log'), 'w+')

        return True
예제 #10
0
 def getRootLocalResourcePath(self, *args, **kwargs):
     return PyGlassEnvironment.getRootLocalResourcePath(*args, **kwargs)
예제 #11
0
 def rootLocalResourcePath(self):
     return PyGlassEnvironment.getRootLocalResourcePath()
예제 #12
0
 def getLocalAppResourcePath(self, *args, **kwargs):
     return PyGlassEnvironment.getRootLocalResourcePath('apps', self.appID, *args, **kwargs)
예제 #13
0
 def getLocalAppResourcePath(cls, *args, **kwargs):
     """getLocalAppResourcePath doc..."""
     return PyGlassEnvironment.getRootLocalResourcePath(
         'apps', cls.APP_ID, *args, **kwargs)
예제 #14
0
 def getRelativeEngineUrl(cls, databaseUrl, localResourcesPath=None):
     """getRelativeEngineUrl doc..."""
     if not localResourcesPath:
         localResourcesPath = PyGlassEnvironment.getRootLocalResourcePath(isDir=True)
     url = cls.getEngineUrl(databaseUrl=databaseUrl, localResourcesPath=localResourcesPath)
     return url.replace(localResourcesPath, "")