PackageParser

class geojson_modelica_translator.modelica.input_parser.PackageParser(path=None)

Bases: object

Class to read and modify the package.mo and the package.order file

__init__(path=None)

Create an instance to manage the package.mo/order file. If no path is provided then the user must add in their own package and order data. Or the user can load from the new_from_template class method.

Parameters

path – string, path to where the package.mo and package.order reside.

Methods

__init__([path])

Create an instance to manage the package.mo/order file.

add_model(new_model_name[, insert_at])

Insert a new model into the package> Note that the order_data is stored as a string right now, so there is a bit of a hack to get this to work correctly.

load()

Load the package.mo and package.mo data from the member variable path

new_from_template(path, name, order[, within])

Create new package data based on the package.mo template.

rename_model(old_model, new_model)

Rename the model name in the package.order file

save()

Save the updated files to the same location

Attributes

order

Return the order of the packages from the package.order file

add_model(new_model_name, insert_at=- 1)

Insert a new model into the package> Note that the order_data is stored as a string right now, so there is a bit of a hack to get this to work correctly.

Parameters
  • new_model_name – string, name of the new model to add to the package order.

  • insert_at – int, location to insert package, if 0 at beginning, -1 at end

load()

Load the package.mo and package.mo data from the member variable path

classmethod new_from_template(path: Union[str, Path], name: str, order: list[str], within: Optional[str] = None) PackageParser

Create new package data based on the package.mo template. If within is not specified, then it is assumed that this is a top level package and will load from the package_base template.

Parameters
  • path (str) – the path where the resulting package file and order will be saved to.

  • name (str) – the name of the model

  • order (list[str]) – ordered list of which models will be loaded (saved to package.order)

  • within (str, optional) – name where this package is within.. Defaults to None.

Returns

object of the package parser

Return type

PackageParser

property order

Return the order of the packages from the package.order file

Returns

list, list of the loaded models in the package.order file

rename_model(old_model, new_model)

Rename the model name in the package.order file

Parameters
  • old_model – string, existing name

  • new_model – string, new name

save()

Save the updated files to the same location