def check_release_file_exists(): """Check if the release.yaml file exists""" release_file = get_twister2_release_file() # if the file does not exist and is not a file if not os.path.isfile(release_file): Log.error("Required file not found: %s" % release_file) return False return True
def parse_cluster_role_env(cluster_role_env, config_path): """Parse cluster/[role]/[environ], supply default, if not provided, not required""" parts = cluster_role_env.split('/')[:3] Log.info("Using config file under %s" % config_path) if not os.path.isdir(config_path): Log.error("Config path cluster directory does not exist: %s" % config_path) raise Exception("Invalid config path") # if cluster/role/env is not completely provided, check further if len(parts) < 3: cli_conf_file = os.path.join(config_path, CLIENT_YAML) # if client conf doesn't exist, use default value if not os.path.isfile(cli_conf_file): if len(parts) == 1: parts.append(getpass.getuser()) if len(parts) == 2: parts.append(ENVIRON) else: cli_confs = {} with open(cli_conf_file, 'r') as conf_file: tmp_confs = yaml.load(conf_file) # the return value of yaml.load can be None if conf_file is an empty file if tmp_confs is not None: cli_confs = tmp_confs else: print("Failed to read: %s due to it is empty" % (CLIENT_YAML)) # if role is required but not provided, raise exception if len(parts) == 1: if (IS_ROLE_REQUIRED in cli_confs) and (cli_confs[IS_ROLE_REQUIRED] is True): raise Exception("role required but not provided (cluster/role/env = %s). See %s in %s" % (cluster_role_env, IS_ROLE_REQUIRED, CLIENT_YAML)) else: parts.append(getpass.getuser()) # if environ is required but not provided, raise exception if len(parts) == 2: if (IS_ENV_REQUIRED in cli_confs) and (cli_confs[IS_ENV_REQUIRED] is True): raise Exception("environ required but not provided (cluster/role/env = %s). See %s in %s" % (cluster_role_env, IS_ENV_REQUIRED, CLIENT_YAML)) else: parts.append(ENVIRON) # if cluster or role or environ is empty, print if len(parts[0]) == 0 or len(parts[1]) == 0 or len(parts[2]) == 0: print("Failed to parse") sys.exit(1) return (parts[0], parts[1], parts[2])
def check_java_home_set(): """Check if the java home set""" # check if environ variable is set if "JAVA_HOME" not in os.environ: Log.error("JAVA_HOME not set") return False # check if the value set is correct java_path = get_java_path() if os.path.isfile(java_path) and os.access(java_path, os.X_OK): return True Log.error("JAVA_HOME/bin/java either does not exist or not an executable") return False
def run(command, parser, args, unknown_args): ''' :param command: :param parser: :param args: :param unknown_args: :return: ''' # get the command for detailed help command_help = args['help-command'] # if no command is provided, just print main help if command_help == 'help': parser.print_help() return SimpleResult(Status.Ok) # get the subparser for the specific command subparser = config.get_subparser(parser, command_help) if subparser: print subparser.format_help() return SimpleResult(Status.Ok) else: Log.error("Unknown subcommand \'%s\'", command_help) return SimpleResult(Status.InvocationError)