Beispiel #1
0
def generate_tasks_manual():
    """ Return a formatted listing of all tasks with their descriptions. """
    from siskin.sources import *
    from siskin.workflows import *

    output = StringIO.StringIO()
    # task_tuples = sorted(Register.get_reg().iteritems())
    task_names = Register.task_names()
    output.write(MAN_HEADER)
    output.write('  {0} tasks found\n\n'.format(len(task_names)))

    for name in task_names:
        klass = Register.get_task_cls(name)
        doc = klass.__doc__ or colors.red("@todo: docs")
        output.write('{0} {1}\n'.format(colors.green(name), doc))

        try:
            deps = flatten(klass().requires())
        except Exception:
            # TODO: tasks that have required arguments will fail here
            formatted = colors.yellow("\tUnavailable since task has required parameters.")
        else:
            formatted = '\t{0}'.format(pprint.pformat(deps).replace('\n', '\n\t'))
        output.write(colors.magenta('\n\tDependencies ({0}):\n\n{1}\n\n'.format(len(deps), formatted)))

    return output.getvalue()
Beispiel #2
0
    def _timed(*args, **kwargs):
        """ Benchmark decorator. """
        with Timer() as timer:
            result = method(*args, **kwargs)
        klass = args[0].__class__.__name__
        fun = method.__name__

        msg = '[%s.%s] %0.5f' % (klass, fun, timer.elapsed_s)
        if timer.elapsed_s <= timer.green:
            logger.debug(green(msg))
        elif timer.elapsed_s <= timer.yellow:
            logger.debug(yellow(msg))
        else:
            logger.debug(red(msg))
        return result
Beispiel #3
0
    def _timed(*args, **kwargs):
        """ Benchmark decorator. """
        with Timer() as timer:
            result = method(*args, **kwargs)
        klass = args[0].__class__.__name__
        fun = method.__name__

        msg = '[%s.%s] %0.5f' % (klass, fun, timer.elapsed_s)
        if timer.elapsed_s <= timer.green:
            logger.debug(green(msg))
        elif timer.elapsed_s <= timer.yellow:
            logger.debug(yellow(msg))
        else:
            logger.debug(red(msg))
        return result
Beispiel #4
0
    def decorator(*args, **kwargs):
        """ Benchmark decorator. """
        with Timer() as timer:
            result = method(*args, **kwargs)

        module = args[0].__module__
        klass = args[0].__class__.__name__
        fun = method.__name__

        key = '{0}.{1}.{2}'.format(module, klass, fun)
        value = timer.elapsed_s
        # just a quick visual impression, everything that takes more
        # than 10s is yellow, more then 1min, red.
        status = 'green'
        if value > 10:
            status = 'yellow'
        if value > 60:
            status = 'red'

        if not os.path.exists(os.path.dirname(path)):
            os.makedirs(os.path.dirname(path))
        with sqlite3db(path) as cursor:
            cursor.execute("""
                CREATE TABLE IF NOT EXISTS
                t (key TEXT, value REAL, date TEXT, status TEXT)
            """)
            cursor.execute(
                """
                INSERT INTO t (key, value, date, status)
                VALUES (?, ?, datetime('now'), ?)
            """, (key, value, status))

        if log is True:
            msg = '[%s.%s] %0.5f' % (klass, fun, timer.elapsed_s)
            if timer.elapsed_s <= timer.green:
                logger.debug(green(msg))
            elif timer.elapsed_s <= timer.yellow:
                logger.debug(yellow(msg))
            else:
                logger.debug(red(msg))

        return result
Beispiel #5
0
    def decorator(*args, **kwargs):
        """ Benchmark decorator. """
        with Timer() as timer:
            result = method(*args, **kwargs)

        module = args[0].__module__
        klass = args[0].__class__.__name__
        fun = method.__name__

        key = '{0}.{1}.{2}'.format(module, klass, fun)
        value = timer.elapsed_s
        # just a quick visual impression, everything that takes more
        # than 10s is yellow, more then 1min, red.
        status = 'green'
        if value > 10:
            status = 'yellow'
        if value > 60:
            status = 'red'

        if not os.path.exists(os.path.dirname(path)):
            os.makedirs(os.path.dirname(path))
        with sqlite3db(path) as cursor:
            cursor.execute("""
                CREATE TABLE IF NOT EXISTS
                t (key TEXT, value REAL, date TEXT, status TEXT)
            """)
            cursor.execute("""
                INSERT INTO t (key, value, date, status)
                VALUES (?, ?, datetime('now'), ?)
            """, (key, value, status))

        if log is True:
            msg = '[%s.%s] %0.5f' % (klass, fun, timer.elapsed_s)
            if timer.elapsed_s <= timer.green:
                logger.debug(green(msg))
            elif timer.elapsed_s <= timer.yellow:
                logger.debug(yellow(msg))
            else:
                logger.debug(red(msg))

        return result