Example #1
0
def print_summary (successful, summary, start, end, options, failure_message):
    sys.stdout.write("\n")
    drawLine()
    if successful:
        msg = "BUILD SUCCESSFUL\n"
        if should_colorize(options):
            msg = styled_text(msg, BOLD, fg(GREEN))
    else:
        msg = "BUILD FAILED - %s\n" % failure_message
        if should_colorize(options):
            msg = styled_text(msg, BOLD, fg(RED))
    sys.stdout.write(msg)
    drawLine()

    if successful and summary:
        sys.stdout.write("Build Summary\n")
        sys.stdout.write("%20s: %s\n" % ("Project", summary.project.name))
        sys.stdout.write("%20s: %s\n" % ("Version", summary.project.version))
        sys.stdout.write("%20s: %s\n" % ("Base directory", summary.project.basedir))
        sys.stdout.write("%20s: %s\n" % ("Environments", ", ".join(options.environments)))

        task_summary = ""
        for task in summary.task_summaries:
            task_summary += " %s [%d ms]" % (task.task, task.execution_time)

        sys.stdout.write("%20s:%s\n" % ("Tasks", task_summary))

    time_needed = end - start
    millis = ((time_needed.days * 24 * 60 * 60) + time_needed.seconds) * 1000 + time_needed.microseconds / 1000

    sys.stdout.write("Build finished at %s\n" % format_timestamp(end))
    sys.stdout.write("Build took %d seconds (%d ms)\n" % (time_needed.seconds, millis))
Example #2
0
def main(*args):
    try:
        options, arguments = parse_options(args)
    except CommandLineUsageException as e:
        sys.stderr.write("Usage error: %s\n" % e)
        sys.stderr.write(e.usage)
        return 1

    start = datetime.datetime.now()

    logger = init_logger(options)
    reactor = init_reactor(logger)

    if options.list_tasks:
        reactor.prepare_build(property_overrides=options.property_overrides,
            project_directory=options.project_directory)

        sys.stdout.write("Tasks found in %s building in %s:\n\n" % (reactor.project.name, reactor.project.basedir))
        for task in sorted(reactor.get_tasks()):
            sys.stdout.write("%20s\t%s\n" % (task.name,
                                             " ".join(task.description) or "<no description available>"))
            if task.dependencies:
                sys.stdout.write("\t\t\tdepends on tasks: %s\n" % " ".join(task.dependencies))
            sys.stdout.write("\n")
        return 0

    banner = "PYTHON BUILDER Version %s\n" % VERSION
    if should_colorize(options):
        banner = bold(banner)

    if not options.very_quiet:
        sys.stdout.write(banner)
        sys.stdout.write("Build started at %s\n" % format_timestamp(start))
        sys.stdout.write(("-" * 60) + "\n\n")

    successful = True
    failure_message = None
    summary = None

    try:
        try:
            reactor.prepare_build(property_overrides=options.property_overrides,
                project_directory=options.project_directory)

            if options.list_tasks:
                for task in sorted(reactor.get_tasks()):
                    sys.stdout.write("%20s\t%s\n" % (task.name,
                                                     task.description or "<no description available>"))
                    if task.dependencies:
                        sys.stdout.write("\t\t\tdepends on tasks: %s\n" % " ".join(task.dependencies))
                    sys.stdout.write("\n")
            else:
                summary = reactor.build(environments=options.environments, tasks=arguments)
        except KeyboardInterrupt:
            raise PythonbuilderException("Build aborted")

    except Exception as e:
        failure_message = str(e)
        if options.debug:
            traceback.print_exc(file=sys.stderr)
        successful = False

    finally:
        end = datetime.datetime.now()
        if not options.very_quiet:
            print_summary(successful, summary, start, end, options, failure_message)

        return 0 if successful else 1
Example #3
0
 def test_should_format_timestamp (self):
     self.assert_matches(r"^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$", 
                         format_timestamp(datetime.datetime.now()))