コード例 #1
0
ファイル: trackMatchPrinter.py プロジェクト: sernst/Cadence
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,
コード例 #2
0
ファイル: PyGlassModelUtils.py プロジェクト: sernst/PyGlass
    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