class Command(AbstractCommand): name = 'routes' summary = "Show Application routing" usage = "Usage: %prog [OPTIONS]" def __init__(self): super(Command, self).__init__() def handle(self, *args, **options): try: importFromString('config') except ImportError: sys.path.append(os.getcwd()) try: importFromString('config') except ImportError, e: t = sys.exc_info()[2] raise CommandError(u'コンフィグファイルが見当たりません:: %s' % e), None, traceback.print_tb(t) config = ConfigManager.getConfig(getEnviron()) appPath = os.path.join(os.getcwd(), config['APP_DIRECTORY']) if not os.path.isdir(appPath): t = sys.exc_info()[2] raise CommandError( u'アプリケーションが見当たりません::'), None, traceback.print_tb(t) try: router = importFromString(config['APP_DIRECTORY'] + '.' + 'router') except Exception, e: t = sys.exc_info()[2] raise CommandError(u'ルーターがみつかりません。\n %s' % e), None, traceback.print_tb(t)
def handle(self, moduleType, name, *args, **options): if not moduleType == 'controller': raise CommandError('ない') path = options.get('path') if path is None: currentPath = os.getcwd() try: importFromString('config') except: sys.path.append(os.getcwd()) try: importFromString('config') except ImportError: raise CommandError('config file is not found...') config = ConfigManager.getConfig(getEnviron()) path = os.path.join(currentPath, config['APP_DIRECTORY'], config['CONTROLLER_DIRECTORY']) if not os.path.isdir(path): raise CommandError('Given path is invalid') ctrlTemplate = os.path.join(shimehari.__path__[0], 'core', 'conf', 'controller_template.org.py') name, filename = self.filenameValidation(path, name) newPath = os.path.join(path, filename) self.readAndCreateFileWithRename(ctrlTemplate, newPath, name)
def __init__(self, storetype=None): config = ConfigManager.getConfig(getEnviron()) if config['CACHE_STORE'] is not None: store = config['CACHE_STORE'] else: store = storetype self.store = self._importCacheStore(store)
def _importCacheStore(self, storetype): if storetype == 'simple': return SimpleCacheStore() if storetype == 'memcache': return MemcachedCacheStore() if storetype == 'file': config = ConfigManager.getConfig(getEnviron()) return FileSystemCacheStore(cacheDir=config['CACHE_DIR']) if storetype == 'redis': return RedisCacheStore() return NullCacheStore()
def getConfig(cls, environ=None): u"""Config インスタンスを取得します。 :param environ: 取得したい環境。 指定されない場合は現在の環境に合わせた Config が返されます。 """ if environ is None: environ = getEnviron() if environ in cls.configrations: return cls.configrations[environ] return None
def createLogger(loggerName='shimehariLoagger'): Logger = getLoggerClass() class DebugLogger(Logger): def getEffectiveLevel(x): if x.level == 0 and config['DEBUG']: return DEBUG return Logger.getEffectiveLevel(x) class DebugHandler(StreamHandler): def emit(x, record): StreamHandler.emit(x, record) if config['DEBUG'] else None config = ConfigManager.getConfig(getEnviron()) if config['LOG_FILE_OUTPUT']: fn = os.path.join(config['LOG_FILE_DIRECTORY'], getEnviron()) + '.log' if config['LOG_FILE_ROTATE']: from logging import RotateFileHandler handler = RotateFileHandler(fn, 'a', config['LOG_ROTATE_MAX_BITE'], config['LOG_ROTATE_COUNT']) else: from logging import FileHandler handler = FileHandler(fn, 'a') handler.setFormatter(Formatter(config['LOG_OUTPUT_FORMAT'])) logger = getLogger() else: handler = DebugHandler() handler.setFormatter(Formatter(config['LOG_DEBUG_FORMAT'])) logger = getLogger(loggerName) logger.setLevel(DEBUG) del logger.handlers[:] logger.__class__ = DebugLogger logger.addHandler(handler) return logger
#!/usr/bin/env python # -*- coding: utf-8 -*- u""" =============================== [[Shimehari Config]] config ~~~~~~ =============================== """ from shimehari.configuration import Config, ConfigManager from werkzeug.utils import import_string from shimehari.helpers import getEnviron currentEnv = getEnviron() obj = import_string('config.%s' % currentEnv) config = {} for key in dir(obj): if key.isupper(): config[key] = getattr(obj, key) ConfigManager.addConfig(Config(currentEnv, config))