本文整理汇总了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
示例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()
示例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)
示例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)