python类config()的实例源码

util.py 文件源码 项目:abe-bootstrap 作者: TryCoin-Team 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def init(self):
        import DataStore, readconf, logging, sys
        self.conf.update({ "debug": None, "logging": None })
        self.conf.update(DataStore.CONFIG_DEFAULTS)

        args, argv = readconf.parse_argv(self.argv, self.conf, strict=False)
        if argv and argv[0] in ('-h', '--help'):
            print self.usage()
            return None, []

        logging.basicConfig(
            stream=sys.stdout, level=logging.DEBUG, format="%(message)s")
        if args.logging is not None:
            import logging.config as logging_config
            logging_config.dictConfig(args.logging)

        store = DataStore.new(args)

        return store, argv

# Abstract hex-binary conversions for eventual porting to Python 3.
env.py 文件源码 项目:flask 作者: ljxxcaijing 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def run_migrations_offline():
    """Run migrations in 'offline' mode.

    This configures the context with just a URL
    and not an Engine, though an Engine is acceptable
    here as well.  By skipping the Engine creation
    we don't even need a DBAPI to be available.

    Calls to context.execute() here emit the given string to the
    script output.

    """
    url = config.get_main_option("sqlalchemy.url")
    context.configure(url=url)

    with context.begin_transaction():
        context.run_migrations()
utils.py 文件源码 项目:concierge 作者: 9seconds 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def configure_logging(debug=False, verbose=True, stderr=True):
    config = copy.deepcopy(LOG_CONFIG)

    for handler in config["handlers"].values():
        if verbose:
            handler["level"] = "INFO"
        if debug:
            handler["level"] = "DEBUG"

    if verbose:
        config["handlers"]["stderr"]["formatter"] = "verbose"
    if debug:
        config["handlers"]["stderr"]["formatter"] = "debug"

    if stderr:
        config["loggers"][LOG_NAMESPACE]["handlers"].append("stderr")

    logging.config.dictConfig(config)
env.py 文件源码 项目:zlktqa 作者: NunchakusHuang 项目源码 文件源码 阅读 42 收藏 0 点赞 0 评论 0
def run_migrations_offline():
    """Run migrations in 'offline' mode.

    This configures the context with just a URL
    and not an Engine, though an Engine is acceptable
    here as well.  By skipping the Engine creation
    we don't even need a DBAPI to be available.

    Calls to context.execute() here emit the given string to the
    script output.

    """
    url = config.get_main_option("sqlalchemy.url")
    context.configure(url=url)

    with context.begin_transaction():
        context.run_migrations()
logmanagement.py 文件源码 项目:PowerMeter-Reader 作者: lucab85 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def setup_logging(self, default_path=PATH_LOGGING, default_level=logging.INFO, env_key='LOG_CFG'):
        path = default_path
        self.logconf = None
        value = os.getenv(env_key, None)
        if value:
            path = value
        if os.path.exists(path):
            with open(path, 'rt') as f:
                config = json.load(f)
            self.logconf = logging.config.dictConfig(config)
        elif os.path.exists(path.replace("../", "")):
            with open(path.replace("../", ""), 'rt') as f:
                config = json.load(f)
                self._changePath(config["handlers"])
            self.logconf = logging.config.dictConfig(config)
        else:
            print("Configurazione log non trovata (\"%s\"): applico le impostazioni predefinite" % path)
            self.logconf = logging.basicConfig(level=default_level)
env.py 文件源码 项目:Flask_Blog 作者: sugarguo 项目源码 文件源码 阅读 44 收藏 0 点赞 0 评论 0
def run_migrations_offline():
    """Run migrations in 'offline' mode.

    This configures the context with just a URL
    and not an Engine, though an Engine is acceptable
    here as well.  By skipping the Engine creation
    we don't even need a DBAPI to be available.

    Calls to context.execute() here emit the given string to the
    script output.

    """
    url = config.get_main_option("sqlalchemy.url")
    context.configure(url=url)

    with context.begin_transaction():
        context.run_migrations()
env.py 文件源码 项目:BookCloud 作者: livro-aberto 项目源码 文件源码 阅读 39 收藏 0 点赞 0 评论 0
def run_migrations_offline():
    """Run migrations in 'offline' mode.

    This configures the context with just a URL
    and not an Engine, though an Engine is acceptable
    here as well.  By skipping the Engine creation
    we don't even need a DBAPI to be available.

    Calls to context.execute() here emit the given string to the
    script output.

    """
    url = config.get_main_option("sqlalchemy.url")
    context.configure(url=url)

    with context.begin_transaction():
        context.run_migrations()
app.py 文件源码 项目:sharkfacts 作者: andrewthetechie 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def _get_config(key, default_value=None, required=False):
    """
    Gets config from environment variables
    Will return default_value if key is not in environment variables
    :param key: the key of the env variable you are looking for
    :param default_value: value to return if key not in os.environ.
    :param required: if true and key is not set, will raise InvalidConfigException
    :return: os.environ[key] if key in os.environ els default_value
    :exception InvalidConfigException - raised when a required config key is not properly set
    """
    if required and key not in os.environ:
        raise InvalidConfigException("Invalid ENV variable. Please check {0}".format(key))
    to_return = os.environ.get(key, default_value)
    if isinstance(to_return, basestring):
        try:
            to_return = _string_to_bool(to_return)
        except NonBooleanStringException:
            pass
    os.environ[key] = str(to_return)
    return to_return
run.py 文件源码 项目:Round1 作者: general-ai-challenge 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def setup_logging(
    default_path='logging.ini',
    default_level=logging.INFO,
    env_key='LOG_CFG'
):
    """Setup logging configuration

    """
    path = default_path
    value = os.getenv(env_key, None)
    if value:
        path = value
    if os.path.exists(path):
        logging.config.fileConfig(default_path)
    else:
        logging.basicConfig(level=default_level)
env.py 文件源码 项目:IntegraTI-API 作者: discentes-imd 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def run_migrations_offline():
    """Run migrations in 'offline' mode.

    This configures the context with just a URL
    and not an Engine, though an Engine is acceptable
    here as well.  By skipping the Engine creation
    we don't even need a DBAPI to be available.

    Calls to context.execute() here emit the given string to the
    script output.

    """
    url = config.get_main_option("sqlalchemy.url")
    context.configure(url=url)

    with context.begin_transaction():
        context.run_migrations()
log.py 文件源码 项目:CodingDojo 作者: ComputerSocietyUNB 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def configure_logging(logging_config, logging_settings):
    if not sys.warnoptions:
        # Route warnings through python logging
        logging.captureWarnings(True)
        # RemovedInNextVersionWarning is a subclass of DeprecationWarning which
        # is hidden by default, hence we force the "default" behavior
        warnings.simplefilter("default", RemovedInNextVersionWarning)

    if logging_config:
        # First find the logging configuration function ...
        logging_config_func = import_string(logging_config)

        logging.config.dictConfig(DEFAULT_LOGGING)

        # ... then invoke it with the logging settings
        if logging_settings:
            logging_config_func(logging_settings)
env.py 文件源码 项目:flask-api-skeleton 作者: ianunruh 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def run_migrations_offline():
    """Run migrations in 'offline' mode.

    This configures the context with just a URL
    and not an Engine, though an Engine is acceptable
    here as well.  By skipping the Engine creation
    we don't even need a DBAPI to be available.

    Calls to context.execute() here emit the given string to the
    script output.

    """
    url = config.get_main_option("sqlalchemy.url")
    context.configure(url=url)

    with context.begin_transaction():
        context.run_migrations()
env.py 文件源码 项目:bit 作者: codesmart-co 项目源码 文件源码 阅读 37 收藏 0 点赞 0 评论 0
def run_migrations_offline():
    """Run migrations in 'offline' mode.

    This configures the context with just a URL
    and not an Engine, though an Engine is acceptable
    here as well.  By skipping the Engine creation
    we don't even need a DBAPI to be available.

    Calls to context.execute() here emit the given string to the
    script output.

    """
    url = config.get_main_option("sqlalchemy.url")
    context.configure(url=url)

    with context.begin_transaction():
        context.run_migrations()
config.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def _applyConfigurationToValues(self, parser, config, values):
        for name, value, filename in config:
            if name in option_blacklist:
                continue
            try:
                self._processConfigValue(name, value, values, parser)
            except NoSuchOptionError, exc:
                self._file_error(
                    "Error reading config file %r: "
                    "no such option %r" % (filename, exc.name),
                    name=name, filename=filename)
            except optparse.OptionValueError, exc:
                msg = str(exc).replace('--' + name, repr(name), 1)
                self._file_error("Error reading config file %r: "
                                 "%s" % (filename, msg),
                                 name=name, filename=filename)
env.py 文件源码 项目:circleci-demo-python-flask 作者: CircleCI-Public 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def run_migrations_offline():
    """Run migrations in 'offline' mode.

    This configures the context with just a URL
    and not an Engine, though an Engine is acceptable
    here as well.  By skipping the Engine creation
    we don't even need a DBAPI to be available.

    Calls to context.execute() here emit the given string to the
    script output.

    """
    url = config.get_main_option("sqlalchemy.url")
    context.configure(url=url)

    with context.begin_transaction():
        context.run_migrations()
env.py 文件源码 项目:microflack_messages 作者: miguelgrinberg 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def run_migrations_offline():
    """Run migrations in 'offline' mode.

    This configures the context with just a URL
    and not an Engine, though an Engine is acceptable
    here as well.  By skipping the Engine creation
    we don't even need a DBAPI to be available.

    Calls to context.execute() here emit the given string to the
    script output.

    """
    url = config.get_main_option("sqlalchemy.url")
    context.configure(url=url)

    with context.begin_transaction():
        context.run_migrations()
env.py 文件源码 项目:sitrep 作者: bittorrent 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def run_migrations_offline():
    """Run migrations in 'offline' mode.

    This configures the context with just a URL
    and not an Engine, though an Engine is acceptable
    here as well.  By skipping the Engine creation
    we don't even need a DBAPI to be available.

    Calls to context.execute() here emit the given string to the
    script output.

    """
    url = config.get_main_option("sqlalchemy.url")
    context.configure(url=url)

    with context.begin_transaction():
        context.run_migrations()
env.py 文件源码 项目:Leics 作者: LeicsFrameWork 项目源码 文件源码 阅读 60 收藏 0 点赞 0 评论 0
def run_migrations_offline():
    """Run migrations in 'offline' mode.

    This configures the context with just a URL
    and not an Engine, though an Engine is acceptable
    here as well.  By skipping the Engine creation
    we don't even need a DBAPI to be available.

    Calls to context.execute() here emit the given string to the
    script output.

    """
    url = config.get_main_option("sqlalchemy.url")
    context.configure(url=url)

    with context.begin_transaction():
        context.run_migrations()
env.py 文件源码 项目:ud-catalog 作者: aviaryan 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def run_migrations_offline():
    """Run migrations in 'offline' mode.

    This configures the context with just a URL
    and not an Engine, though an Engine is acceptable
    here as well.  By skipping the Engine creation
    we don't even need a DBAPI to be available.

    Calls to context.execute() here emit the given string to the
    script output.

    """
    url = config.get_main_option("sqlalchemy.url")
    context.configure(url=url)

    with context.begin_transaction():
        context.run_migrations()
invalidroutesreporter.py 文件源码 项目:invalidroutesreporter 作者: pierky 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def process_alert(self, route):
        recipients = list(set(route["recipient_ids"]))

        logging.debug("Processing alert for {}, recipients {}".format(
            str(route), str(recipients)
        ))

        if "*" in self.data:
            recipients.append("*")

        for recipient_id in recipients:
            if not recipient_id in self.data:
                continue

            recipient = self.data[recipient_id]

            if len(recipient["routes"]) < recipient["config"]["max_routes"]:
                recipient["routes"].append(route)
            else:
                logging.debug("Discarding route {} for {}: buffer full ".format(
                    route["prefix"], recipient_id
                ))
invalidroutesreporter.py 文件源码 项目:invalidroutesreporter 作者: pierky 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def _flush_recipient(self, recipient):
        if not isinstance(recipient["config"]["info"]["email"], list):
            email_addresses = [recipient["config"]["info"]["email"]]
        else:
            email_addresses = list(set(recipient["config"]["info"]["email"]))

        logging.info("Sending email to {} ({}) for {}".format(
            recipient["id"],
            ", ".join(email_addresses),
            ", ".join([route["prefix"] for route in recipient["routes"]])
        ))

        data = {
            "id": recipient["id"],
            "from_addr": self.from_addr,
            "subject": self.subject,
            "routes_list": self._format_list_of_routes(recipient["routes"])
        }
        msg = MIMEText(self.template.format(**data))
        msg['Subject'] = self.subject
        msg['From'] = self.from_addr
        msg['To'] = ", ".join(email_addresses)

        self._send_email(self.from_addr, email_addresses, msg.as_string())
invalidroutesreporter.py 文件源码 项目:invalidroutesreporter 作者: pierky 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def process_alert(self, route):
        recipients = list(set(route["recipient_ids"]))

        logging.debug("Processing alert for {}, recipients {}".format(
            str(route), str(recipients)
        ))

        if "*" in self.data:
            recipients.append("*")

        for recipient_id in recipients:
            if not recipient_id in self.data:
                continue

            recipient = self.data[recipient_id]

            if len(recipient["routes"]) < recipient["config"]["max_routes"]:
                recipient["routes"].append(route)
            else:
                logging.debug("Discarding route {} for {}: buffer full ".format(
                    route["prefix"], recipient_id
                ))
invalidroutesreporter.py 文件源码 项目:invalidroutesreporter 作者: pierky 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def _flush_recipient(self, recipient):
        if not isinstance(recipient["config"]["info"]["email"], list):
            email_addresses = [recipient["config"]["info"]["email"]]
        else:
            email_addresses = list(set(recipient["config"]["info"]["email"]))

        logging.info("Sending email to {} ({}) for {}".format(
            recipient["id"],
            ", ".join(email_addresses),
            ", ".join([route["prefix"] for route in recipient["routes"]])
        ))

        data = {
            "id": recipient["id"],
            "from_addr": self.from_addr,
            "subject": self.subject,
            "routes_list": self._format_list_of_routes(recipient["routes"])
        }
        msg = MIMEText(self.template.format(**data))
        msg['Subject'] = self.subject
        msg['From'] = self.from_addr
        msg['To'] = ", ".join(email_addresses)

        self._send_email(self.from_addr, email_addresses, msg.as_string())
env.py 文件源码 项目:do-portal 作者: certeu 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def run_migrations_offline():
    """Run migrations in 'offline' mode.

    This configures the context with just a URL
    and not an Engine, though an Engine is acceptable
    here as well.  By skipping the Engine creation
    we don't even need a DBAPI to be available.

    Calls to context.execute() here emit the given string to the
    script output.

    """
    url = config.get_main_option("sqlalchemy.url")
    context.configure(url=url)

    with context.begin_transaction():
        context.run_migrations()
env.py 文件源码 项目:akamatsu 作者: rmed 项目源码 文件源码 阅读 42 收藏 0 点赞 0 评论 0
def run_migrations_offline():
    """Run migrations in 'offline' mode.

    This configures the context with just a URL
    and not an Engine, though an Engine is acceptable
    here as well.  By skipping the Engine creation
    we don't even need a DBAPI to be available.

    Calls to context.execute() here emit the given string to the
    script output.

    """
    url = config.get_main_option("sqlalchemy.url")
    context.configure(url=url)

    with context.begin_transaction():
        context.run_migrations()
env.py 文件源码 项目:flask-microservices-users 作者: realpython 项目源码 文件源码 阅读 38 收藏 0 点赞 0 评论 0
def run_migrations_offline():
    """Run migrations in 'offline' mode.

    This configures the context with just a URL
    and not an Engine, though an Engine is acceptable
    here as well.  By skipping the Engine creation
    we don't even need a DBAPI to be available.

    Calls to context.execute() here emit the given string to the
    script output.

    """
    url = config.get_main_option("sqlalchemy.url")
    context.configure(url=url)

    with context.begin_transaction():
        context.run_migrations()
env.py 文件源码 项目:podigger 作者: perna 项目源码 文件源码 阅读 40 收藏 0 点赞 0 评论 0
def run_migrations_offline():
    """Run migrations in 'offline' mode.

    This configures the context with just a URL
    and not an Engine, though an Engine is acceptable
    here as well.  By skipping the Engine creation
    we don't even need a DBAPI to be available.

    Calls to context.execute() here emit the given string to the
    script output.

    """
    url = config.get_main_option("sqlalchemy.url")
    context.configure(url=url)

    with context.begin_transaction():
        context.run_migrations()
log.py 文件源码 项目:scarlett_os 作者: bossjones 项目源码 文件源码 阅读 75 收藏 0 点赞 0 评论 0
def setup_logging(verbosity_level, save_debug_log):

    logging.captureWarnings(True)

    # if config['logging']['config_file']:
    #     # Logging config from file must be read before other handlers are
    #     # added. If not, the other handlers will have no effect.
    #     try:
    #         path = config['logging']['config_file']
    #         logging.config.fileConfig(path, disable_existing_loggers=False)
    #     except Exception as e:
    #         # Catch everything as logging does not specify what can go wrong.
    #         logger.error('Loading logging config %r failed. %s', path, e)

    setup_console_logging(verbosity_level)
    if save_debug_log:
        print('Here we would call setup_debug_logging_to_file(config)')
        # setup_debug_logging_to_file(config)

    _delayed_handler.release()
logger.py 文件源码 项目:scarlett_os 作者: bossjones 项目源码 文件源码 阅读 45 收藏 0 点赞 0 评论 0
def setup_logger():
    from colorlog import ColoredFormatter
    from gettext import gettext as _  # noqa

    try:
        """Return a logging obj with a default ColoredFormatter."""
        formatter = ColoredFormatter(
            "%(asctime)s %(name)-12s (%(threadName)-9s) %(log_color)s%(levelname)-8s%(reset)s (%(funcName)-5s) %(message_log_color)s%(message)s",  # noqa
            datefmt=None,
            reset=True,
            log_colors={
                'DEBUG': 'cyan',
                'INFO': 'green',
                'WARNING': 'yellow',
                'ERROR': 'red',
                'CRITICAL': 'bold_red',
                'TRACE': 'purple'
            },
            secondary_log_colors={
                'message': {
                    'ERROR': 'red',
                    'CRITICAL': 'red',
                    'DEBUG': 'yellow',
                    'INFO': 'yellow,bg_blue'
                }
            },
            style='%'
        )

        handler = logging.StreamHandler()
        handler.setFormatter(formatter)
        logging.getLogger('').addHandler(handler)
        logging.root.setLevel(logging.DEBUG)
    except ImportError:
        # No color available, use default config
        logging.basicConfig(format='%(levelname)s: %(message)s')
        logging.warn("Disabling color, you really want to install colorlog.")
env.py 文件源码 项目:myproject 作者: dengliangshi 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def run_migrations_offline():
    """Run migrations in 'offline' mode.

    This configures the context with just a URL
    and not an Engine, though an Engine is acceptable
    here as well.  By skipping the Engine creation
    we don't even need a DBAPI to be available.

    Calls to context.execute() here emit the given string to the
    script output.

    """
    url = config.get_main_option("sqlalchemy.url")
    context.configure(url=url)

    with context.begin_transaction():
        context.run_migrations()


问题


面经


文章

微信
公众号

扫码关注公众号