.. _ref_asset: Assets ====== .. currentmodule:: ansys.scadeone.core.assets - An Asset represents a unit of data managed by the project. - Assets link a Job's inputs and outputs to physical resources such as files or folders. - The lifecycle of an Asset is tied to its parent Job: when a Job is deleted, all Assets it generated are automatically removed. The table lists the assets, the jobs using the asset, its kind (file, folder), its location with respect to the project folder: ======================= ================================== ==================== ======================= Asset Job Kind Location ======================= ================================== ==================== ======================= Swan body module CodeGeneration(in), ModelCheck(in) .swan file 'assets' project folder Swan test module Simulation(in), TestExecution(in) .swant file 'assets' project folder Swan interface module None .swani file 'assets' project folder Generated C code CodeGeneration(out) out/code folder Job folder Mapping Info CodeGeneration(out) out/cg_map.json Job folder Test results TestExecution(out) out/testResults.json Job folder Trace Simulation(out) out/trace.sd Job folder ======================= ================================== ==================== ======================= - :py:class:`ModuleBodyAsset`, :py:class:`ModuleInterfaceAsset` and :py:class:`TestModuleAsset` are Swan module assets that represent the Swan files used as input of the Jobs. - :py:class:`SimulationDataAsset`, :py:class:`GeneratedCodeAsset`, :py:class:`CGMappingAsset` and :py:class:`TestResultsAsset` are output assets that represent the files generated by the Jobs. Example ------- The following example shows how to retrieve assets from a project, open them, and access their producer or consumer jobs. .. code:: python from ansys.scadeone.core import ScadeOne import ansys.scadeone.core.assets as assets from ansys.scadeone.core.svc.simdata import FileBase # Initialize Scade One application and load a project s_one_install = "C:/Scade One" app = ScadeOne(install_dir=s_one_install) # Load project with a path given by sproj_path project = app.load_project(sproj_path) # Access an asset (module body) with its name given and inspect jobs consuming it module_asset = next( a for a in project.assets if isinstance(a, assets.ModuleBodyAsset) and str(a.path) == "assets\\testBodyModule.swan" ) # Open the asset module = module_asset.open() # swan.ModuleBody # Get consumer jobs of the asset consumers = module_asset.consumer_jobs # Access an output asset (simulation trace) with its name SimulationJob1, run its producer job and open it sim_asset = next( a for a in project.assets if isinstance(a, assets.SimulationDataAsset) and str(a.job_name) == "SimulationJob1" ) # Get the producer job of the asset producer = sim_asset.producer_job # Launch the producer job to generate the trace file. result = producer.run() if result.code == 0: # Open the asset trace = sim_asset.open() assert isinstance(trace, FileBase) # Delete job and its output assets project.delete_job(producer) assert project.get_job(producer.name) is None assert sim_asset.producer_job is None Asset base class ----------------- .. currentmodule:: ansys.scadeone.core.assets :py:class:`Asset` is a base class, and it has the following properties: - :py:attr:`Asset.path` is the asset path. - :py:attr:`Asset.job_name` is the job name that is associated with the asset. - :py:attr:`Asset.producer_job` is the job that produces the asset. - :py:attr:`Asset.consumer_jobs` is the list of jobs that consume the asset. and it has the following method: - The :py:meth:`Asset.open` method to open the underlying asset by returning its proper instance. This method must be implemented by its child classes. Asset classes ------------- .. automodule:: ansys.scadeone.core.assets :member-order: bysource