コード例 #1
0
ファイル: commands.py プロジェクト: rkhmelyuk/twister
def print_failed_command_output(e):
    if e.output:
        log.info("Command output:")
        for line in str(e.output).splitlines():
            line_lower = line.lower()
            if "error" in line_lower or "failure" in line_lower:
                line = log.RED + line + log.END
            if "success" in line_lower:
                line = log.GREEN + line + log.END
            print("   " + log.GRAY + line + log.END)
コード例 #2
0
ファイル: twister.py プロジェクト: retoter/twister
def get_twister_args(args=sys.argv[1:]):
    module_name = None
    command_name = None
    command_args = []

    # read module and command
    if len(args) == 1:
        command_name = args[0]
        command_args = []
    elif len(args) >= 2:
        module_name = args[0]
        command_name = args[1]
        command_args = args[2:]

    # -- handle the case when we have only parameters or command + parameter
    if module_name and module_name.startswith("--"):
        module_name = None
    if command_name and command_name.startswith("--"):
        command_name = module_name
        module_name = None
        command_args = args[1:]

    # -- if module name is incorrect, this might be a command..
    if module_name and module_name not in list_modules():
        command_name = module_name
        command_args = args[1:]
        module_name = None

    # -- handle the aliases
    if not module_name:
        aliases = load_aliases()
        if command_name in aliases.keys():
            log.info("Using alias '%s' => '%s'" % (command_name, aliases[command_name]))
            alias_parts = re.split("\s+", aliases[command_name])
            alias_args, command_name, module_name = get_twister_args(alias_parts)
            # sum up alias args and command args
            command_args = alias_args + command_args

    return command_args, command_name, module_name
コード例 #3
0
ファイル: command.py プロジェクト: retoter/twister
def build_command_context(command, args):
    parser = argparse.ArgumentParser(add_help=False)
    parser.add_argument(TWISTED_PATH_ARG)
    parser.add_argument(PROJECT_PATH_ARG)
    parser.add_argument("--verbose", action="store_true")

    parsed_args, unknown = parser.parse_known_args()

    # use use-project-path and use-twisted-path to specify value, but remove from parsed args
    project_path = parsed_args.use_project_path
    twisted_path = parsed_args.use_twisted_path

    twister_directory = get_twister_directory()
    if not project_path:
        # use the $PROJECT_PATH env var
        project_path = os.environ.get('PROJECT_PATH')
    if not project_path:
        # the default one is parent directory
        project_path = os.path.dirname(twister_directory)

    if not twisted_path:
        # use the $TWISTED_PATH env var
        twisted_path = os.environ.get("TWISTED_PATH")
    if not twisted_path:
        # the default one is twisted directory in parent directory
        twisted_path = os.path.join(os.path.dirname(twister_directory), "twisted")

    if not os.path.exists(twisted_path):
        os.mkdir(twisted_path)
        print "Created twisted directory: %s" % twisted_path
    elif not os.path.isdir(twisted_path):
        print "%s is not directory" % twisted_path
        exit(-1)

    if parsed_args.verbose:
        log.info("Detected command: %s" % str(command))
        log.info("Use project at %s" % project_path)
        log.info("Use twisted at %s" % twisted_path)

    command_args = get_command_arguments(args)
    parsed_args = command.get_arg_parser().parse_args(command_args)

    return Context(command=command, twisted_path=twisted_path, project_path=project_path, args=parsed_args)