ARCH_CONFIG_PATH = "/etc/rest_arch/env.yaml" APP_CONFIG_PATH = "app.yaml" APP_TYPE_BARE = "bare" HUSKAR_CACHE_DIR = "/var/run/skt_huskar" DEFAULT_APP_PORT = 8010 DEFAULT_WORKER_CLASS = 'gevent' DEFAULT_WORKER_NUMBER_DEV = 1 DEFAULT_WORKER_NUMBER_PROD = 2 ENV_DEV = 'dev' class AppConfigLoadFailException(SKTBaseException):
    """Failed to load app.yaml, not found or yaml invalid""" MOBILE_RE = re.compile('^1[34578]\d{9}$')
ALL_PHONE_RE = re.compile('^1[34578]\d{9}$|^[2-9]\d{6,7}(-\d{1,4})?$'
                          '|^6[1-9]{2,5}$')
EMAIL_RE = re.compile('\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*')
UNIT_MAP = {u'十': 10, u'百': 100, u'千': 1000, u'万': 10000, u'亿': 100000000}
NUM_MAP = u"零一二三四五六七八九"
LIB_DIR_PATH = os.path.dirname(os.path.abspath(__file__))
DEPRECATION_PATTERN = 'option %r is deprecating, please use %r instead'
def is_mobile(s):
def is_phone(s):
def is_email(s):
def datetime2utc(dt):
def utc2datetime(t):
def strptime2date(date_str):
def chinese2num(s):
def md5(s):
def sha1(s):
def get_unique_string(length=31):
    def __init__(self, fn):
    def __get__(self, inst, cls):
    def __init__(self, *envvars):
    def configured(self):
    def _normalize(self, varname):
    def __getitem__(self, key):
    def get_int(self, key):
    def __setitem__(self, key, value):
    def __init__(self, val):
    def is_empty(val):
def warn_deprecation(logger_or_name, old, new, lvl=logging.WARNING,
                     pat=DEPRECATION_PATTERN):
class CachedProperty(object):
class EnvvarReader(dict):
class EmptyValue(object):
import sys
import yaml
import logging
import rest_arch
from .consts import (
    ARCH_CONFIG_PATH,
    APP_CONFIG_PATH,
    APP_TYPE_BARE,
    HUSKAR_CACHE_DIR,
    DEFAULT_APP_PORT,
    DEFAULT_WORKER_CLASS,
    DEFAULT_WORKER_NUMBER_DEV,
    DEFAULT_WORKER_NUMBER_PROD,
    ENV_DEV
)
from .exc import AppConfigLoadFailException
from ..utils import EnvvarReader, cached_property
        from .env import is_in_dev
        from .env import env, is_in_prod
        from .env import is_in_prod
# -*- coding: utf-8 -*-




logger = logging.getLogger(__name__)


class ArchConfig(object):
    """
    Application independent configs, as a yaml file at
    `CORE_CONFIG_PATH`, example::

        env: 'dev'
        cluster: 'arch-sync-01'
        zookeeper_config:
          hosts: localhost:2181
          username: root
          password:

    """

    def __init__(self):
        self.config = None

    def _load(self, _file):
        try:
            if isinstance(_file, basestring):
                self.config = yaml.load(open(_file))
            else:
                self.config = yaml.load(_file)
        except (IOError, yaml.error.YAMLError):
            logger.warn("cannot load config from %r, useing default", _file)
            self.config = {}

    def load(self, file=None):
        file = file or ARCH_CONFIG_PATH
        self._load(file)
        return self

    @property
    def env(self):
        return self.config.get('env', ENV_DEV)

    @property
    def cluster(self):
        return self.config.get('cluster', None)

arch_config = None


def load_arch_config():
    global arch_config
    if arch_config is None:
        arch_config = ArchConfig().load()
    return arch_config

haproxy_port_map = {}
worker_num_map = {}
port_map = {}


class BareAppConfig(object):
    """Application related configs, as a yaml file at
    `APP_CONFIG_PATH`, e.g.:

        app_name: ves.note
        settings: note.settings
        services:
          wsgi:
            app: note:app
            worker_class: gevent
            requirements: wsgi_requirements.txt
    """

    TYPE_NAME = APP_TYPE_BARE
    PORT_MAP = port_map
    DEFAULT_APP_PORT = None
    DEFAULT_WORKER_CLASS = None

    envvar = EnvvarReader(
        "SKT_APP_PORT",
        "SKT_APP_HAPROXY_PORT",
        "SKT_APP_WORKER_NUM"
    )

    def __init__(self):
        self.config = None


    def load(self, config_path=APP_CONFIG_PATH, raise_exc=False):