当前位置: 首页>>代码示例>>Python>>正文


Python Config.get方法代码示例

本文整理汇总了Python中flask.Config.get方法的典型用法代码示例。如果您正苦于以下问题:Python Config.get方法的具体用法?Python Config.get怎么用?Python Config.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在flask.Config的用法示例。


在下文中一共展示了Config.get方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Config

# 需要导入模块: from flask import Config [as 别名]
# 或者: from flask.Config import get [as 别名]
import re
import redis
import urlparse

from flask import Blueprint, Config, flash, g, jsonify, request, render_template
from flask import session, url_for
from flask_bibframe.models import CoverArt

blueprint_folder = os.path.abspath(os.path.dirname(__file__))
app_folder = os.path.split(blueprint_folder)[0]


metrics_config = Config(app_folder)
metrics_config.from_pyfile('catalog.cfg')

redis_ds = redis.StrictRedis(metrics_config.get('REDIS_HOST'))


def parse_logfile(log_path, redis_ds=redis_ds, tz='-0700'):
    """Takes a nginx access log, opens the file, and parses through and creates
    metrics for use by other Blueprints and apps.

    Parameters
    ----------
    log_path : str
        Full path and filename of the nginx access log
    redis_ds : StrictRedis instance
        defaults to Redis datastore for CPP's metrics
    tz : str
        Timezone offset, defaults to -0700
    """
开发者ID:Tutt-Library,项目名称:pilot-tiger-catalog,代码行数:33,代码来源:metrics.py

示例2: Configurator

# 需要导入模块: from flask import Config [as 别名]
# 或者: from flask.Config import get [as 别名]
class Configurator(object):
    """
    Object that takes care of loading the different configurations from the
    different sources. There are 3 types of settings:
        * Project: The basic set of settings needed by the system. These are
          shipped with Shiva.
        * Local: Specific to each instance, useful for overwriting system
          settings. Some of them must be defined before running Shiva, like the
          DB URI.
        * Debug: This setting will only be loaded if ``DEBUG`` is set to True
          in the local settings.

    There are also 3 different places where Shiva looks for this config files:
        * A ``local.py`` file inside the ``config/`` directory, relative to
          Shiva.
        * The ``$SHIVA_CONFIG`` environment variable. It's assumed to be
          pointing to a file (not a dir) if exists.
        * The ``$XDG_CONFIG_HOME/shiva/config.py`` file. If
          ``$XDG_CONFIG_HOME`` is not set, defaults to ``$HOME/.config``, as
          defined by the `XDG Base Directory Specification
          <http://standards.freedesktop.org/basedir-spec/basedir-spec-latest\
.html>`_.
    """

    def __init__(self):
        self._config = FlaskConfig("")

        # project
        _project = self.load_project()

        # local
        _xdg_config = self.from_xdg_config()
        _env = self.from_env()
        _local = self.from_local()

        # debug
        _debug = self.load_debug()

        self.extract_conf(self._config)

        if not (_xdg_config or _env or _local):
            raise NoConfigFoundError

    def load_project(self):
        return self._config.from_object(project)

    def get_xdg_path(self):
        path_home = os.getenv("HOME")
        if not path_home:
            return None

        default_config_home = os.path.join(path_home, ".config")

        return os.getenv("XDG_CONFIG_HOME") or default_config_home

    def from_xdg_config(self):
        xdg_path = self.get_xdg_path()
        if not xdg_path:
            return False

        local_py = os.path.join(xdg_path, "shiva/config.py")

        if not os.path.exists(local_py):
            return False

        return self._config.from_pyfile(local_py)

    def from_env(self):
        if not os.getenv("SHIVA_CONFIG"):
            return False

        return self._config.from_envvar("SHIVA_CONFIG")

    def from_local(self):
        with ignored(ImportError):
            self._config.from_object("shiva.config.local")

            return True

        return False

    def load_debug(self):
        if not self._config.get("DEBUG"):
            return False

        loaded = False
        with ignored(ImportError):
            from shiva.config import debug

            loaded = self._config.from_object(debug)

        xdg_path = self.get_xdg_path()
        if not xdg_path:
            return False

        debug_py = os.path.join(xdg_path, "shiva/debug.py")
        if not os.path.exists(debug_py):
            return False

        return self._config.from_pyfile(debug_py) or loaded
#.........这里部分代码省略.........
开发者ID:tooxie,项目名称:shiva-server,代码行数:103,代码来源:__init__.py

示例3: configure_engine

# 需要导入模块: from flask import Config [as 别名]
# 或者: from flask.Config import get [as 别名]
engine = None
sessionmaker = sa.orm.sessionmaker()
session = sa.orm.scoped_session(sessionmaker)

def configure_engine(url):
    global sessionmaker, engine, session

    engine = sa.create_engine(url)
    session.remove()
    sessionmaker.configure(bind=engine)

_config = Config('')
_config.from_object('config')
_config.from_envvar('MULCHN_CONFIG', silent=True)
configure_engine(_config.get('DATABASE_URL'))

class _Base(object):
    @declared_attr
    def __tablename__(cls):
        """
        Convert CamelCase class name to underscores_between_words
        table name.
        """

        name = cls.__name__
        return (
            name[0].lower() +
            re.sub(r'([A-Z])', lambda m:"_" + m.group(0).lower(), name[1:])
        )
开发者ID:milkypostman,项目名称:mulchn,代码行数:31,代码来源:db.py

示例4: Config

# 需要导入模块: from flask import Config [as 别名]
# 或者: from flask.Config import get [as 别名]
import sqlalchemy

from gunrskite import parser as gparse
from gunrskite import consumer as consumer
from flask import Config

cfg = Config(os.path.abspath("."))
cfg.from_pyfile("config.py")

loop = asyncio.get_event_loop()

formatter = logging.Formatter('%(asctime)s - [%(levelname)s] %(name)s -> %(message)s')
root = logging.getLogger()

root.setLevel(cfg.get("LOG_LEVEL", logging.INFO))

consoleHandler = logging.StreamHandler()
consoleHandler.setFormatter(formatter)
root.addHandler(consoleHandler)

logger = logging.getLogger("Gunrskite::Listener")

logging.getLogger("sqlalchemy").setLevel(cfg.get("SQLALCHEMY_LOG_LEVEL", logging.CRITICAL))

# Load database
from gunrskite import db

session = db.create_sess()

开发者ID:SunDwarf,项目名称:Gunrskite,代码行数:30,代码来源:udpserver.py

示例5: main

# 需要导入模块: from flask import Config [as 别名]
# 或者: from flask.Config import get [as 别名]
def main(argconfig):
    # Load the config file the same way Flask does which Chill uses.
    config_file = argconfig if argconfig[0] == os.sep else os.path.join(os.getcwd(), argconfig)
    config = Config(os.getcwd())
    config.from_pyfile(config_file)

    pyrax.set_credential_file(config["RACKSPACE_CREDENTIAL_FILE"])
    cf = pyrax.cloudfiles

    # sync sync_folder_to_container
    local = config["FREEZER_DESTINATION"]
    container_name = config.get("RACKSPACE_CONTAINER_NAME", os.path.basename(os.getcwd()))

    prefix = config.get("PUBLIC_URL_PREFIX", None)
    if prefix:
        for page in (INDEX_PAGE, ERROR_PAGE, "401{0}".format(ERROR_PAGE), "404{0}".format(ERROR_PAGE)):
            # If no index.html or error pages then link to the one found in
            # PUBLIC_URL_PREFIX
            if not os.path.exists(os.path.join(local, page)) and os.path.exists(os.path.join(local, prefix[1:], page)):
                print "Creating hard link for {0}".format(page)
                print "{0} -> {1}".format(os.path.join(local, page), os.path.join(local, prefix[1:], page))
                os.link(os.path.join(local, prefix[1:], page), os.path.join(local, page))

    confirm = raw_input(
        "\nsync the folder: {local} \nto rackspace cloudfiles container: {container_name}\n[n]/y\n".format(**locals())
    )
    if confirm != "y":
        return

    remote = cf.create_container(container_name)

    local_files = set()
    for root, dir, files in os.walk(local):
        for f in files:
            local_files.add(os.path.join(root[len(local) + 1 :], f))

    cf.sync_folder_to_container(local, remote)

    # Mark all objects on remote to be deleted if not in local
    # The limit here is arbitrary, but can not be higher then 10000.
    limit = 1000
    marker = ""
    remote_objects_list = remote.get_objects(limit=limit, marker=marker)
    while remote_objects_list:
        marker = remote_objects_list[-1].name
        for obj in remote_objects_list:
            if obj.name not in local_files:
                obj.delete_in_seconds(DELETE_OBJECTS_DELAY)

        remote_objects_list = remote.get_objects(limit=limit, marker=marker)

    # publish
    cf.make_container_public(container_name, ttl=TTL)

    # cdn website
    remote.set_web_index_page(INDEX_PAGE)
    remote.set_web_error_page(ERROR_PAGE)

    # Totally copied from the docs
    print
    print "After Making Public"
    print "cdn_enabled", remote.cdn_enabled
    print "cdn_ttl", remote.cdn_ttl
    print "cdn_log_retention", remote.cdn_log_retention
    print "cdn_uri", remote.cdn_uri
    print "cdn_ssl_uri", remote.cdn_ssl_uri
    print "cdn_streaming_uri", remote.cdn_streaming_uri
    print "cdn_ios_uri", remote.cdn_ios_uri
开发者ID:jkenlooper,项目名称:dot_files,代码行数:70,代码来源:chill-upload-rackspace.py


注:本文中的flask.Config.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。