示例#1
0
文件: base.py 项目: muma378/moose
 def __init__(self, stdout=None, stderr=None, no_color=False):
     self.stdout = OutputWrapper(stdout or sys.stdout)
     self.stderr = OutputWrapper(stderr or sys.stderr)
     if no_color:
         self.style = no_style()
     else:
         self.style = color_style()
         self.stderr.style_func = self.style.ERROR
示例#2
0
	def __init__(self, app_config, stdout=None, stderr=None, style=None):
		super(BaseAction, self).__init__()

		# Sets app_config
		self.app = app_config

		# Sets stdout and stderr, which were supposed to passed from command
		self.stdout = stdout or sys.stdout
		self.stderr = stderr or sys.stderr
		self.style  = style or color_style()

		# Imports stats class
		self.stats = import_string(self.stats_class)(self)

		# String to record and display after all works done
		self.output = []
示例#3
0
    def main_help_text(self, commands_only=False):
        """
        Returns the script's main help text, as a string.
        """
        if commands_only:
            usage = sorted(get_commands().keys())
        else:
            usage = [
                "",
                "Type '%s help <subcommand>' for help on a specific subcommand."
                % self.prog_name,
                "",
                "Available subcommands:",
            ]
            commands_dict = defaultdict(lambda: [])
            for name, app in get_commands().items():
                if app == 'moose.core':
                    app = 'moose'
                else:
                    app = app.rpartition('.')[-1]
                commands_dict[app].append(name)
            style = color_style()
            for app in sorted(commands_dict.keys()):
                usage.append("")
                usage.append(style.NOTICE("[%s]" % app))
                for name in sorted(commands_dict[app]):
                    usage.append("    %s" % name)
            # Output an extra note if settings are not properly configured
            if self.settings_exception is not None:
                usage.append(
                    style.NOTICE(
                        "Note that only Moose core commands are listed "
                        "as settings are not properly configured (error: %s)."
                        % self.settings_exception))

        return '\n'.join(usage)
示例#4
0
文件: base.py 项目: muma378/moose
 def __init__(self, out, style_func=None, ending='\n'):
     self._out = out
     self.style_func = style_func
     self.ending = ending
     self.style = color_style()
示例#5
0
文件: log.py 项目: yuwenhui/moose
 def __init__(self, *args, **kwargs):
     self.style = color_style()
     super(ConsoleFormatter, self).__init__(*args, **kwargs)
示例#6
0
文件: terminal.py 项目: muma378/moose
# -*- coding: utf-8 -*-
# A standard output wrapper, defines whether (according to the verbose level)
# and what style (according to colors defined) uses to output

import sys

from moose.utils.encoding import force_str
from moose.core.management.color import color_style
from moose.core.exceptions import ImproperlyConfigured

style = color_style()


class OutputWrapper(object):
    @property
    def verbose(self):
        return self._verbose

    @verbose.setter
    def verbose(self, verbose):
        if verbose in [0, 1, 2, 3]:
            self._verbose = verbose
        elif verbose == None:
            self._verbose = 1
        else:
            raise ImproperlyConfigured(
                "Verbose level was ought to be set from "
                "0 to 3, but got %s." % verbose)

    @property
    def style_func(self):