Beispiel #1
0
    def test_more_unicode(self):
        c = colored()
        s = c.red('foo', c.blue('bar'), c.green('baz'))
        assert s.no_color()
        c._fold_no_color(s, 'øfoo')
        c._fold_no_color('fooå', s)

        c = colored().red('åfoo')
        assert c._add(c, 'baræ') == '\x1b[1;31m\xe5foo\x1b[0mbar\xe6'

        c2 = colored().blue('ƒƒz')
        c3 = c._add(c, c2)
        assert c3 == '\x1b[1;31m\xe5foo\x1b[0m\x1b[1;34m\u0192\u0192z\x1b[0m'
Beispiel #2
0
    def execute_from_commandline(self, argv, cmd="celeryd"):
        argv = list(argv)   # don't modify callers argv.

        # Reserve the --nosplash|--quiet|-q/--verbose options.
        self.nosplash = False
        self.quiet = False
        self.verbose = False
        self.no_color = False
        if "--nosplash" in argv:
            self.nosplash = argv.pop(argv.index("--nosplash"))
        if "--quiet" in argv:
            self.quiet = argv.pop(argv.index("--quiet"))
        if "-q" in argv:
            self.quiet = argv.pop(argv.index("-q"))
        if "--verbose" in argv:
            self.verbose = argv.pop(argv.index("--verbose"))
        if "--no-color" in argv:
            self.no_color = argv.pop(argv.index("--no-color"))

        self.colored = term.colored(enabled=not self.no_color)
        self.OK = str(self.colored.green("OK"))
        self.FAILED = str(self.colored.red("FAILED"))
        self.DOWN = str(self.colored.magenta("DOWN"))

        self.prog_name = os.path.basename(argv.pop(0))
        if len(argv) == 0 or argv[0][0] == "-":
            return self.error()

        try:
            self.commands[argv[0]](argv[1:], cmd)
        except KeyError:
            self.error("Invalid command: %s" % argv[0])

        return self.retcode
Beispiel #3
0
    def __init__(
        self,
        loglevel=None,
        logfile=None,
        schedule=None,
        max_interval=None,
        scheduler_cls=None,
        defaults=None,
        socket_timeout=30,
        redirect_stdouts=None,
        redirect_stdouts_level=None,
        **kwargs
    ):
        """Starts the celerybeat task scheduler."""

        if defaults is None:
            from celery import conf as defaults
        self.defaults = defaults

        self.loglevel = loglevel or defaults.CELERYBEAT_LOG_LEVEL
        self.logfile = logfile or defaults.CELERYBEAT_LOG_FILE
        self.schedule = schedule or defaults.CELERYBEAT_SCHEDULE_FILENAME
        self.scheduler_cls = scheduler_cls or defaults.CELERYBEAT_SCHEDULER
        self.max_interval = max_interval
        self.socket_timeout = socket_timeout
        self.colored = term.colored(enabled=defaults.CELERYD_LOG_COLOR)
        self.redirect_stdouts = redirect_stdouts or defaults.REDIRECT_STDOUTS
        self.redirect_stdouts_level = redirect_stdouts_level or defaults.REDIRECT_STDOUTS_LEVEL

        if not isinstance(self.loglevel, int):
            self.loglevel = LOG_LEVELS[self.loglevel.upper()]
Beispiel #4
0
 def __init__(self, app=None, no_color=False, stdout=sys.stdout,
         stderr=sys.stderr):
     super(Command, self).__init__(app=app)
     self.colored = term.colored(enabled=not no_color)
     self.stdout = stdout
     self.stderr = stderr
     self.quiet = False
Beispiel #5
0
 def say(self, direction, title, body=""):
     if direction == "<-" and self.quiet:
         return
     dirstr = not self.quiet and t.bold(t.white(direction), " ") or ""
     print(t.colored(dirstr, title))
     if body and not self.quiet:
         print(body)
Beispiel #6
0
 def __init__(self, app, no_color=False, **kwargs):
     self.app = app
     self._init_manager(app, **kwargs)
     if not isatty(self.stdout):
         no_color = True
     self.colored = colored(enabled=not no_color)
     self.init_groups()
Beispiel #7
0
 def __init__(self, app=None, no_color=False, stdout=sys.stdout, stderr=sys.stderr, show_reply=True):
     super(Command, self).__init__(app=app)
     self.colored = term.colored(enabled=not no_color)
     self.stdout = stdout
     self.stderr = stderr
     self.quiet = False
     if show_reply is not None:
         self.show_reply = show_reply
Beispiel #8
0
 def run_from_argv(self, prog_name, argv):
     self.prog_name = prog_name
     self.command = argv[0]
     self.arglist = argv[1:]
     self.parser = self.create_parser(self.prog_name, self.command)
     options, args = self.parser.parse_args(self.arglist)
     self.colored = term.colored(enabled=not options.no_color)
     return self(*args, **options.__dict__)
Beispiel #9
0
    def __init__(self, concurrency=None, loglevel=None, logfile=None,
            hostname=None, discard=False, run_clockservice=False,
            schedule=None, task_time_limit=None, task_soft_time_limit=None,
            max_tasks_per_child=None, queues=None, events=False, db=None,
            include=None, app=None, pidfile=None,
            redirect_stdouts=None, redirect_stdouts_level=None,
            autoscale=None, scheduler_cls=None, pool=None, **kwargs):
        self.app = app = app_or_default(app)
        self.concurrency = (concurrency or
                            app.conf.CELERYD_CONCURRENCY or
                            multiprocessing.cpu_count())
        self.loglevel = loglevel or app.conf.CELERYD_LOG_LEVEL
        self.logfile = logfile or app.conf.CELERYD_LOG_FILE
        app.conf.CELERYD_LOG_COLOR = not self.logfile and isatty(sys.stderr)

        self.hostname = hostname or socket.gethostname()
        self.discard = discard
        self.run_clockservice = run_clockservice
        self.schedule = schedule or app.conf.CELERYBEAT_SCHEDULE_FILENAME
        self.scheduler_cls = scheduler_cls or app.conf.CELERYBEAT_SCHEDULER
        self.events = events
        self.task_time_limit = (task_time_limit or
                                app.conf.CELERYD_TASK_TIME_LIMIT)
        self.task_soft_time_limit = (task_soft_time_limit or
                                     app.conf.CELERYD_TASK_SOFT_TIME_LIMIT)
        self.max_tasks_per_child = (max_tasks_per_child or
                                    app.conf.CELERYD_MAX_TASKS_PER_CHILD)
        self.redirect_stdouts = (redirect_stdouts or
                                 app.conf.CELERY_REDIRECT_STDOUTS)
        self.redirect_stdouts_level = (redirect_stdouts_level or
                                       app.conf.CELERY_REDIRECT_STDOUTS_LEVEL)
        self.pool = (pool or app.conf.CELERYD_POOL)
        self.db = db
        self.use_queues = queues or []
        self.queues = None
        self.include = include or []
        self.pidfile = pidfile
        self.autoscale = None
        if autoscale:
            max_c, _, min_c = partition(autoscale, ",")
            self.autoscale = [int(max_c), min_c and int(min_c) or 0]
        self._isatty = sys.stdout.isatty()

        self.colored = term.colored(enabled=app.conf.CELERYD_LOG_COLOR)

        if isinstance(self.use_queues, basestring):
            self.use_queues = self.use_queues.split(",")
        if isinstance(self.include, basestring):
            self.include = self.include.split(",")

        if not isinstance(self.loglevel, int):
            try:
                self.loglevel = LOG_LEVELS[self.loglevel.upper()]
            except KeyError:
                self.die("Unknown level %r. Please use one of %s." % (
                            self.loglevel,
                            "|".join(l for l in LOG_LEVELS.keys()
                                        if isinstance(l, basestring))))
Beispiel #10
0
 def run_from_argv(self, prog_name, argv):
     self.prog_name = prog_name
     self.command = argv[0]
     self.arglist = argv[1:]
     self.parser = self.create_parser(self.prog_name, self.command)
     options, args = self.prepare_args(*self.parser.parse_args(self.arglist))
     self.colored = term.colored(enabled=not options["no_color"])
     self.quiet = options.get("quiet", False)
     self.show_body = options.get("show_body", True)
     return self(*args, **options)
Beispiel #11
0
 def get_command_info(self, command, indent=0, color=None):
     colored = term.colored().names[color] if color else lambda x: x
     obj = self.commands[command]
     if obj.leaf:
         return '|' + text.indent("celery %s" % colored(command), indent)
     return text.join([
         " ",
         '|' + text.indent("celery %s --help" % colored(command), indent),
         obj.list_commands(indent, "celery %s" % command, colored),
     ])
Beispiel #12
0
 def list_commands(self, indent=0, colored=None):
     colored = term.colored() if colored is None else colored
     white = colored.white
     ret = []
     for cls, commands, color in command_classes:
         ret.extend([
             text.indent('+ {0}: '.format(white(cls)), indent), '\n'.join(
                 self.get_command_info(command, indent + 4, color, colored)
                 for command in commands), ''
         ])
     return '\n'.join(ret).strip()
Beispiel #13
0
 def get_command_info(self, command, indent=0, color=None):
     colored = term.colored().names[color] if color else lambda x: x
     obj = self.commands[command]
     cmd = 'celery {0}'.format(colored(command))
     if obj.leaf:
         return '|' + text.indent(cmd, indent)
     return text.join([
         ' ',
         '|' + text.indent('{0} --help'.format(cmd), indent),
         obj.list_commands(indent, 'celery {0}'.format(command), colored),
     ])
Beispiel #14
0
    def format(self, record):
        levelname = record.levelname
        if self.use_color and levelname in COLORS:
            record.msg = term.colored(COLORS[levelname](record.msg))

        # Very ugly, but have to make sure processName is supported
        # by foreign logger instances.
        # (processName is always supported by Python 2.7)
        if "processName" not in record.__dict__:
            record.__dict__["processName"] = current_process()._name
        return logging.Formatter.format(self, record)
Beispiel #15
0
 def get_command_info(self, command, indent=0, color=None):
     colored = term.colored().names[color] if color else lambda x: x
     obj = self.commands[command]
     cmd = 'celery {0}'.format(colored(command))
     if obj.leaf:
         return '|' + text.indent(cmd, indent)
     return text.join([
         ' ',
         '|' + text.indent('{0} --help'.format(cmd), indent),
         obj.list_commands(indent, 'celery {0}'.format(command), colored),
     ])
Beispiel #16
0
 def list_commands(self, indent=0):
     white = term.colored().white
     ret = []
     for cls, commands, color in command_classes:
         ret.extend([
             text.indent("+ %s: " % white(cls), indent),
             "\n".join(self.get_command_info(command, indent + 4, color)
                         for command in commands),
             ""
         ])
     return "\n".join(ret).strip()
Beispiel #17
0
 def list_commands(self, indent=0):
     white = term.colored().white
     ret = []
     for cls, commands, color in command_classes:
         ret.extend([
             text.indent('+ {0}: '.format(white(cls)), indent),
             '\n'.join(self.get_command_info(command, indent + 4, color)
                       for command in commands),
             ''
         ])
     return '\n'.join(ret).strip()
Beispiel #18
0
 def __init__(self, app=None, get_app=None, no_color=False,
              stdout=None, stderr=None, quiet=False):
     self.app = app
     self.get_app = get_app or self._get_default_app
     self.stdout = stdout or sys.stdout
     self.stderr = stderr or sys.stderr
     self.no_color = no_color
     self.colored = term.colored(enabled=not self.no_color)
     self.quiet = quiet
     if not self.description:
         self.description = self.__doc__
Beispiel #19
0
class ColorFormatter(CeleryColorFormatter):
    """Logging formatter that adds colors based on severity."""

    #: Loglevel -> Color mapping.
    COLORS = colored().names
    colors = {
        u'DEBUG': COLORS[u'blue'], 
        u'WARNING': COLORS[u'yellow'],
        u'WARN': COLORS[u'yellow'],
        u'ERROR': COLORS[u'red'], 
        u'CRITICAL': COLORS[u'magenta']
    }  
Beispiel #20
0
 def run_from_argv(self, argv):
     self.prog_name = os.path.basename(argv[0])
     self.command = argv[1]
     self.arglist = argv[2:]
     self.parser = self.create_parser(self.prog_name, self.command)
     options, args = self.parser.parse_args(self.arglist)
     if options.loader:
         os.environ["CELERY_LOADER"] = options.loader
     if options.conf:
         os.environ["CELERY_CONFIG_MODULE"] = options.conf
     self.colored = term.colored(enabled=not options.no_color)
     self(*args, **options.__dict__)
Beispiel #21
0
class ColorFormatter(CeleryColorFormatter):
    #: Loglevel -> Color mapping.
    COLORS = colored().names
    colors = {
        'DEBUG': COLORS['blue'],
        'WARNING': COLORS['yellow'],
        'WARN': COLORS['yellow'],
        'ERROR': COLORS['red'],
        'CRITICAL': COLORS['magenta'],
        'TEST': COLORS['green'],
        'TESTPLAN': COLORS['cyan']
    }
Beispiel #22
0
 def run_from_argv(self, argv):
     self.prog_name = os.path.basename(argv[0])
     self.command = argv[1]
     self.arglist = argv[2:]
     self.parser = self.create_parser(self.prog_name, self.command)
     options, args = self.parser.parse_args(self.arglist)
     if options.loader:
         os.environ["CELERY_LOADER"] = options.loader
     if options.conf:
         os.environ["CELERY_CONFIG_MODULE"] = options.conf
     self.colored = term.colored(enabled=not options.no_color)
     self(*args, **options.__dict__)
Beispiel #23
0
 def get_command_info(self, command, indent=0, color=None):
     colored = term.colored().names[color] if color else lambda x: x
     obj = self.commands[command]
     cmd = "celery {0}".format(colored(command))
     if obj.leaf:
         return "|" + text.indent(cmd, indent)
     return text.join(
         [
             " ",
             "|" + text.indent("{0} --help".format(cmd), indent),
             obj.list_commands(indent, "celery {0}".format(command), colored),
         ]
     )
Beispiel #24
0
 def __init__(self,
              app=None,
              no_color=False,
              stdout=sys.stdout,
              stderr=sys.stderr,
              show_reply=True):
     super(Command, self).__init__(app=app)
     self.colored = term.colored(enabled=not no_color)
     self.stdout = stdout
     self.stderr = stderr
     self.quiet = False
     if show_reply is not None:
         self.show_reply = show_reply
Beispiel #25
0
 def list_commands(self, indent=0, colored=None):
     colored = term.colored() if colored is None else colored
     white = colored.white
     ret = []
     for cls, commands, color in command_classes:
         ret.extend([
             text.indent('+ {0}: '.format(white(cls)), indent),
             '\n'.join(
                 self.get_command_info(command, indent + 4, color, colored)
                 for command in commands),
             ''
         ])
     return '\n'.join(ret).strip()
Beispiel #26
0
 def get_command_info(cls, command, indent=0,
                      color=None, colored=None, app=None):
     colored = term.colored() if colored is None else colored
     colored = colored.names[color] if color else lambda x: x
     obj = cls.commands[command]
     cmd = 'celery {0}'.format(colored(command))
     if obj.leaf:
         return '|' + text.indent(cmd, indent)
     return text.join([
         ' ',
         '|' + text.indent('{0} --help'.format(cmd), indent),
         obj.list_commands(indent, 'celery {0}'.format(command), colored,
                           app=app),
     ])
Beispiel #27
0
    def __init__(self, concurrency=None, loglevel=None, logfile=None,
            hostname=None, discard=False, run_clockservice=False,
            schedule=None, task_time_limit=None, task_soft_time_limit=None,
            max_tasks_per_child=None, queues=None, events=False, db=None,
            include=None, defaults=None, pidfile=None,
            redirect_stdouts=None, redirect_stdouts_level=None, **kwargs):
        if defaults is None:
            from celery import conf
            defaults = conf
        self.defaults = defaults
        self.concurrency = (concurrency or
                            defaults.CELERYD_CONCURRENCY or
                            multiprocessing.cpu_count())
        self.loglevel = loglevel or defaults.CELERYD_LOG_LEVEL
        self.logfile = logfile or defaults.CELERYD_LOG_FILE
        self.hostname = hostname or socket.gethostname()
        self.discard = discard
        self.run_clockservice = run_clockservice
        self.schedule = schedule or defaults.CELERYBEAT_SCHEDULE_FILENAME
        self.events = events
        self.task_time_limit = (task_time_limit or
                                defaults.CELERYD_TASK_TIME_LIMIT)
        self.task_soft_time_limit = (task_soft_time_limit or
                                     defaults.CELERYD_TASK_SOFT_TIME_LIMIT)
        self.max_tasks_per_child = (max_tasks_per_child or
                                    defaults.CELERYD_MAX_TASKS_PER_CHILD)
        self.redirect_stdouts = (redirect_stdouts or
                                 defaults.REDIRECT_STDOUTS)
        self.redirect_stdouts_level = (redirect_stdouts_level or
                                       defaults.REDIRECT_STDOUTS_LEVEL)
        self.db = db
        self.queues = queues or []
        self.include = include or []
        self.pidfile = pidfile
        self._isatty = sys.stdout.isatty()
        self.colored = term.colored(enabled=defaults.CELERYD_LOG_COLOR)

        if isinstance(self.queues, basestring):
            self.queues = self.queues.split(",")
        if isinstance(self.include, basestring):
            self.include = self.include.split(",")

        if not isinstance(self.loglevel, int):
            try:
                self.loglevel = LOG_LEVELS[self.loglevel.upper()]
            except KeyError:
                self.die("Unknown level %r. Please use one of %s." % (
                            self.loglevel,
                            "|".join(l for l in LOG_LEVELS.keys()
                                        if isinstance(l, basestring))))
Beispiel #28
0
 def __init__(self,
              addrport='',
              id=None,
              loglevel=logging.INFO,
              logfile=None,
              without_httpd=False,
              numc=2,
              sup_interval=None,
              ready_event=None,
              colored=None,
              **kwargs):
     self.id = id or gen_unique_id()
     if isinstance(addrport, basestring):
         addr, _, port = addrport.partition(':')
         addrport = (addr, int(port) if port else 8000)
     self.addrport = addrport
     self.connection = celery.broker_connection()
     self.without_httpd = without_httpd
     self.logfile = logfile
     self.loglevel = loglevel
     self.numc = numc
     self.ready_event = ready_event
     self.exit_request = Event()
     self.colored = colored or term.colored(enabled=False)
     self.httpd = None
     gSup = find_symbol(self, self.intsup_cls)
     if not self.without_httpd:
         self.httpd = MockSup(instantiate(self, self.httpd_cls, addrport),
                              signals.httpd_ready)
     self.supervisor = gSup(
         instantiate(self, self.supervisor_cls, sup_interval),
         signals.supervisor_ready)
     self.controllers = [
         gSup(
             instantiate(self,
                         self.controller_cls,
                         id='%s.%s' % (self.id, i),
                         connection=self.connection,
                         branch=self), signals.controller_ready)
         for i in xrange(1, numc + 1)
     ]
     c = [self.supervisor] + self.controllers + [self.httpd]
     c = self.components = list(filter(None, c))
     self._components_ready = dict(
         zip([z.thread for z in c], [False] * len(c)))
     for controller in self.controllers:
         if hasattr(controller.thread, 'presence'):
             self._components_ready[controller.thread.presence] = False
     self._components_shutdown = dict(self._components_ready)
     super(Branch, self).__init__()
Beispiel #29
0
 def __init__(self, app,
              block_timeout=30 * 60, no_color=False,
              stdout=None, stderr=None):
     self.app = app
     self.stdout = sys.stdout if stdout is None else stdout
     self.stderr = sys.stderr if stderr is None else stderr
     if not isatty(self.stdout):
         no_color = True
     self.colored = colored(enabled=not no_color)
     self.connerrors = self.app.connection().recoverable_connection_errors
     self.block_timeout = block_timeout
     self.progress = None
     self.speaker = Speaker(file=self.stdout)
     self.fbi = FBI(app)
     self.init_groups()
Beispiel #30
0
    def format(self, record):
        levelname = record.levelname

        if self.use_color and levelname in COLORS:
            record.msg = unicode(colored().names[COLORS[levelname]](record.msg))

        # Very ugly, but have to make sure processName is supported
        # by foreign logger instances.
        # (processName is always supported by Python 2.7)
        if "processName" not in record.__dict__:
            record.__dict__["processName"] = current_process()._name
        t = logging.Formatter.format(self, record)
        if type(t) in [types.UnicodeType]:
            t = t.encode('utf-8', 'replace')
        return t
Beispiel #31
0
    def format(self, record):
        levelname = record.levelname

        if self.use_color and levelname in COLORS:
            record.msg = unicode(colored().names[COLORS[levelname]](
                record.msg))

        # Very ugly, but have to make sure processName is supported
        # by foreign logger instances.
        # (processName is always supported by Python 2.7)
        if "processName" not in record.__dict__:
            record.__dict__["processName"] = current_process()._name
        t = logging.Formatter.format(self, record)
        if type(t) in [types.UnicodeType]:
            t = t.encode('utf-8', 'replace')
        return t
Beispiel #32
0
 def __init__(self, app=None, get_app=None, no_color=False,
              stdout=None, stderr=None, quiet=False, on_error=None,
              on_usage_error=None):
     self.app = app
     self.get_app = get_app or self._get_default_app
     self.stdout = stdout or sys.stdout
     self.stderr = stderr or sys.stderr
     self.no_color = no_color
     self.colored = term.colored(enabled=not self.no_color)
     self.quiet = quiet
     if not self.description:
         self.description = self.__doc__
     if on_error:
         self.on_error = on_error
     if on_usage_error:
         self.on_usage_error = on_usage_error
Beispiel #33
0
 def __init__(self,
              app,
              block_timeout=30 * 60,
              no_color=False,
              stdout=None,
              stderr=None):
     self.app = app
     self.stdout = sys.stdout if stdout is None else stdout
     self.stderr = sys.stderr if stderr is None else stderr
     if not isatty(self.stdout):
         no_color = True
     self.colored = colored(enabled=not no_color)
     self.connerrors = self.app.connection().recoverable_connection_errors
     self.block_timeout = block_timeout
     self.progress = None
     self.speaker = Speaker(file=self.stdout)
     self.fbi = FBI(app)
     self.init_groups()
Beispiel #34
0
class ExtTaskFormatter(ColorFormatter):
    COLORS = colored().names
    colors = {
        'DEBUG': COLORS['blue'],
        'WARNING': COLORS['yellow'],
        'ERROR': COLORS['red'],
        'CRITICAL': COLORS['magenta']
    }

    def format(self, record):
        task = get_current_task()
        if task and task.request:
            name = task.name.split(u'.')[-1]
            record.__dict__.update(task_id=task.request.id, task_name=name)
        else:
            record.__dict__.update(task_id=u'xxx', task_name=u'xxx')
            #record.__dict__.setdefault('task_name', '???')
            #record.__dict__.setdefault('task_id', '???')
        return ColorFormatter.format(self, record)
Beispiel #35
0
class ColorFormatter(logging.Formatter):
    #: Loglevel -> Color mapping.
    COLORS = colored().names
    colors = {
        "DEBUG": COLORS["blue"],
        "WARNING": COLORS["yellow"],
        "ERROR": COLORS["red"],
        "CRITICAL": COLORS["magenta"]
    }

    def __init__(self, msg, use_color=True):
        logging.Formatter.__init__(self, msg)
        self.use_color = use_color

    def formatException(self, ei):
        r = logging.Formatter.formatException(self, ei)
        if isinstance(r, str):
            return r.decode("utf-8", "replace")  # Convert to unicode
        return r

    def format(self, record):
        levelname = record.levelname
        color = self.colors.get(levelname)

        if self.use_color and color:
            try:
                record.msg = str(color(safe_str(record.msg)))
            except Exception, exc:
                record.msg = "<Unrepresentable %r: %r>" % (type(
                    record.msg), exc)
                record.exc_info = sys.exc_info()

        # Very ugly, but have to make sure processName is supported
        # by foreign logger instances.
        # (processName is always supported by Python 2.7)
        if "processName" not in record.__dict__:
            process_name = current_process and current_process()._name or ""
            record.__dict__["processName"] = process_name
        t = logging.Formatter.format(self, record)
        if isinstance(t, unicode):
            return t.encode("utf-8", "replace")
        return t
Beispiel #36
0
    def __init__(self, loglevel=None, logfile=None, schedule=None,
            max_interval=None, scheduler_cls=None, app=None,
            socket_timeout=30, redirect_stdouts=None,
            redirect_stdouts_level=None, **kwargs):
        """Starts the celerybeat task scheduler."""
        self.app = app = app_or_default(app)

        self.loglevel = loglevel or app.conf.CELERYBEAT_LOG_LEVEL
        self.logfile = logfile or app.conf.CELERYBEAT_LOG_FILE
        self.schedule = schedule or app.conf.CELERYBEAT_SCHEDULE_FILENAME
        self.scheduler_cls = scheduler_cls or app.conf.CELERYBEAT_SCHEDULER
        self.max_interval = max_interval
        self.socket_timeout = socket_timeout
        self.colored = term.colored(enabled=app.conf.CELERYD_LOG_COLOR)
        self.redirect_stdouts = (redirect_stdouts or
                                 app.conf.CELERY_REDIRECT_STDOUTS)
        self.redirect_stdouts_level = (redirect_stdouts_level or
                                       app.conf.CELERY_REDIRECT_STDOUTS_LEVEL)

        if not isinstance(self.loglevel, int):
            self.loglevel = LOG_LEVELS[self.loglevel.upper()]
Beispiel #37
0
 def __init__(self, addrport='', id=None, loglevel=logging.INFO,
         logfile=None, without_httpd=False, numc=2, sup_interval=None,
         ready_event=None, colored=None, **kwargs):
     self.id = id or gen_unique_id()
     if isinstance(addrport, basestring):
         addr, _, port = addrport.partition(':')
         addrport = (addr, int(port) if port else 8000)
     self.addrport = addrport
     self.connection = celery.broker_connection()
     self.without_httpd = without_httpd
     self.logfile = logfile
     self.loglevel = loglevel
     self.numc = numc
     self.ready_event = ready_event
     self.exit_request = Event()
     self.colored = colored or term.colored(enabled=False)
     self.httpd = None
     gSup = find_symbol(self, self.intsup_cls)
     if not self.without_httpd:
         self.httpd = MockSup(instantiate(self, self.httpd_cls, addrport),
                           signals.httpd_ready)
     self.supervisor = gSup(instantiate(self, self.supervisor_cls,
                             sup_interval), signals.supervisor_ready)
     self.controllers = [gSup(instantiate(self, self.controller_cls,
                                id='%s.%s' % (self.id, i),
                                connection=self.connection,
                                branch=self),
                              signals.controller_ready)
                             for i in xrange(1, numc + 1)]
     c = [self.supervisor] + self.controllers + [self.httpd]
     c = self.components = list(filter(None, c))
     self._components_ready = dict(zip([z.thread for z in c],
                                       [False] * len(c)))
     for controller in self.controllers:
         if hasattr(controller.thread, 'presence'):
             self._components_ready[controller.thread.presence] = False
     self._components_shutdown = dict(self._components_ready)
     super(Branch, self).__init__()
Beispiel #38
0
 def colored(self, logfile=None):
     return colored(enabled=self.supports_color(logfile))
Beispiel #39
0
 def __init__(self, app=None, no_color=False):
     self.app = app_or_default(app)
     self.colored = term.colored(enabled=not no_color)
Beispiel #40
0
    def test_colors(self):
        colors = (
            ('black', term.BLACK),
            ('red', term.RED),
            ('green', term.GREEN),
            ('yellow', term.YELLOW),
            ('blue', term.BLUE),
            ('magenta', term.MAGENTA),
            ('cyan', term.CYAN),
            ('white', term.WHITE),
        )

        for name, key in colors:
            self.assertIn(fg(30 + key), str(colored().names[name]('foo')))

        self.assertTrue(str(colored().bold('f')))
        self.assertTrue(str(colored().underline('f')))
        self.assertTrue(str(colored().blink('f')))
        self.assertTrue(str(colored().reverse('f')))
        self.assertTrue(str(colored().bright('f')))
        self.assertTrue(str(colored().ired('f')))
        self.assertTrue(str(colored().igreen('f')))
        self.assertTrue(str(colored().iyellow('f')))
        self.assertTrue(str(colored().iblue('f')))
        self.assertTrue(str(colored().imagenta('f')))
        self.assertTrue(str(colored().icyan('f')))
        self.assertTrue(str(colored().iwhite('f')))
        self.assertTrue(str(colored().reset('f')))

        self.assertTrue(str_t(colored().green(u'∂bar')))

        self.assertTrue(
            colored().red(u'éefoo') + colored().green(u'∂bar'))

        self.assertEqual(
            colored().red('foo').no_color(), 'foo')

        self.assertTrue(
            repr(colored().blue(u'åfoo')))

        self.assertEqual(repr(colored()), "''")

        c = colored()
        s = c.red('foo', c.blue('bar'), c.green('baz'))
        self.assertTrue(s.no_color())

        c._fold_no_color(s, u'øfoo')
        c._fold_no_color(u'fooå', s)

        c = colored().red(u'åfoo')
        self.assertEqual(
            c._add(c, u'baræ'),
            u'\x1b[1;31m\xe5foo\x1b[0mbar\xe6',
        )

        c2 = colored().blue(u'ƒƒz')
        c3 = c._add(c, c2)
        self.assertEqual(
            c3,
            u'\x1b[1;31m\xe5foo\x1b[0m\x1b[1;34m\u0192\u0192z\x1b[0m',
        )
Beispiel #41
0
    def test_colors(self):
        colors = (
            ("black", term.BLACK),
            ("red", term.RED),
            ("green", term.GREEN),
            ("yellow", term.YELLOW),
            ("blue", term.BLUE),
            ("magenta", term.MAGENTA),
            ("cyan", term.CYAN),
            ("white", term.WHITE),
        )

        for name, key in colors:
            self.assertIn(fg(30 + key), str(colored().names[name]("foo")))

        self.assertTrue(str(colored().bold("f")))
        self.assertTrue(str(colored().underline("f")))
        self.assertTrue(str(colored().blink("f")))
        self.assertTrue(str(colored().reverse("f")))
        self.assertTrue(str(colored().bright("f")))
        self.assertTrue(str(colored().ired("f")))
        self.assertTrue(str(colored().igreen("f")))
        self.assertTrue(str(colored().iyellow("f")))
        self.assertTrue(str(colored().iblue("f")))
        self.assertTrue(str(colored().imagenta("f")))
        self.assertTrue(str(colored().icyan("f")))
        self.assertTrue(str(colored().iwhite("f")))
        self.assertTrue(str(colored().reset("f")))

        self.assertTrue(str(colored().green(u"∂bar")))

        self.assertTrue(colored().red(u"éefoo") + colored().green(u"∂bar"))

        self.assertEqual(colored().red("foo").no_color(), "foo")

        self.assertTrue(repr(colored().blue(u"åfoo")))

        self.assertEqual(repr(colored()), "''")

        c = colored()
        s = c.red("foo", c.blue("bar"), c.green("baz"))
        self.assertTrue(s.no_color())

        c._fold_no_color(s, u"øfoo")
        c._fold_no_color(u"fooå", s)

        c = colored().red(u"åfoo")
        self.assertEqual(c._add(c, u"baræ"),
                         u'\x1b[1;31m\xe5foo\x1b[0mbar\xe6')

        c2 = colored().blue(u"ƒƒz")
        c3 = c._add(c, c2)
        self.assertEqual(
            c3, u'\x1b[1;31m\xe5foo\x1b[0m\x1b[1;34m\u0192\u0192z\x1b[0m')
Beispiel #42
0
    def __init__(self,
                 concurrency=None,
                 loglevel=None,
                 logfile=None,
                 hostname=None,
                 discard=False,
                 run_clockservice=False,
                 schedule=None,
                 task_time_limit=None,
                 task_soft_time_limit=None,
                 max_tasks_per_child=None,
                 queues=None,
                 events=False,
                 db=None,
                 include=None,
                 defaults=None,
                 pidfile=None,
                 redirect_stdouts=None,
                 redirect_stdouts_level=None,
                 scheduler_cls=None,
                 **kwargs):
        if defaults is None:
            from celery import conf
            defaults = conf
        self.defaults = defaults
        self.concurrency = (concurrency or defaults.CELERYD_CONCURRENCY
                            or multiprocessing.cpu_count())
        self.loglevel = loglevel or defaults.CELERYD_LOG_LEVEL
        self.logfile = logfile or defaults.CELERYD_LOG_FILE
        self.hostname = hostname or socket.gethostname()
        self.discard = discard
        self.run_clockservice = run_clockservice
        self.schedule = schedule or defaults.CELERYBEAT_SCHEDULE_FILENAME
        self.scheduler_cls = scheduler_cls or defaults.CELERYBEAT_SCHEDULER
        self.events = events
        self.task_time_limit = (task_time_limit
                                or defaults.CELERYD_TASK_TIME_LIMIT)
        self.task_soft_time_limit = (task_soft_time_limit
                                     or defaults.CELERYD_TASK_SOFT_TIME_LIMIT)
        self.max_tasks_per_child = (max_tasks_per_child
                                    or defaults.CELERYD_MAX_TASKS_PER_CHILD)
        self.redirect_stdouts = (redirect_stdouts or defaults.REDIRECT_STDOUTS)
        self.redirect_stdouts_level = (redirect_stdouts_level
                                       or defaults.REDIRECT_STDOUTS_LEVEL)
        self.db = db
        self.queues = queues or []
        self.include = include or []
        self.pidfile = pidfile
        self._isatty = sys.stdout.isatty()
        self.colored = term.colored(enabled=defaults.CELERYD_LOG_COLOR)

        if isinstance(self.queues, basestring):
            self.queues = self.queues.split(",")
        if isinstance(self.include, basestring):
            self.include = self.include.split(",")

        if not isinstance(self.loglevel, int):
            try:
                self.loglevel = LOG_LEVELS[self.loglevel.upper()]
            except KeyError:
                self.die(
                    "Unknown level %r. Please use one of %s." %
                    (self.loglevel, "|".join(l for l in LOG_LEVELS.keys()
                                             if isinstance(l, basestring))))
Beispiel #43
0
###############################################################################

"""
Bindings for tying BPMTask events to callback celery tasks.
"""

from time import time
from functools import wraps

from celery.signals import task_prerun, task_postrun
from celery.datastructures import ExceptionInfo
from celery.utils.term import colored
from celery.log import get_default_logger

logger = get_default_logger()
c = colored()

from ws.tasks import BPMTask


def bpm_only(func):
    """
    Decorator for excluding tasks that don't inherit from ws.tasks.BPMTask
    
    Call a function only when it receives an object inherited from
    :class:`ws.tasks.BPMTask` as it's 'task' argument.
    """
    @wraps(func)
    def wrapper(self, task, *args, **kwargs):
        if isinstance(task, BPMTask):
            return func(self, task=task, *args, **kwargs)
Beispiel #44
0
 def colored(self, logfile=None, enabled=None):
     return colored(enabled=self.supports_color(enabled, logfile))
 def colored(self):
     return term.colored(enabled=not self.no_color)
Beispiel #46
0
 def test_unicode(self):
     assert text_t(colored().green('∂bar'))
     assert colored().red('éefoo') + colored().green('∂bar')
     assert colored().red('foo').no_color() == 'foo'
Beispiel #47
0
 def test_repr(self):
     assert repr(colored().blue('åfoo'))
     assert "''" in repr(colored())
Beispiel #48
0
 def colored(self):
     if self._colored is None:
         self._colored = term.colored(enabled=not self.no_color)
     return self._colored
Beispiel #49
0
 def colored(self):
     return term.colored(enabled=not self.no_color)
Beispiel #50
0
 def colored(self):
     if self._colored is None:
         self._colored = term.colored(
             enabled=isatty(self.stdout) and not self.no_color)
     return self._colored
Beispiel #51
0
 def __init__(self, app=None, no_color=False):
     self.app = app_or_default(app)
     self.colored = term.colored(enabled=not no_color)
Beispiel #52
0
 def test_modifiers(self, name):
     assert str(getattr(colored(), name)('f'))
Beispiel #53
0
 def colored(self):
     if self._colored is None:
         self._colored = term.colored(enabled=not self.no_color)
     return self._colored
Beispiel #54
0
 def test_colors(self, name, color):
     assert fg(30 + color) in str(colored().names[name]('foo'))
Beispiel #55
0
    def test_colors(self):
        colors = (
            ('black', term.BLACK),
            ('red', term.RED),
            ('green', term.GREEN),
            ('yellow', term.YELLOW),
            ('blue', term.BLUE),
            ('magenta', term.MAGENTA),
            ('cyan', term.CYAN),
            ('white', term.WHITE),
        )

        for name, key in colors:
            self.assertIn(fg(30 + key), str(colored().names[name]('foo')))

        self.assertTrue(str(colored().bold('f')))
        self.assertTrue(str(colored().underline('f')))
        self.assertTrue(str(colored().blink('f')))
        self.assertTrue(str(colored().reverse('f')))
        self.assertTrue(str(colored().bright('f')))
        self.assertTrue(str(colored().ired('f')))
        self.assertTrue(str(colored().igreen('f')))
        self.assertTrue(str(colored().iyellow('f')))
        self.assertTrue(str(colored().iblue('f')))
        self.assertTrue(str(colored().imagenta('f')))
        self.assertTrue(str(colored().icyan('f')))
        self.assertTrue(str(colored().iwhite('f')))
        self.assertTrue(str(colored().reset('f')))

        self.assertTrue(text_t(colored().green('∂bar')))

        self.assertTrue(colored().red('éefoo') + colored().green('∂bar'))

        self.assertEqual(colored().red('foo').no_color(), 'foo')

        self.assertTrue(repr(colored().blue('åfoo')))

        self.assertIn("''", repr(colored()))

        c = colored()
        s = c.red('foo', c.blue('bar'), c.green('baz'))
        self.assertTrue(s.no_color())

        c._fold_no_color(s, 'øfoo')
        c._fold_no_color('fooå', s)

        c = colored().red('åfoo')
        self.assertEqual(
            c._add(c, 'baræ'),
            '\x1b[1;31m\xe5foo\x1b[0mbar\xe6',
        )

        c2 = colored().blue('ƒƒz')
        c3 = c._add(c, c2)
        self.assertEqual(
            c3,
            '\x1b[1;31m\xe5foo\x1b[0m\x1b[1;34m\u0192\u0192z\x1b[0m',
        )
Beispiel #56
0
 def __init__(self, no_color=False):
     self.colored = term.colored(enabled=not no_color)