Пример #1
0
def main():
    CONF.register_cli_opt(command_opt)
    try:
        cfg_files = cfg.find_config_files(
            project='glance', prog='glance-registry')
        cfg_files.extend(
            cfg.find_config_files(project='glance', prog='glance-api'))
        config.parse_args(
            default_config_files=cfg_files, usage="%(prog)s [options] <cmd>")
        log.setup('glance')
    except RuntimeError as e:
        sys.exit("ERROR: %s" % e)

    try:
        if CONF.command.action.startswith('db'):
            return CONF.command.action_fn()
        else:
            func_kwargs = {}
            for k in CONF.command.action_kwargs:
                v = getattr(CONF.command, 'action_kwarg_' + k)
                if v is None:
                    continue
                func_kwargs[k] = strutils.safe_decode(v)

            func_args = [
                strutils.safe_decode(arg) for arg in CONF.command.action_args
            ]
            return CONF.command.action_fn(*func_args, **func_kwargs)
    except exception.GlanceException as e:
        sys.exit("ERROR: %s" % utils.exception_to_str(e))
Пример #2
0
def main():
    CONF.register_cli_opt(command_opt)
    try:
        cfg_files = cfg.find_config_files(project='glance',
                                          prog='glance-registry')
        cfg_files.extend(
            cfg.find_config_files(project='glance', prog='glance-api'))
        config.parse_args(default_config_files=cfg_files,
                          usage="%(prog)s [options] <cmd>")
        log.setup('glance')
    except RuntimeError as e:
        sys.exit("ERROR: %s" % e)

    try:
        if CONF.command.action.startswith('db'):
            return CONF.command.action_fn()
        else:
            func_kwargs = {}
            for k in CONF.command.action_kwargs:
                v = getattr(CONF.command, 'action_kwarg_' + k)
                if v is None:
                    continue
                func_kwargs[k] = strutils.safe_decode(v)

            func_args = [
                strutils.safe_decode(arg) for arg in CONF.command.action_args
            ]
            return CONF.command.action_fn(*func_args, **func_kwargs)
    except exception.GlanceException as e:
        sys.exit("ERROR: %s" % e)
Пример #3
0
def _exception_to_unicode(exc):
    try:
        return unicode(exc)
    except UnicodeError:
        try:
            return strutils.safe_decode(str(exc), errors="ignore")
        except UnicodeError:
            msg = _("Caught '%(exception)s' exception.") % {"exception": exc.__class__.__name__}
            return strutils.safe_decode(msg, errors="ignore")
Пример #4
0
def _exception_to_unicode(exc):
    try:
        return unicode(exc)
    except UnicodeError:
        try:
            return strutils.safe_decode(str(exc), errors='ignore')
        except UnicodeError:
            msg = (_("Caught '%(exception)s' exception.") %
                   {"exception": exc.__class__.__name__})
            return strutils.safe_decode(msg, errors='ignore')
Пример #5
0
def loads(s, encoding='utf-8', **kwargs):
    return json.loads(strutils.safe_decode(s, encoding), **kwargs)