當前位置: 首頁>>代碼示例>>Python>>正文


Python PyGlassEnvironment.initializeFromInternalPath方法代碼示例

本文整理匯總了Python中pyglass.app.PyGlassEnvironment.PyGlassEnvironment.initializeFromInternalPath方法的典型用法代碼示例。如果您正苦於以下問題:Python PyGlassEnvironment.initializeFromInternalPath方法的具體用法?Python PyGlassEnvironment.initializeFromInternalPath怎麽用?Python PyGlassEnvironment.initializeFromInternalPath使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pyglass.app.PyGlassEnvironment.PyGlassEnvironment的用法示例。


在下文中一共展示了PyGlassEnvironment.initializeFromInternalPath方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: print

# 需要導入模塊: from pyglass.app.PyGlassEnvironment import PyGlassEnvironment [as 別名]
# 或者: from pyglass.app.PyGlassEnvironment.PyGlassEnvironment import initializeFromInternalPath [as 別名]
from __future__ import print_function, absolute_import, unicode_literals, division

import sqlalchemy as sqla
from pyaid.dict.DictUtils import DictUtils
from pyglass.app.PyGlassEnvironment import PyGlassEnvironment
PyGlassEnvironment.initializeFromInternalPath(__file__)

from cadence.models.tracks.Tracks_Track import Tracks_Track

models = {'Track':Tracks_Track.MASTER}
session = Tracks_Track.MASTER.createSession()
verbose = True

for label,model in models.iteritems():
    query = session.query(model).filter(model.uid.in_((
        'track1l2ic-1s7-rZ3g4I0Yzvzd',
        'track1l2id-1sZ-UvtVfQoOAOPo')) )
    items = query.all()
    print('\n\n\n%s' % (60*'-'))
    print('MODEL:', label)
    print('COUNT:', len(items))

    if not items:
        print('No matching items found')
    else:
        for item in items:
            if verbose:
                print('[TRACK]: %s [%s]:\n  * hidden: %s\n  * complete: %s\n  * next: %s\n%s' % (
                    item.fingerprint, item.uid,
                    'Y' if item.hidden else 'N', 'Y' if item.isComplete else 'N', item.next,
開發者ID:sernst,項目名稱:Cadence,代碼行數:32,代碼來源:trackMatchPrinter.py

示例2: modelsInit

# 需要導入模塊: from pyglass.app.PyGlassEnvironment import PyGlassEnvironment [as 別名]
# 或者: from pyglass.app.PyGlassEnvironment.PyGlassEnvironment import initializeFromInternalPath [as 別名]
    def modelsInit(cls, databaseUrl, initPath, initName):
        out = dict()
        zipIndex = initPath[0].find(cls._ZIP_FIND)
        if zipIndex == -1:
            moduleList = os.listdir(initPath[0])
        else:
            splitIndex = zipIndex + len(cls._ZIP_FIND)
            zipPath = initPath[0][: splitIndex - 1]
            modulePath = initPath[0][splitIndex:]
            z = zipfile.ZipFile(zipPath)
            moduleList = []
            for item in z.namelist():
                item = os.sep.join(item.split("/"))
                if item.startswith(modulePath):
                    moduleList.append(item.rsplit(os.sep, 1)[-1])

        # Warn if module initialization occurs before pyglass environment initialization and
        # then attempt to initialize the environment automatically to prevent errors
        if not PyGlassEnvironment.isInitialized:
            cls.logger.write(
                StringUtils.dedent(
                    """
                [WARNING]: Database initialization called before PyGlassEnvironment initialization.
                Attempting automatic initialization to prevent errors."""
                )
            )
            PyGlassEnvironment.initializeFromInternalPath(initPath[0])

        if not cls.upgradeDatabase(databaseUrl):
            cls.logger.write(
                StringUtils.dedent(
                    """
                [WARNING]: No alembic support detected. Migration support disabled."""
                )
            )

        items = []
        for module in moduleList:
            if module.startswith("__init__.py") or module.find("_") == -1:
                continue

            parts = module.rsplit(".", 1)
            parts[0] = parts[0].rsplit(os.sep, 1)[-1]
            if not parts[-1].startswith(StringUtils.toStr2("py")) or parts[0] in items:
                continue
            items.append(parts[0])

            m = None
            n = None
            r = None
            c = None
            try:
                n = module.rsplit(".", 1)[0]
                m = initName + "." + n
                r = __import__(m, locals(), globals(), [n])
                c = getattr(r, StringUtils.toText(n))
                out[n] = c
                if not c.__table__.exists(c.ENGINE):
                    c.__table__.create(c.ENGINE, True)
            except Exception as err:
                cls._logger.writeError(
                    [
                        "MODEL INITIALIZATION FAILURE:",
                        "INIT PATH: %s" % initPath,
                        "INIT NAME: %s" % initName,
                        "MODULE IMPORT: %s" % m,
                        "IMPORT CLASS: %s" % n,
                        "IMPORT RESULT: %s" % r,
                        "CLASS RESULT: %s" % c,
                    ],
                    err,
                )

        return out
開發者ID:sernst,項目名稱:PyGlass,代碼行數:76,代碼來源:PyGlassModelUtils.py


注:本文中的pyglass.app.PyGlassEnvironment.PyGlassEnvironment.initializeFromInternalPath方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。