Пример #1
0
def print_elapsed_time_summary(start, end):
    time_needed = end - start
    millis = ((time_needed.days * 24 * 60 * 60) + time_needed.seconds) * \
        1000 + time_needed.microseconds / 1000
    print_text_line("Build finished at %s" % format_timestamp(end))
    print_text_line("Build took %d seconds (%d ms)" %
                    (time_needed.seconds, millis))
def run_single_test(logger, project, reports_dir, test, ):
    name, _ = os.path.splitext(os.path.basename(test))
    logger.info("Running acceptance test %s", name)
    env = prepare_environment(project)
    test_time = Timer.start()
    command_and_arguments = (sys.executable, test)
    report_file_name = os.path.join(reports_dir, name)
    error_file_name = report_file_name + ".err"
    return_code = execute_command(
        command_and_arguments, report_file_name, env, error_file_name=error_file_name)
    test_time.stop()
    report_item = {
        "test": name,
        "test_file": test,
        "time": test_time.get_millis(),
        "success": True
    }
    if return_code != 0:
        logger.error("acceptance test failed: %s", test)
        report_item["success"] = False

        if project.get_property("verbose"):
            print_file_content(report_file_name)
            print_text_line()
            print_file_content(error_file_name)

    return report_item
Пример #3
0
def write_report(name, project, logger, result, console_out):
    project.write_report("%s" % name, console_out)

    report = {"tests-run": result.testsRun,
              "errors": [],
              "failures": []}

    for error in result.errors:
        report["errors"].append({"test": error[0].id(),
                                 "traceback": error[1]})
        logger.error("Test has error: %s", error[0].id())

        if project.get_property("verbose"):
            print_text_line(error[1])

    for failure in result.failures:
        report["failures"].append({"test": failure[0].id(),
                                   "traceback": failure[1]})
        logger.error("Test failed: %s", failure[0].id())

        if project.get_property("verbose"):
            print_text_line(failure[1])

    project.write_report("%s.json" % name, render_report(report))

    report_to_ci_server(project, result)
Пример #4
0
def start_project():
    try:
        scaffolding = collect_project_information()
    except KeyboardInterrupt:
        print_text_line('\nCanceled.')
        return 1

    descriptor = scaffolding.render_build_descriptor()

    with open('build.py', 'w') as build_descriptor_file:
        build_descriptor_file.write(descriptor)

    scaffolding.set_up_project()
    return 0
Пример #5
0
def run_single_test(logger, project, reports_dir, test, output_test_names=True):
    additional_integrationtest_commandline_text = project.get_property("integrationtest_additional_commandline", "")

    if additional_integrationtest_commandline_text:
        additional_integrationtest_commandline = tuple(additional_integrationtest_commandline_text.split(" "))
    else:
        additional_integrationtest_commandline = ()

    name, _ = os.path.splitext(os.path.basename(test))

    if output_test_names:
        logger.info("Running integration test %s", name)

    env = prepare_environment(project)
    test_time = Timer.start()
    command_and_arguments = (sys.executable, test)
    command_and_arguments += additional_integrationtest_commandline

    report_file_name = os.path.join(reports_dir, name)
    error_file_name = report_file_name + ".err"
    return_code = execute_command(
        command_and_arguments, report_file_name, env, error_file_name=error_file_name)
    test_time.stop()
    report_item = {
        "test": name,
        "test_file": test,
        "time": test_time.get_millis(),
        "success": True
    }
    if return_code != 0:
        logger.error("Integration test failed: %s", test)
        report_item["success"] = False

        if project.get_property("verbose") or project.get_property("integrationtest_always_verbose"):
            print_file_content(report_file_name)
            print_text_line()
            print_file_content(error_file_name)
            report_item['exception'] = ''.join(read_file(error_file_name)).replace('\'', '')
    elif project.get_property("integrationtest_always_verbose"):
        print_file_content(report_file_name)
        print_text_line()
        print_file_content(error_file_name)

    return report_item
Пример #6
0
def print_list_of_tasks(reactor, quiet=False):
    tasks = reactor.get_tasks()
    sorted_tasks = sorted(tasks)

    if quiet:
        print_text_line("\n".join([task.name + ":" + task_description(task) for task in sorted_tasks]))
        return

    column_length = length_of_longest_string(list(map(lambda task: task.name, sorted_tasks)))
    column_length += 4

    print_text_line('Tasks found for project "%s":' % reactor.project.name)
    for task in sorted_tasks:
        task_name = task.name.rjust(column_length)
        print_text_line("{0} - {1}".format(task_name, task_description(task)))

        if task.dependencies:
            whitespace = (column_length + 3) * " "
            depends_on_message = "depends on tasks: %s" % " ".join(task.dependencies)
            print_text_line(whitespace + depends_on_message)
Пример #7
0
def print_list_of_tasks(reactor):
    print_text_line('Tasks found for project "%s":' % reactor.project.name)

    tasks = reactor.get_tasks()
    column_length = length_of_longest_string(
        list(map(lambda task: task.name, tasks)))
    column_length += 4

    for task in sorted(tasks):
        task_name = task.name.rjust(column_length)
        task_description = " ".join(
            task.description) or "<no description available>"
        print_text_line("{0} - {1}".format(task_name, task_description))

        if task.dependencies:
            whitespace = (column_length + 3) * " "
            depends_on_message = "depends on tasks: %s" % " ".join(
                task.dependencies)
            print_text_line(whitespace + depends_on_message)
Пример #8
0
def print_task_list(tasks, quiet=False):
    if quiet:
        print_text_line("\n".join([task.name + ":" + task_description(task)
                                   for task in tasks]))
        return

    column_length = length_of_longest_string(
        list(map(lambda task: task.name, tasks)))
    column_length += 4

    for task in tasks:
        task_name = task.name.rjust(column_length)
        print_text_line("{0} - {1}".format(task_name, task_description(task)))

        if task.dependencies:
            whitespace = (column_length + 3) * " "
            depends_on_message = "depends on tasks: %s" % " ".join(
                [str(dependency) for dependency in task.dependencies])
            print_text_line(whitespace + depends_on_message)
Пример #9
0
def print_build_summary(options, summary):
    print_text_line("Build Summary")
    print_text_line("%20s: %s" % ("Project", summary.project.name))
    print_text_line("%20s: %s%s" % ("Version", summary.project.version, get_dist_version_string(summary.project)))
    print_text_line("%20s: %s" % ("Base directory", summary.project.basedir))
    print_text_line("%20s: %s" %
                    ("Environments", ", ".join(options.environments)))

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

    print_text_line("%20s:%s" % ("Tasks", task_summary))
Пример #10
0
def print_elapsed_time_summary(start, end):
    time_needed = end - start
    millis = ((time_needed.days * 24 * 60 * 60) + time_needed.seconds) * 1000 + time_needed.microseconds / 1000
    print_text_line("Build finished at %s" % format_timestamp(end))
    print_text_line("Build took %d seconds (%d ms)" %
                    (time_needed.seconds, millis))
Пример #11
0
 def mark_as_finished(self):
     if self.can_be_displayed:
         print_text_line()
Пример #12
0
 def _do_log(self, level, message, *arguments):
     formatted_message = self._format_message(message, *arguments)
     log_level = self._level_to_string(level)
     print_text_line("{0} {1}".format(log_level, formatted_message))
Пример #13
0
 def _do_log(self, level, message, *arguments):
     formatted_message = self._format_message(message, *arguments)
     log_level = self._level_to_string(level)
     print_text_line("{0} {1}".format(log_level, formatted_message))
Пример #14
0
def print_plan_list_of_tasks(options, arguments, reactor, quiet=False):
    execution_plan = reactor.create_execution_plan(arguments, options.environments)
    if not quiet:
        print_text_line('Tasks that will be executed for project "%s":' % reactor.project.name)
    print_task_list(execution_plan, quiet)
Пример #15
0
def main(*args):
    if not args:
        args = sys.argv[1:]
    try:
        options, arguments = parse_options(args)
    except CommandLineUsageException as e:
        print_error_line("Usage error: %s\n" % e)
        print_error(e.usage)
        return 1

    start = datetime.datetime.now()

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

    if options.start_project:
        return start_project()

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

        print_list_of_tasks(reactor, quiet=options.very_quiet)
        return 0

    if not options.very_quiet:
        print_styled_text_line(
            "PyBuilder version {0}".format(__version__), options, BOLD)
        print_text_line("Build started at %s" % format_timestamp(start))
        draw_line()

    successful = True
    failure_message = None
    summary = None

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

            if options.verbose or options.debug:
                logger.debug("Verbose output enabled.\n")
                reactor.project.set_property("verbose", True)

            summary = reactor.build(
                environments=options.environments, tasks=arguments)

        except KeyboardInterrupt:
            raise PyBuilderException("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)

        if not successful:
            return 1

        return 0
Пример #16
0
def print_build_summary(options, summary):
    print_text_line("Build Summary")
    print_text_line("%20s: %s" % ("Project", summary.project.name))
    print_text_line("%20s: %s" % ("Version", summary.project.version))
    print_text_line("%20s: %s" % ("Base directory", summary.project.basedir))
    print_text_line("%20s: %s" %
                    ("Environments", ", ".join(options.environments)))

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

    print_text_line("%20s:%s" % ("Tasks", task_summary))
Пример #17
0
def print_elapsed_time_summary(start, end):
    time_needed = end - start
    millis = ((time_needed.days * 24 * 60 * 60) + time_needed.seconds) * 1000 + time_needed.microseconds / 1000
    print_text_line("Build finished at {0!s}".format(format_timestamp(end)))
    print_text_line("Build took {0:d} seconds ({1:d} ms)".format(time_needed.seconds, millis))
Пример #18
0
def print_build_summary(options, summary):
    print_text_line("Build Summary")
    print_text_line("{0:20!s}: {1!s}".format("Project", summary.project.name))
    print_text_line("{0:20!s}: {1!s}{2!s}".format("Version", summary.project.version, get_dist_version_string(summary.project)))
    print_text_line("{0:20!s}: {1!s}".format("Base directory", summary.project.basedir))
    print_text_line("{0:20!s}: {1!s}".format("Environments", ", ".join(options.environments)))

    task_summary = ""
    for task in summary.task_summaries:
        task_summary += " {0!s} [{1:d} ms]".format(task.task, task.execution_time)

    print_text_line("{0:20!s}:{1!s}".format("Tasks", task_summary))
Пример #19
0
def _create_setup_file():
    setup_py_file_contents = '''#!/usr/bin/env python
#

#   -*- coding: utf-8 -*-
#
#   This file is part of PyBuilder
#
#   Copyright 2011-2015 PyBuilder Team
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.

#
# This script allows to support installation via:
#   pip install git+git://<project>@<branch>
#
# This script is designed to be used in combination with `pip install` ONLY
#
# DO NOT RUN MANUALLY
#

import os
import subprocess
import sys
import glob
import shutil

from sys import version_info
py3 = version_info[0] == 3
py2 = not py3
if py2:
    FileNotFoundError = OSError


def install_pyb():
    try:
        subprocess.check_call([sys.executable, "-m", "pip.__main__", "install", "pybuilder"])
    except subprocess.CalledProcessError as e:
        sys.exit(e.returncode)


script_dir = os.path.dirname(os.path.realpath(__file__))
exit_code = 0

try:
    subprocess.check_call(["pyb", "--version"])
except FileNotFoundError as e:
    if py3 or py2 and e.errno == 2:
        install_pyb()
    else:
        raise
except subprocess.CalledProcessError as e:
    if e.returncode == 127:
        install_pyb()
    else:
        sys.exit(e.returncode)

try:
    subprocess.check_call(["pyb", "clean", "install_build_dependencies", "package", "-o"])
    dist_dir = glob.glob(os.path.join(script_dir, "target", "dist", "*"))[0]
    for src_file in glob.glob(os.path.join(dist_dir, "*")):
        file_name = os.path.basename(src_file)
        target_file_name = os.path.join(script_dir, file_name)
        if os.path.exists(target_file_name):
            if os.path.isdir(target_file_name):
                shutil.rmtree(target_file_name)
            else:
                os.remove(target_file_name)
        shutil.move(src_file, script_dir)
    setup_args = sys.argv[1:]
    subprocess.check_call([sys.executable, "setup.py"] + setup_args, cwd=script_dir)
except subprocess.CalledProcessError as e:
    exit_code = e.returncode
sys.exit(exit_code)
'''
    if os.path.exists("setup.py"):
        choice = prompt_user("Overwrite 'setup.py' (y/N)?", 'n')
        overwrite = not choice or choice.lower() == 'y'
        if not overwrite:
            return
        os.unlink("setup.py")
    with open('setup.py', 'w') as setup_descriptor_file:
        setup_descriptor_file.write(setup_py_file_contents)
    print_text_line("\nCreated 'setup.py'.")
Пример #20
0
def print_list_of_tasks(reactor, quiet=False):
    tasks = reactor.get_tasks()
    sorted_tasks = sorted(tasks)
    if not quiet:
        print_text_line('Tasks found for project "%s":' % reactor.project.name)
    print_task_list(sorted_tasks, quiet)
Пример #21
0
def _create_setup_file():
    setup_py_file_contents = '''#!/usr/bin/env python
#

#   -*- coding: utf-8 -*-
#
#   This file is part of PyBuilder
#
#   Copyright 2011-2015 PyBuilder Team
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.

#
# This script allows to support installation via:
#   pip install git+git://<project>@<branch>
#
# This script is designed to be used in combination with `pip install` ONLY
#
# DO NOT RUN MANUALLY
#

import os
import subprocess
import sys
import glob
import shutil

from sys import version_info
py3 = version_info[0] == 3
py2 = not py3
if py2:
    FileNotFoundError = OSError


def install_pyb():
    try:
        subprocess.check_call([sys.executable, "-m", "pip.__main__", "install", "pybuilder"])
    except subprocess.CalledProcessError as e:
        sys.exit(e.returncode)


script_dir = os.path.dirname(os.path.realpath(__file__))
exit_code = 0

try:
    subprocess.check_call(["pyb", "--version"])
except FileNotFoundError as e:
    if py3 or py2 and e.errno == 2:
        install_pyb()
    else:
        raise
except subprocess.CalledProcessError as e:
    if e.returncode == 127:
        install_pyb()
    else:
        sys.exit(e.returncode)

try:
    subprocess.check_call(["pyb", "clean", "install_build_dependencies", "package", "-o"])
    dist_dir = glob.glob(os.path.join(script_dir, "target", "dist", "*"))[0]
    for src_file in glob.glob(os.path.join(dist_dir, "*")):
        file_name = os.path.basename(src_file)
        target_file_name = os.path.join(script_dir, file_name)
        if os.path.exists(target_file_name):
            if os.path.isdir(target_file_name):
                shutil.rmtree(target_file_name)
            else:
                os.remove(target_file_name)
        shutil.move(src_file, script_dir)
    setup_args = sys.argv[1:]
    subprocess.check_call([sys.executable, "setup.py"] + setup_args, cwd=script_dir)
except subprocess.CalledProcessError as e:
    exit_code = e.returncode
sys.exit(exit_code)
'''
    if os.path.exists("setup.py"):
        choice = prompt_user("Overwrite 'setup.py' (y/N)?", 'n')
        overwrite = not choice or choice.lower() == 'y'
        if not overwrite:
            return
        os.unlink("setup.py")
    with open('setup.py', 'w') as setup_descriptor_file:
        setup_descriptor_file.write(setup_py_file_contents)
    print_text_line("\nCreated 'setup.py'.")
Пример #22
0
def main(*args):
    if not args:
        args = sys.argv[1:]
    try:
        options, arguments = parse_options(args)
    except CommandLineUsageException as e:
        print_error_line("Usage error: %s\n" % e)
        print_error(e.usage)
        return 1

    start = datetime.datetime.now()

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

    if options.start_project:
        return start_project()

    if options.update_project:
        return update_project()

    if options.list_tasks or options.list_plan_tasks:
        try:
            reactor.prepare_build(property_overrides=options.property_overrides,
                                  project_directory=options.project_directory,
                                  exclude_optional_tasks=options.exclude_optional_tasks,
                                  exclude_tasks=options.exclude_tasks,
                                  exclude_all_optional=options.exclude_all_optional
                                  )
            if options.list_tasks:
                print_list_of_tasks(reactor, quiet=options.very_quiet)

            if options.list_plan_tasks:
                print_plan_list_of_tasks(options, arguments, reactor, quiet=options.very_quiet)
            return 0
        except PyBuilderException as e:
            print_build_status(str(e), options, successful=False)
            return 1

    if not options.very_quiet:
        print_styled_text_line(
            "PyBuilder version {0}".format(__version__), options, BOLD)
        print_text_line("Build started at %s" % format_timestamp(start))
        draw_line()

    successful = True
    failure_message = None
    summary = None

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

            if options.verbose or options.debug:
                logger.debug("Verbose output enabled.\n")
                reactor.project.set_property("verbose", True)

            summary = reactor.build(
                environments=options.environments, tasks=arguments)

        except KeyboardInterrupt:
            raise PyBuilderException("Build aborted")

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

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

        if not successful:
            return 1

        return 0
Пример #23
0
def print_list_of_tasks(reactor, quiet=False):
    tasks = reactor.get_tasks()
    sorted_tasks = sorted(tasks)
    if not quiet:
        print_text_line('Tasks found for project "%s":' % reactor.project.name)
    print_task_list(sorted_tasks, quiet)
Пример #24
0
def run_single_test(logger,
                    project,
                    reactor,
                    reports_dir,
                    test,
                    output_test_names=True):
    additional_integrationtest_commandline_text = project.get_property(
        "integrationtest_additional_commandline")

    if additional_integrationtest_commandline_text:
        additional_integrationtest_commandline = tuple(
            additional_integrationtest_commandline_text.split(" "))
    else:
        additional_integrationtest_commandline = ()

    name, _ = os.path.splitext(os.path.basename(test))

    if output_test_names:
        logger.info("Running integration test %s", name)

    python_env = reactor.python_env_registry[project.get_property(
        "integrationtest_python_env")]
    env = prepare_environment(project)
    command_and_arguments = python_env.executable + [test]
    command_and_arguments += additional_integrationtest_commandline

    report_file_name = os.path.join(reports_dir, name)
    error_file_name = report_file_name + ".err"

    test_time = Timer.start()
    return_code = python_env.execute_command(
        command_and_arguments,
        report_file_name,
        env,
        error_file_name=error_file_name,
        inherit_env=project.get_property(
            "integrationtest_inherit_environment"))
    test_time.stop()
    report_item = {
        "test": name,
        "test_file": test,
        "time": test_time.get_millis(),
        "success": True
    }
    if return_code != 0:
        logger.error("Integration test failed: %s, exit code %d", test,
                     return_code)
        report_item["success"] = False

        if project.get_property("verbose") or project.get_property(
                "integrationtest_always_verbose"):
            print_file_content(report_file_name)
            print_text_line()
            print_file_content(error_file_name)
            report_item["exception"] = ''.join(
                read_file(error_file_name)).replace('\'', '')
    elif project.get_property("integrationtest_always_verbose"):
        print_file_content(report_file_name)
        print_text_line()
        print_file_content(error_file_name)

    return report_item
 def mark_as_finished(self):
     if self.can_be_displayed:
         print_text_line()