Generalize task status output
This commit is contained in:
@ -1783,158 +1783,3 @@ def format_list_profile(config, profile_data):
|
||||
)
|
||||
|
||||
return "\n".join(profile_list_output)
|
||||
|
||||
|
||||
def format_list_task(config, task_data):
|
||||
if not isinstance(task_data, list):
|
||||
job_state = task_data["state"]
|
||||
if job_state == "RUNNING":
|
||||
retdata = "Job state: RUNNING\nStage: {}/{}\nStatus: {}".format(
|
||||
task_data["current"], task_data["total"], task_data["status"]
|
||||
)
|
||||
elif job_state == "FAILED":
|
||||
retdata = "Job state: FAILED\nStatus: {}".format(task_data["status"])
|
||||
elif job_state == "COMPLETED":
|
||||
retdata = "Job state: COMPLETED\nStatus: {}".format(task_data["status"])
|
||||
else:
|
||||
retdata = "Job state: {}\nStatus: {}".format(
|
||||
task_data["state"], task_data["status"]
|
||||
)
|
||||
return retdata
|
||||
|
||||
task_list_output = []
|
||||
|
||||
# Determine optimal column widths
|
||||
task_id_length = 7
|
||||
task_type_length = 7
|
||||
task_worker_length = 7
|
||||
task_vm_name_length = 5
|
||||
task_vm_profile_length = 8
|
||||
task_vm_define_length = 8
|
||||
task_vm_start_length = 7
|
||||
|
||||
for task in task_data:
|
||||
# task_id column
|
||||
_task_id_length = len(str(task["id"])) + 1
|
||||
if _task_id_length > task_id_length:
|
||||
task_id_length = _task_id_length
|
||||
# task_worker column
|
||||
_task_worker_length = len(str(task["worker"])) + 1
|
||||
if _task_worker_length > task_worker_length:
|
||||
task_worker_length = _task_worker_length
|
||||
# task_type column
|
||||
_task_type_length = len(str(task["type"])) + 1
|
||||
if _task_type_length > task_type_length:
|
||||
task_type_length = _task_type_length
|
||||
# task_vm_name column
|
||||
_task_vm_name_length = len(str(task["vm_name"])) + 1
|
||||
if _task_vm_name_length > task_vm_name_length:
|
||||
task_vm_name_length = _task_vm_name_length
|
||||
# task_vm_profile column
|
||||
_task_vm_profile_length = len(str(task["vm_profile"])) + 1
|
||||
if _task_vm_profile_length > task_vm_profile_length:
|
||||
task_vm_profile_length = _task_vm_profile_length
|
||||
# task_vm_define column
|
||||
_task_vm_define_length = len(str(task["vm_define"])) + 1
|
||||
if _task_vm_define_length > task_vm_define_length:
|
||||
task_vm_define_length = _task_vm_define_length
|
||||
# task_vm_start column
|
||||
_task_vm_start_length = len(str(task["vm_start"])) + 1
|
||||
if _task_vm_start_length > task_vm_start_length:
|
||||
task_vm_start_length = _task_vm_start_length
|
||||
|
||||
# Format the string (header)
|
||||
task_list_output.append(
|
||||
"{bold}{task_header: <{task_header_length}} {vms_header: <{vms_header_length}}{end_bold}".format(
|
||||
bold=ansiprint.bold(),
|
||||
end_bold=ansiprint.end(),
|
||||
task_header_length=task_id_length
|
||||
+ task_type_length
|
||||
+ task_worker_length
|
||||
+ 2,
|
||||
vms_header_length=task_vm_name_length
|
||||
+ task_vm_profile_length
|
||||
+ task_vm_define_length
|
||||
+ task_vm_start_length
|
||||
+ 3,
|
||||
task_header="Tasks "
|
||||
+ "".join(
|
||||
[
|
||||
"-"
|
||||
for _ in range(
|
||||
6, task_id_length + task_type_length + task_worker_length + 1
|
||||
)
|
||||
]
|
||||
),
|
||||
vms_header="VM Details "
|
||||
+ "".join(
|
||||
[
|
||||
"-"
|
||||
for _ in range(
|
||||
11,
|
||||
task_vm_name_length
|
||||
+ task_vm_profile_length
|
||||
+ task_vm_define_length
|
||||
+ task_vm_start_length
|
||||
+ 2,
|
||||
)
|
||||
]
|
||||
),
|
||||
)
|
||||
)
|
||||
|
||||
task_list_output.append(
|
||||
"{bold}{task_id: <{task_id_length}} {task_type: <{task_type_length}} \
|
||||
{task_worker: <{task_worker_length}} \
|
||||
{task_vm_name: <{task_vm_name_length}} \
|
||||
{task_vm_profile: <{task_vm_profile_length}} \
|
||||
{task_vm_define: <{task_vm_define_length}} \
|
||||
{task_vm_start: <{task_vm_start_length}}{end_bold}".format(
|
||||
task_id_length=task_id_length,
|
||||
task_type_length=task_type_length,
|
||||
task_worker_length=task_worker_length,
|
||||
task_vm_name_length=task_vm_name_length,
|
||||
task_vm_profile_length=task_vm_profile_length,
|
||||
task_vm_define_length=task_vm_define_length,
|
||||
task_vm_start_length=task_vm_start_length,
|
||||
bold=ansiprint.bold(),
|
||||
end_bold=ansiprint.end(),
|
||||
task_id="Job ID",
|
||||
task_type="Status",
|
||||
task_worker="Worker",
|
||||
task_vm_name="Name",
|
||||
task_vm_profile="Profile",
|
||||
task_vm_define="Define?",
|
||||
task_vm_start="Start?",
|
||||
)
|
||||
)
|
||||
|
||||
# Format the string (elements)
|
||||
for task in sorted(task_data, key=lambda i: i.get("type", None)):
|
||||
task_list_output.append(
|
||||
"{bold}{task_id: <{task_id_length}} {task_type: <{task_type_length}} \
|
||||
{task_worker: <{task_worker_length}} \
|
||||
{task_vm_name: <{task_vm_name_length}} \
|
||||
{task_vm_profile: <{task_vm_profile_length}} \
|
||||
{task_vm_define: <{task_vm_define_length}} \
|
||||
{task_vm_start: <{task_vm_start_length}}{end_bold}".format(
|
||||
task_id_length=task_id_length,
|
||||
task_type_length=task_type_length,
|
||||
task_worker_length=task_worker_length,
|
||||
task_vm_name_length=task_vm_name_length,
|
||||
task_vm_profile_length=task_vm_profile_length,
|
||||
task_vm_define_length=task_vm_define_length,
|
||||
task_vm_start_length=task_vm_start_length,
|
||||
bold="",
|
||||
end_bold="",
|
||||
task_id=task["id"],
|
||||
task_type=task["type"],
|
||||
task_worker=task["worker"],
|
||||
task_vm_name=task["vm_name"],
|
||||
task_vm_profile=task["vm_profile"],
|
||||
task_vm_define=task["vm_define"],
|
||||
task_vm_start=task["vm_start"],
|
||||
)
|
||||
)
|
||||
|
||||
return "\n".join(task_list_output)
|
||||
|
Reference in New Issue
Block a user