deprecation.py 文件源码

python
阅读 36 收藏 0 点赞 0 评论 0

项目:zing 作者: evernote 项目源码 文件源码
def check_deprecated_settings(app_configs=None, **kwargs):
    errors = []

    for old, new, dep_ver, remove_ver in DEPRECATIONS:

        # Old setting just disappeared, we just want you to cleanup
        if hasattr(settings, old) and new is None:
            errors.append(checks.Info(
                ("Setting %s was removed in Pootle %s." %
                 (old, dep_ver)),
                hint=("Remove %s from your settings." % old),
                id="pootle.I002",
            ))
            continue

        # Both old and new defined, we'd like you to remove the old setting
        if hasattr(settings, old) and hasattr(settings, new):
            errors.append(checks.Info(
                ("Setting %s was replaced by %s in Pootle %s. Both are set." %
                 (old, new, dep_ver)),
                hint=("Remove %s from your settings." % old),
                id="pootle.I002",
            ))
            continue

        # Old setting is present and new setting is not defined:
        # - Warn and copy
        # - Fail hard if its too old
        if hasattr(settings, old) and not hasattr(settings, new):
            from pootle import VERSION
            if VERSION >= tuple(int(x) for x in remove_ver.split(".")):
                errors.append(checks.Critical(
                    ("Setting %s is deprecated and was removed in Pootle %s." %
                     (old, remove_ver)),
                    hint=("Use %s instead." % new),
                    id="pootle.W002",
                ))
            else:
                errors.append(checks.Warning(
                    ("Setting %s is deprecated and will be removed in "
                     "Pootle %s." % (old, remove_ver)),
                    hint=("Use %s instead." % new),
                    id="pootle.W002",
                ))
                setattr(settings, new, getattr(settings, old))
            continue

    return errors
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号