當前位置: 首頁>>代碼示例>>Python>>正文


Python base.OutputWrapper方法代碼示例

本文整理匯總了Python中django.core.management.base.OutputWrapper方法的典型用法代碼示例。如果您正苦於以下問題:Python base.OutputWrapper方法的具體用法?Python base.OutputWrapper怎麽用?Python base.OutputWrapper使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.core.management.base的用法示例。


在下文中一共展示了base.OutputWrapper方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from django.core.management import base [as 別名]
# 或者: from django.core.management.base import OutputWrapper [as 別名]
def __init__(self, stdout=None, stderr=None, no_color=False):
        super().__init__(stdout, stderr, no_color)

        # 檢測目錄位置
        if self.NEED_PROJECT:
            settings_path = os.path.join(os.getcwd(), 'deeru')
            settings_py = os.path.join(settings_path, 'settings.py')

            if not os.path.exists(settings_py):
                raise CommandError('該命令需要在工程目錄下運行')

        self.error = self.stderr.write

        info_out = OutputWrapper(sys.stdout)
        info_out.style_func = self.style.WARNING
        self.info = info_out.write

        success_out = OutputWrapper(sys.stdout)
        success_out.style_func = self.style.SUCCESS
        self.success = success_out.write 
開發者ID:gojuukaze,項目名稱:DeerU,代碼行數:22,代碼來源:base.py

示例2: run_migrations

# 需要導入模塊: from django.core.management import base [as 別名]
# 或者: from django.core.management.base import OutputWrapper [as 別名]
def run_migrations(args, options, executor_codename, schema_name, allow_atomic=True, idx=None, count=None):
    from django.core.management import color
    from django.core.management.base import OutputWrapper
    from django.db import connections

    style = color.color_style()

    def style_func(msg):
        percent_str = ''
        if idx is not None and count is not None and count > 0:
            percent_str = '%d/%d (%s%%) ' % (idx + 1, count, int(100 * (idx + 1) / count))
        return '[%s%s:%s] %s' % (
            percent_str,
            style.NOTICE(executor_codename),
            style.NOTICE(schema_name),
            msg
        )

    connection = connections[options.get('database', get_tenant_database_alias())]
    connection.set_schema(schema_name)

    stdout = OutputWrapper(sys.stdout)
    stdout.style_func = style_func
    stderr = OutputWrapper(sys.stderr)
    stderr.style_func = style_func
    if int(options.get('verbosity', 1)) >= 1:
        stdout.write(style.NOTICE("=== Starting migration"))
    MigrateCommand(stdout=stdout, stderr=stderr).execute(*args, **options)

    try:
        transaction.commit()
        connection.close()
        connection.connection = None
    except transaction.TransactionManagementError:
        if not allow_atomic:
            raise

        # We are in atomic transaction, don't close connections
        pass

    connection.set_schema_to_public() 
開發者ID:django-tenants,項目名稱:django-tenants,代碼行數:43,代碼來源:base.py

示例3: log

# 需要導入模塊: from django.core.management import base [as 別名]
# 或者: from django.core.management.base import OutputWrapper [as 別名]
def log(self, level, *args, **kwargs):
        style = kwargs.pop("style", self.color.NOTICE)
        msg = " ".join((level.upper(), args[0] % args[1:], "\n"))
        if OutputWrapper is None:
            self.stream.write(msg)
        else:
            self.stream.write(msg, style_func=style) 
開發者ID:elastic,項目名稱:apm-agent-python,代碼行數:9,代碼來源:elasticapm.py

示例4: write

# 需要導入模塊: from django.core.management import base [as 別名]
# 或者: from django.core.management.base import OutputWrapper [as 別名]
def write(self, msg, style_func=None, ending=None, stream=None):
        """
        wrapper around self.stdout/stderr to ensure Django 1.4 compatibility
        """
        if stream is None:
            stream = self.stdout
        if OutputWrapper is None:
            ending = "\n" if ending is None else ending
            msg += ending
            stream.write(msg)
        else:
            stream.write(msg, style_func=style_func, ending=ending) 
開發者ID:elastic,項目名稱:apm-agent-python,代碼行數:14,代碼來源:elasticapm.py


注:本文中的django.core.management.base.OutputWrapper方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。