コード例 #1
0
def init_database(argv):
    try:
        url = argv[1]
    except IndexError:
        from pycopia import basicconfig
        cf = basicconfig.get_config("database3.conf")
        url = cf["DATABASE_URL"]
    create_db(url)

    models.connect(url)
    database = models.database
    database.create_tables(
        [getattr(models, name) for name in models.TABLES + models._ASSOC_TABLES], 
        safe=False)
    try:
        do_schedules(database)
        do_functional_areas(database)
        do_attribute_types(database)
        do_env_attribute_types(database)
        do_language(database)
        do_country(database)
        do_interface_types(database)
        do_default_environment(database)
        do_default_group(database)
        do_function(database)
        do_corporations(database)
        do_riskcategory(database)
        do_config(database)
    finally:
        database.close()
コード例 #2
0
ファイル: __main__.py プロジェクト: feitianyiren/pycopia3
def _init_db():
    """Initialize a mock database with minimal entries."""
    models.connect("sqlite://:memory:")
    models.database.create_tables([
        getattr(models, name) for name in models.TABLES + models._ASSOC_TABLES
    ],
                                  safe=True)
    with models.database.atomic():
        models.Environments.create(name="default")
        rn = models.Config.create(name="root",
                                  user=None,
                                  parent=None,
                                  value=NULL)
        flags = models.Config.create(name="flags",
                                     user=None,
                                     parent=rn,
                                     value=NULL)
        root = config.Container(rn)
        flags = config.Container(flags)
        flags.DEBUG = 1
        flags.VERBOSE = 0
        root["logbasename"] = "unittest.log"
        root["logfiledir"] = "/var/tmp"
        root["resultsdirbase"] = '/var/www/localhost/htdocs/testresults'
        root["documentroot"] = "/var/www/localhost"
        root["baseurl"] = "http://localhost"
コード例 #3
0
ファイル: environment.py プロジェクト: feitianyiren/pycopia3
def get_environment(name, storageurl=None):
    models.connect(storageurl)
    try:
        env = models.Environments.select().where(
            models.Environments.name == name).get()
    except models.DoesNotExist as err:
        raise ConfigError("Bad environment name {!r}: {}".format(
            name, err)) from None
    return EnvironmentRuntime(env)
コード例 #4
0
ファイル: environment.py プロジェクト: kdart/pycopia3
def get_environment(name, storageurl=None):
    models.connect(storageurl)
    try:
        env = models.Environments.select().where(
            models.Environments.name == name).get()
    except models.DoesNotExist as err:
        raise ConfigError(
            "Bad environment name {!r}: {}".format(name, err)) from None
    return EnvironmentRuntime(env)
コード例 #5
0
ファイル: __main__.py プロジェクト: kdart/pycopia3
def _init_db():
    """Initialize a mock database with minimal entries."""
    models.connect("sqlite://:memory:")
    models.database.create_tables(
        [getattr(models, name) for name in models.TABLES + models._ASSOC_TABLES],
        safe=True)
    with models.database.atomic():
        models.Environments.create(name="default")
        rn = models.Config.create(name="root", user=None, parent=None,
                value=NULL)
        flags = models.Config.create(name="flags", user=None, parent=rn,
                value=NULL)
        root = config.Container(rn)
        flags = config.Container(flags)
        flags.DEBUG = 1
        flags.VERBOSE = 0
        root["logbasename"] = "unittest.log"
        root["logfiledir"] = "/var/tmp"
        root["resultsdirbase"] = '/var/www/localhost/htdocs/testresults'
        root["documentroot"] = "/var/www/localhost"
        root["baseurl"] = "http://localhost"
コード例 #6
0
ファイル: config.py プロジェクト: kdart/pycopia3
def get_config(storageurl=None, _extrafiles=None, initdict=None, **kwargs):
    """Get primary configuration.

    Returns a RootContainer instance containing configuration parameters.  An
    extra dictionary may be merged in with the 'initdict' parameter.  And
    finally, extra options may be added with keyword parameters when calling
    this.
    """
    models.connect(storageurl)
    files = []

    if type(_extrafiles) is str:
        _extrafiles = [_extrafiles]
    if _extrafiles:
        files.extend(_extrafiles)
    try:
        rootnode = config.get_root()
    except models.OperationalError:
        logging.exception_warning(
            "Could not connect to database. Configuration not available.")
        return get_mock_config(files, initdict, kwargs)
    cache = AttrDict()
    flags = AttrDict()
    # copy flag values to cache so changes don't persist.
    flagsnode = Config.select().where(
        (Config.parent == rootnode) & (Config.name == "flags")).get()
    for valnode in flagsnode.children:
        flags[valnode.name] = valnode.value
    cache.flags = flags
    cf = RootContainer(rootnode, cache)
    for f in files:
        if os.path.isfile(f):
            cf.mergefile(f)
    if type(initdict) is dict:
        cf.evalupdate(initdict)
    cf.update(kwargs)
    return cf
コード例 #7
0
ファイル: config.py プロジェクト: feitianyiren/pycopia3
def get_config(storageurl=None, _extrafiles=None, initdict=None, **kwargs):
    """Get primary configuration.

    Returns a RootContainer instance containing configuration parameters.  An
    extra dictionary may be merged in with the 'initdict' parameter.  And
    finally, extra options may be added with keyword parameters when calling
    this.
    """
    models.connect(storageurl)
    files = []

    if type(_extrafiles) is str:
        _extrafiles = [_extrafiles]
    if _extrafiles:
        files.extend(_extrafiles)
    try:
        rootnode = config.get_root()
    except models.OperationalError:
        logging.exception_warning(
            "Could not connect to database. Configuration not available.")
        return get_mock_config(files, initdict, kwargs)
    cache = AttrDict()
    flags = AttrDict()
    # copy flag values to cache so changes don't persist.
    flagsnode = Config.select().where((Config.parent == rootnode)
                                      & (Config.name == "flags")).get()
    for valnode in flagsnode.children:
        flags[valnode.name] = valnode.value
    cache.flags = flags
    cf = RootContainer(rootnode, cache)
    for f in files:
        if os.path.isfile(f):
            cf.mergefile(f)
    if type(initdict) is dict:
        cf.evalupdate(initdict)
    cf.update(kwargs)
    return cf
コード例 #8
0
"""
Dynamic pages for the web UI for QA framework.
"""

# This import pattern is what Flask requires.

from pycopia import logging
from pycopia.QA.db import models

from flask import Flask


models.connect()
app = Flask(__name__)
app._logger = logging.Logger(app.logger_name)

# Needs to be last.
from . import views
コード例 #9
0
ファイル: config.py プロジェクト: feitianyiren/pycopia3
def get_config(url=None):
    models.connect(url)
    root = get_root()
    return Container(root)
コード例 #10
0
ファイル: config.py プロジェクト: kdart/pycopia3
def get_config(url=None):
    models.connect(url)
    root = get_root()
    return Container(root)