Skip to content

Add example to the user guide: how to list a job's files #343

@FedericoNegri

Description

@FedericoNegri

Example script

import humanize
from tabulate import tabulate

from ansys.hps.client import Client, ProjectApi

project_id = "02vna3Aap8ZEkykK0j52Uj"
job_id = "02vna3DVqDW2CgQrRe3X34"
cl = Client(
    url="https://localhost:8443/hps",
    username="repuser",
    password="repuser",
    verify=False
)

project_api = ProjectApi(cl, project_id)

job = project_api.get_jobs(id=[job_id], fields=["id", "file_ids"])[0]
query_params = {"id": job.file_ids, "hash.ne": "null"}
files = project_api.get_files(**query_params)

table_data = [['Name', 'Path', 'Size',  'Last Modified']]
table_data.extend(
    [[
        f.name,
        f.evaluation_path,
        humanize.naturalsize(f.size),
        humanize.naturaltime(f.modification_time)
    ] for f in files]
)
print(tabulate(table_data, headers="firstrow"))

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions