-
Notifications
You must be signed in to change notification settings - Fork 1
Add adapter to write/read AASX packages #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
somsonson
wants to merge
474
commits into
eclipse-basyx:main
Choose a base branch
from
rwth-iat:copy_aasx
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
474 commits
Select commit
Hold shift + click to select a range
8866d8e
adapter.http: fixing post submodelelement route
Frosty2500 0d41fa4
adapter.http: implement the recommended changes
Frosty2500 33725b0
adapter.http: implement the new recommended changes
Frosty2500 864c7ca
adapter.http: hardcode `utf-8` for XML serialization
jkhsjdhjs cfa775f
adapter.http: change `base64url_encode()` function to return `str`
jkhsjdhjs 7e61895
adapter.http: update AAS submodel refs path
jkhsjdhjs 5e461c7
adapter.http: update AAS submodel refs `DELETE` route
jkhsjdhjs a6e9a53
adapter.http: suffix submodel refs deletion route with a slash
jkhsjdhjs db85bc4
adapter.http: refactor submodel ref access as separate function
jkhsjdhjs a13fea5
adapter.http: suffix slashes to all routes
jkhsjdhjs 13e4d50
adapter.http: implement AAS API submodel routes via redirects
jkhsjdhjs cebe4bb
adapter.http: move `asset-information` routes to a submount
jkhsjdhjs 4dd4055
adapter.http: rename `/constraints` routes to `/qualifiers`
jkhsjdhjs c3f711f
adapter.http: fix `Qualifier` JSON deserialization
jkhsjdhjs 4e8b3f5
adapter.http: refactor qualifier retrieval/removal
jkhsjdhjs 7d78a51
adapter.http: improve an error mesage
jkhsjdhjs dbaa752
adapter.http: rename `IdentifierConverter` to `Base64URLConverter`
jkhsjdhjs ea77752
adapter.http: add `SpecificAssetId` filtering to `get_aas_all()`
hadijannat 47e67ed
adapter.http: improve `SpecificAssetId` filtering
jkhsjdhjs 9b3e836
adapter.http: refactor AAS retrieval
jkhsjdhjs 9b7133d
adapter.http: remove outdated TODOs
jkhsjdhjs 9bad7df
adapter.http: implement the AAS reference routes
Frosty2500 b47ab9d
adapter.http: implement the attachment routes (#33)
Frosty2500 04455a4
adapter.http: implement the pagination
Frosty2500 f4b7e5d
adapter.http: fix codestyle errors
Frosty2500 9daee38
adapter.http: implement recommended changes
Frosty2500 c90cac2
adapter.http: implement new recommended changes
Frosty2500 c15e2b3
adapter.http: implement new recommended changes
Frosty2500 299bf32
adapter.http: change the limit and cursor check
Frosty2500 1d4159c
adapter.http: implement warning for not implemented routes
Frosty2500 ba16760
adapter.http: remove unnecessary lines
Frosty2500 304ea86
adapter.http: remove excess blank line
jkhsjdhjs afe4e54
Extract compliance tool to be its own package
s-heppner 166bc42
Update Copyright Notices (#224)
s-heppner df6e7ae
adapter.aasx: allow deleting files from `SupplementaryFileContainer`
jkhsjdhjs 2e4e5e3
adapter.http: allow changing the API base path
jkhsjdhjs 02a9dd5
adapter.http: fix a `DeprecationWarning`
jkhsjdhjs aa0d839
adapter.http: allow retrieving and modifying `File` attachments via API
jkhsjdhjs 5e5f0e9
adapter.http: remove nonfunctional 'Not Implemented' check
jkhsjdhjs 959c6e5
adapter.xml, test.adapter.xml: add lxml typechecking
jkhsjdhjs 501b3ef
adapter.http: fix `lxml` typing
jkhsjdhjs 4ca0142
adapter.http: improve type hints
jkhsjdhjs ff49297
adapter.http: remove unnecessary generator expression
jkhsjdhjs 6a0b3f1
adapter.http: remove trailing slashes from routes
jkhsjdhjs 69753ab
adapter.http: add documentation of not implemented features (#52)
Frosty2500 792f031
adapter.http: add CD-Repo routes
zrgt c2e41a0
adapter.http: code style fixes
zrgt 024852f
adapter.http: Refactor and improve codestyle (#292)
zrgt 33336cf
sdk/basyx/adapter/: move copied files to desired location
somsonson be31e3e
sdk/basyx/adapter/: copied and modified the adapter from the basyx-py…
somsonson a882d81
model.adapter: first version of json serialization
TorbenD 25ddaa4
adapter: restructuring
TorbenD f9c4731
test.adapter.json: first test for validation
TorbenD 651914d
adapter.json: Clean up test
mhthies be6a98e
adapter.json: Add first version of json deserialization functionality
mhthies c9954de
adapter.json: Add read_json_aas_file()
mhthies 6af2976
aas.examples: add example for a nearly complete asset administration …
TorbenD 6a66756
adapter.json: Fix usage of Reference and new AASReference
mhthies 3fa0e43
Add license headers to new files
mhthies d1b9448
test: Add json deserialization to the full example test
mhthies 6bea50b
json.serialization: add write_aas_to_json_file function
TorbenD c5cff06
adapter.json.json_serialization: add modul docstring
TorbenD fd59c7b
example: add example for creation of a submodel template including test
TorbenD 3eba736
json: add function to create an example asset administration shell wi…
TorbenD 8ff9948
example: add example for testing missing object-attribute-combinations
TorbenD cb9cb25
adapter.json: Rename json_serialization.write_aas_to_json_file, impro…
mhthies 2ad9583
test: Add more tests for JSON deserialization
mhthies 4aab9b7
test: Fix codestyle
mhthies bbf8b6e
examples: update docstrings and move example for test to test modul
TorbenD df735ce
test.adapter.json: delete not used example
TorbenD 1a39381
test: Add more expected failure tests for json deserialization
mhthies cc4e9c6
model.base: make key of Reference immutable (convert to Tuple) for cr…
TorbenD 66477ac
test: Make JSON schema validating tests optional
mhthies 949a243
model: Fix incompliant inheritance of OperationVariable from Submodel…
mhthies dc6dfae
test: add tests for examples
TorbenD 401c2b0
adapter.json: Fix missing attributes of AAS and Asset in JSON deseria…
mhthies e32cd2f
adapter.json: Add parameter to deserialization's constructor methods
mhthies e12ed03
aas.examples, test: restructuring and renaming of packages, modules a…
TorbenD 65267d8
test: Prevent aasJSONSchema from being added to git repository
mhthies febed71
Remove unused imports, make imports within the packages relative
mhthies 82126f5
add test function for example_aas_mandatory_attributes
TorbenD 05eb8c2
fixed build error
TorbenD b5b0884
adapter.couchdb: Add first draft of CouchDB database store
mhthies f5b2356
adapter.couchdb: Add major parts of functionality and tests
mhthies ec147e8
test: Add CI test for adapter.couchdb using GitLab CI services
mhthies 5a4ed08
adapter.couchdb: Improve documentation and exception handling
mhthies 66db1b1
adapter.couchdb: Add more docstrings, remove TODOs
mhthies 15642ef
test._helper, adapter.json: add test for example_aas_missing_attribut…
TorbenD 62175d0
test, aas: some replacement and renaming of files
TorbenD 4e2042b
test: add test function for example_submodel_template
TorbenD 167d3b9
aas, test: add test function for example concept description
TorbenD 5f8d9c7
aas, test: restructure of test functions
TorbenD 7488c73
test.xml: add initial files
s-heppner 7dd984e
test.adapter.xml: add .gitignore file to ignore AAS.xsd
s-heppner f3b8cd5
test.adapter.xml: add the other two schemas to the .gitignore
s-heppner 842875c
test.adapter.xml: add test_xml_serialization.py
s-heppner 3691ca5
test.adapter.xml: change name of class XMLSerializationSchemaTest
s-heppner 27c8789
test.adapter.xml: remove json specific comments from serialization test
s-heppner f3aa08d
AASDataChecker: create AASDataChecker for easier testing of examples
TorbenD 777a487
fix build error in test of couchDB
TorbenD 2c5951d
AASDataChecker: add check of Value List Elements
TorbenD 093a8e4
DataChecker: fixed check of annotation attribute of AnnotatedRelation…
TorbenD f61c045
model: make description to empy dict instead of None
TorbenD 0cc13cc
fixed build error
TorbenD 18d03f9
Update example data and tests for native value types
mhthies 19928db
examples: integrate check functions into example files
TorbenD 53dc0f2
add tests and fixed code errors
TorbenD 76287be
add tests and fix code errors
TorbenD 34b79e7
fix commits to #234547
TorbenD add9b76
make imports relative if possible #41'
TorbenD e4ffe92
test: add exception tests for test_couchdb.py
TorbenD 47d92ce
examples: add logger for failsafe mode and fixing failsafe mode
TorbenD faa65a0
update xml_serialization and test with changes that appeared through …
s-heppner 9d18dc1
test.adapter.xml: remove resolved todo
s-heppner e328ace
test.adapter.xml: update test_functions after parameter change in xml…
s-heppner 6cbe4ae
test: Add IEC61360ConceptDescription to json/xml serialization tests
mhthies 0cc2f44
compliance_tool: add unittests for compliance_tool script
TorbenD db9134e
adapter.aasx: Add first draft of AASX reading/writing
mhthies 0c33743
Add aas.util.traversal
mhthies 8cab92d
test: Add test for AASXReader and AASXWriter, improve coverage report
mhthies 21e4854
adapter.aasx: Add type annotation to fix mypy type check
mhthies a1fbdc4
adapter.aasx: Rework SupplementaryFileContainer to detect equal files…
mhthies 2b4d7fe
json: update to schema 2.0.1
1d270dc
adapter: re-publish reader/writer functions
jkhsjdhjs 36018cb
test: add serialize and deserialize test for xml
jkhsjdhjs 17d15af
adapter.xml: rename read_xml_aas_file to read_aas_xml_file
jkhsjdhjs e1c4879
test: add xml_deserialization tests
jkhsjdhjs 506a51b
adapter: explicitly define INSTANCE as ModelingKind default value
jkhsjdhjs ce5ff08
test.xml: don't access protected property _kind
jkhsjdhjs 00bd0ca
set correct copyright year for all files
jkhsjdhjs 0a2eaee
adapter: specify type of objects in DictObjectStore
jkhsjdhjs 8ca3bab
test: Fix occasional test failures due to rounding error in test_aasx
mhthies ddc3faf
adapter.xml: change for current schema
jkhsjdhjs 6041e0e
adapter.xml.xml_deserialization: support schema v2.0.1
jkhsjdhjs b34048d
compliance_tool: Add xml extension including tests
TorbenD ef1bb35
test.adapter.xml: delete aasXMLSchema*.xsd from gitignore
TorbenD 862ae20
adapter, cli: add json schema and change path
TorbenD 57c2b51
adapter: Improve path handling of Schema files
mhthies 5a225b9
test: Remove .gitignore files for Schema files
mhthies 2b3f15f
test.adapter.test_couchdb: Make tests be skipped
s-heppner a5867fc
adapter: Remove couchdb and according tests.
s-heppner b0ad89c
adapter.aasx: Allow chosing between XML and JSON serialization when w…
mhthies c14d486
adapter.xml.xml_deserialization: add read_aas_xml_file_into() function
jkhsjdhjs f98695d
adapter.xml.xml_deserialization: add read_aas_xml_element()
jkhsjdhjs e0f7be4
adapter.xml.xml_deserialization: make failsafe and stripped class var…
jkhsjdhjs b3343b3
adapter.xml.xml_deserialization: change type_ to Referable
jkhsjdhjs 91cb211
adapter.xml.xml_deserialization: add read_aas_xml_file_into() function
jkhsjdhjs 69ef74d
adapter.xml.xml_deserialization: add read_aas_xml_element()
jkhsjdhjs a5de0e8
adapter.xml.xml_deserialization: make failsafe and stripped class var…
jkhsjdhjs 8c47d79
adapter.xml.xml_deserialization: change type_ to Referable
jkhsjdhjs c58f673
adapter.aasx: Add write_aas_objects() method
mhthies 77def45
test: Catch zipfile warnings during writing AASX file
mhthies 542547c
Fix typo in tests
mhthies 2382815
test.adapter.xml: improve xml deserialization tests
jkhsjdhjs 2339693
test.adapter.xml.xml_deserialization: make object_class default to En…
jkhsjdhjs d99e767
test.adapter.json: remove unused imports
jkhsjdhjs 6ee6c70
adapter.json.json_deserialization: support deserializing stripped obj…
jkhsjdhjs 365cd9a
adapter.json.json_serialization: support serializing stripped objects
jkhsjdhjs 1c940ac
model.aas: remove underscore suffix from parameters submodel_ and sec…
jkhsjdhjs 842f00b
Update license headers for EPL-2.0 dual-licensing
mhthies a726d40
Rebrand project code PyI40AAS → Eclipse BaSyx Python SDK
mhthies c85ebb9
Move Python package aas → basyx.aas
mhthies 6d671b6
tests: Suppress MyPy warnings about TestCase.assertLogs
mhthies 37a8eff
minor codestyle improvements
jkhsjdhjs f525c83
Update license headers for MIT license
jkhsjdhjs 0fd4cb1
add whitespace after assert keyword
jkhsjdhjs 07d6a6d
model: prevent creating References without keys
jkhsjdhjs 1b19aef
test.adapter.xml.xml_deserialization: remove unneeded 'type: ignore' …
jkhsjdhjs b13bd58
test.adapter.xml.xml_deserialization: make `OperationVariable` tests …
jkhsjdhjs e217e0a
model, adapter, example: add constraint string not empty, adapt Asset…
TorbenD 67b864a
pycodestyle: fixed warnings
TorbenD 60b72c9
test.adapter.xml: fix xml_deserialization tests
jkhsjdhjs f977c63
submodel.entity: add typ for self.entity_type, add types for return v…
TorbenD a987b46
test.adapter.xml.test_xml_deserialization: Add "<aas:kind>Template</a…
s-heppner a31d260
test.adapter.json.test_json_serialization: Add categories to DataElem…
s-heppner 7c4ff0c
test.adapter.json.test_json_deserialization: Add category to DataElem…
s-heppner aed4648
testfiles: add new test files for v3.0RC01 and fix minor error handli…
TorbenD ddc0f94
bugfixes: fixes findings in merge request
TorbenD 1118d8b
model.namespace: create namespaces for unique id_short, semantic_id a…
TorbenD c5d97c1
model.submodelelementcollection: add new types to support attribute a…
TorbenD 6739cd3
adapter.aasx: Update AASXWriter.write_aas() to DotAAS v3.0 spec
mhthies 25815e6
test: Remove outdated AASX test
mhthies 8eb8122
test: fix dysfunctional xml deserialization test
jkhsjdhjs 34d7e6a
remove Asset
jkhsjdhjs a5e59c9
remove View
jkhsjdhjs 371b82b
remove Constraint
jkhsjdhjs 4e41a20
rename Blob/mimeType File/mimeType to /contentType
jkhsjdhjs 51b9568
rename Identifiable/identification to Identifiable/id
jkhsjdhjs ffec555
change type of Identifiable/id to str
jkhsjdhjs 36b9c43
test.adapter.aasx: add whitespace after assert
jkhsjdhjs 8e6eb97
model: update SubmodelElementCollection
jkhsjdhjs ec32c85
add SubmodelElementList
jkhsjdhjs 6bbacd4
begin integration of new XML and JSON schemata
jkhsjdhjs 94acf12
fix some mypy errors
jkhsjdhjs 5ffc4ad
update implementation and adapters for new DataSpecification classes …
jkhsjdhjs d53ec3d
Change type of all occurrences of `AssetInformation.global_asset_id` …
beca5c0
update XML/JSON schemata, adapter and test files for updated `AssetIn…
jkhsjdhjs a152c61
remove wrapping `Identifier()` around strings
jkhsjdhjs a15bd3d
change type of `Entity.global_asset_id` to `Identifier`
jkhsjdhjs 99eca87
model.base: Rename GlobalReference to ExternalReference
s-heppner 247b437
Fix PyCodeStyle
s-heppner 314126f
model.base: Rename ModelingKind to ModellingKind (#104)
s-heppner 4581f1d
replace all usages of `LangStringSet` with a `ConstrainedLangStringSet`
jkhsjdhjs 10d3597
Update compliance tool test files
zrgt 3709e91
Update test files
zrgt e9fca7a
test.adapter.xml: Reintroduce "# type: ignore" tags that got lost in …
s-heppner 4a073ac
test.adapter.xml: remove 'type: ignore' comments
jkhsjdhjs 3465b01
test.adapter.xml: test deserialization without namespace prefixes
jkhsjdhjs a5aa5c1
test.adater.xml.test_xml_deserialization: simplify
jkhsjdhjs 6ed3797
test.adapter.json: add `BytesIO` test
jkhsjdhjs f596847
adapter.xml: add function for serializing single objects
jkhsjdhjs 2d10cc2
Reintroduce schema files for testing XML and JSON serialization
s-heppner 2fde078
test: Remove schema files and adapt CI to fetch them
s-heppner e11c6cc
Update Copyright Notices (#224)
s-heppner a8f33b7
adapter.aasx: allow deleting files from `SupplementaryFileContainer`
jkhsjdhjs e189f4b
adapter.xml, test.adapter.xml: add lxml typechecking
jkhsjdhjs 910d9a0
test_xml_deserialization: Add tests for `_tag_replace_namespace` (#284)
JAB1305 2b3ab76
http-api-oas: move to test/adapter/ directory
jkhsjdhjs 33f8c3e
http-api-oas: split into aas and submodel interface
jkhsjdhjs 9e873b5
adapter.http: make trailing slashes the default
jkhsjdhjs 5a9a895
http-api-oas: remove PATCH route
jkhsjdhjs 87fc39b
http-api-oas: make result types more accurate
jkhsjdhjs bf2d62f
http-api-oas: add missing 400 responses and fix descriptions
jkhsjdhjs c4a3ec7
http-api-oas: add links
jkhsjdhjs f33d079
test: add http api tests
jkhsjdhjs 6b75ae1
test.adapter.http: update w.r.t. the changes of the last 2 years
jkhsjdhjs b314b30
test.adapter.http: ignore the type of an import to make `mypy` happy
jkhsjdhjs a0d05fd
adapter.http: update Werkzeug to 3.x
jkhsjdhjs eeb64c2
test: disable http api tests for now
jkhsjdhjs b230766
adapter.http: improve codestyle
jkhsjdhjs ee0c241
test.adapter.http: update license header
jkhsjdhjs ae32225
adapter.http: allow retrieving and modifying `File` attachments via API
jkhsjdhjs 895eb78
move copied files from basyx-python-sdk to desired folders
somsonson b1b9895
sdk/basyx/adapter: modified the adapter from the basy-python-sdk repo…
somsonson a5955b2
sdk/: Add unittests for aasx.py including various testfiles. Fix code…
somsonson 0906826
.github/workflows/ci.yml: import lxml-stubs for CI tests sdk/: fix va…
somsonson 4d24ad8
sdk/basyx/adapter/: redesigned adapter structure to match its use
somsonson f14d0d2
sdk/basyx/adapter/_generic.py: remove unused file
somsonson a63c085
move sdk/basyx/aasx.py and fixed various imports
somsonson 2b74f3f
sdk/basyx/tutorial/tutorial_create_simple_aas.py: Add verification step
JAB1305 0926132
sdk/basyx/tutorial/tutorial_create_simple_aas.py: Add further explana…
JAB1305 a015464
sdk/test: added unittest to improve coverage. Modified test folder to…
somsonson 5f101ea
Update tutorial_create_simple_aas.py
somsonson 82139cd
sdk/: Remove unused functions and simplify the code. Resolve PR threads.
somsonson d618cb2
aasx.py: Rename a few functions and check the docstrings. tutorial_cr…
somsonson 7e0e4ef
sdk/basyx/__init__.py: Import aas-core3 in init file to shortcut its …
somsonson 8c53860
tutorial_create_simple_aas.py rename to tutorial_aasx.py
somsonson 84f798c
tutorial_create_simple_aas.py: restored the original tutorial
somsonson 54b32cc
sdk/basyx/__init__.py: added documentation for aas-core3 shortcut
somsonson a08971f
Update sdk/basyx/__init__.py
s-heppner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,5 @@ | ||
| from .object_store import * | ||
|
|
||
| # Alias `types` as `model` to maintain consistency with the import style of the predecessor project (BaSyx-Python SDK), | ||
| # ensuring a familiar experience for users transitioning to the new BaSyx-Python Framework. | ||
| from aas_core3 import types as model |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| #!/usr/bin/env python3 | ||
| """ | ||
| Tutorial for exporting Asset Administration Shells with related objects and auxiliary files to AASX package files, using | ||
| the :mod:`~basyx.aasx` module from the Eclipse BaSyx Python Framework. | ||
|
|
||
| """ | ||
|
|
||
| import datetime | ||
| from pathlib import Path # Used for easier handling of auxiliary file's local path | ||
|
|
||
| import pyecma376_2 # The base library for Open Packaging Specifications. We will use the OPCCoreProperties class. | ||
| from basyx import model | ||
| from basyx.aasx import AASXWriter, AASXReader, DictSupplementaryFileContainer | ||
| from basyx.object_store import ObjectStore | ||
|
|
||
| # step 1: Setting up an SupplementaryFileContainer and AAS & submodel with File objects | ||
| # step 2: Writing AAS objects and auxiliary files to an AASX package | ||
| # step 3: Reading AAS objects and auxiliary files from an AASX package | ||
|
|
||
|
|
||
| ######################################################################################## | ||
| # Step 1: Setting up a SupplementaryFileContainer and AAS & submodel with File objects # | ||
| ######################################################################################## | ||
|
|
||
| # Let's first create a basic Asset Administration Shell with a simple submodel. | ||
| # See `tutorial_create_simple_aas.py` for more details. | ||
| submodel = model.Submodel(id='https://acplt.org/Submodel', submodel_elements=[]) | ||
|
|
||
| key_types = model.KeyTypes("Submodel") | ||
| Referencetype = model.ReferenceTypes("ModelReference") | ||
| key = model.Key(value='https://acplt.org/Submodel', type=key_types) | ||
| reference = model.Reference(type=Referencetype, keys=[key]) | ||
|
|
||
| aas = model.AssetAdministrationShell(id='https://acplt.org/Simple_AAS', | ||
| asset_information=model.AssetInformation( | ||
| asset_kind=model.AssetKind.TYPE), | ||
| submodels=[reference]) | ||
|
|
||
| # Another submodel, which is not related to the AAS: | ||
| unrelated_submodel = model.Submodel( | ||
| id='https://acplt.org/Unrelated_Submodel' | ||
| ) | ||
|
|
||
| # We add these objects to an ObjectStore for easy retrieval by id. | ||
| object_store: ObjectStore = ObjectStore([unrelated_submodel, submodel, aas]) | ||
|
|
||
|
|
||
| # For holding auxiliary files, which will eventually be added to an AASX package, we need a SupplementaryFileContainer. | ||
| # The `DictSupplementaryFileContainer` is a simple SupplementaryFileContainer that stores the files' contents in simple | ||
| # bytes objects in memory. | ||
| file_store = DictSupplementaryFileContainer() | ||
|
|
||
| # Now, we add an example file from our local filesystem to the SupplementaryFileContainer. | ||
| # | ||
| # For this purpose, we need to specify the file's name in the SupplementaryFileContainer. This name is used to reference | ||
| # the file in the container and will later be used as the filename in the AASX package file. Thus, this file must begin | ||
| # with a slash and should begin with `/aasx/`. Here, we use `/aasx/suppl/MyExampleFile.pdf`. The | ||
| # SupplementaryFileContainer's add_file() method will ensure uniqueness of the name by adding a suffix if an equally | ||
| # named file with different contents exists. The final name is returned. | ||
| # | ||
| # In addition, we need to specify the MIME type of the file, which is later used in the metadata of the AASX package. | ||
| # (This is actually a requirement of the underlying Open Packaging Conventions (ECMA376-2) format, which imposes the | ||
| # specification of the MIME type ("content type") of every single file within the package.) | ||
|
|
||
| with open(Path(__file__).parent / 'data' / 'TestFile.pdf', 'rb') as f: | ||
| actual_file_name = file_store.add_file("/aasx/suppl/MyExampleFile.pdf", f, "application/pdf") | ||
|
|
||
|
|
||
| # With the actual_file_name in the SupplementaryFileContainer, we can create a reference to that file in our AAS | ||
| # Submodel, in the form of a `File` object: | ||
|
|
||
| model.File(id_short="documentationFile", content_type="application/pdf", value=actual_file_name) | ||
|
|
||
| file = model.File(id_short="documentationFile", content_type="application/pdf", value=actual_file_name) | ||
| if submodel.submodel_elements is not None: | ||
| submodel.submodel_elements.append(file) | ||
|
|
||
|
|
||
| ###################################################################### | ||
| # Step 2: Writing AAS objects and auxiliary files to an AASX package # | ||
| ###################################################################### | ||
|
|
||
| # After setting everything up in Step 1, writing the AAS, including the Submodel objects and the auxiliary file | ||
| # to an AASX package is simple. | ||
|
|
||
| # Open an AASXWriter with the destination file name and use it as a context handler, to make sure it is properly closed | ||
| # after doing the modifications: | ||
| with AASXWriter("./MyAASXPackage.aasx") as writer: | ||
| # Write the AAS and everything belonging to it to the AASX package | ||
| # The `write_aas()` method will automatically fetch the AAS object with the given id | ||
| # and all referenced Submodel objects from the ObjectStore. It will also scan every object for | ||
| # semanticIds referencing ConceptDescription, fetch them from the ObjectStore, and scan all sbmodels for `File` | ||
| # objects and fetch the referenced auxiliary files from the SupplementaryFileContainer. | ||
| # In order to add more than one AAS to the package, we can simply add more Identifiers to the `aas_ids` list. | ||
| # | ||
| # ATTENTION: As of Version 3.0 RC01 of Details of the Asset Administration Shell, it is no longer valid to add more | ||
| # than one "aas-spec" part (JSON/XML part with AAS objects) to an AASX package. Thus, `write_aas` MUST | ||
| # only be called once per AASX package! | ||
| writer.write_aas(aas_ids=['https://acplt.org/Simple_AAS'], | ||
| object_store=object_store, | ||
| file_store=file_store) | ||
|
|
||
| # Alternatively, we can use a more low-level interface to add a JSON/XML part with any Identifiable objects (not | ||
| # only an AAS and referenced objects) in the AASX package manually. `write_aas_objects()` will also take care of | ||
| # adding referenced auxiliary files by scanning all submodel objects for contained `File` objects. | ||
| # | ||
| # ATTENTION: As of Version 3.0 RC01 of Details of the Asset Administration Shell, it is no longer valid to add more | ||
| # than one "aas-spec" part (JSON/XML part with AAS objects) to an AASX package. Thus, `write_all_aas_objects` SHALL | ||
| # only be used as an alternative to `write_aas` and SHALL only be called once! | ||
| objects_to_be_written: ObjectStore[model.Identifiable] = ObjectStore([unrelated_submodel]) | ||
| writer.write_all_aas_objects(part_name="/aasx/my_aas_part.xml", | ||
| objects=objects_to_be_written, | ||
| file_store=file_store) | ||
|
|
||
| # We can also add a thumbnail image to the package (using `writer.write_thumbnail()`) or add metadata: | ||
| meta_data = pyecma376_2.OPCCoreProperties() | ||
| meta_data.creator = "Chair of Process Control Engineering" | ||
| meta_data.created = datetime.datetime.now() | ||
| writer.write_core_properties(meta_data) | ||
|
|
||
| # Closing the AASXWriter will write some required parts with relationships and MIME types to the AASX package file and | ||
| # close the package file afterward. Make sure, to always call `AASXWriter.close()` or use the AASXWriter in a `with` | ||
| # statement (as a context manager) as shown above. | ||
|
|
||
|
|
||
| ######################################################################## | ||
| # Step 3: Reading AAS objects and auxiliary files from an AASX package # | ||
| ######################################################################## | ||
|
|
||
| # Let's read the AASX package file, we have just written. | ||
| # We'll use a fresh ObjectStore and SupplementaryFileContainer to read AAS objects and auxiliary files into. | ||
| new_object_store: ObjectStore = ObjectStore() | ||
| new_file_store = DictSupplementaryFileContainer() | ||
|
|
||
| # Again, we need to use the AASXReader as a context manager (or call `.close()` in the end) to make sure the AASX | ||
| # package file is properly closed when we are finished. | ||
| with AASXReader("MyAASXPackage.aasx") as reader: | ||
| # Read all contained AAS objects and all referenced auxiliary files | ||
| reader.read_into(object_store=new_object_store, | ||
| file_store=new_file_store) | ||
|
|
||
| # We can also read the metadata | ||
| new_meta_data = reader.get_core_properties() | ||
|
|
||
| # We could also read the thumbnail image, using `reader.get_thumbnail()` | ||
|
|
||
|
|
||
| # Some quick checks to make sure, reading worked as expected | ||
| assert 'https://acplt.org/Submodel' in new_object_store | ||
| assert actual_file_name in new_file_store | ||
| assert new_meta_data.creator == "Chair of Process Control Engineering" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| from aas_core3 import types as model | ||
| from basyx.object_store import ObjectStore | ||
| import aas_core3.types as aas_types | ||
| from basyx.aasx import DictSupplementaryFileContainer | ||
| from pathlib import Path | ||
|
|
||
|
|
||
| def create_full_example() -> ObjectStore: | ||
| """ | ||
| Creates an object store which is filled with an example :class:`~basyx.aas.model.submodel.Submodel`, | ||
| :class:`~basyx.aas.model.concept.ConceptDescription` and :class:`~basyx.aas.model.aas.AssetAdministrationShell` | ||
| using the functions of this module | ||
|
|
||
| :return: :class:`~basyx.aas.model.provider.DictObjectStore` | ||
| """ | ||
| Referencetype = aas_types.ReferenceTypes("ModelReference") | ||
|
|
||
| key_types = aas_types.KeyTypes("Submodel") | ||
|
|
||
| key = aas_types.Key(value="some-unique-global-identifier", type=key_types) | ||
|
|
||
| reference = aas_types.Reference(type=Referencetype, keys=[key]) | ||
|
|
||
| submodel = aas_types.Submodel( | ||
| id="some-unique-global-identifier", | ||
| submodel_elements=[ | ||
| aas_types.Property( | ||
| id_short="some_property", | ||
| value_type=aas_types.DataTypeDefXSD.INT, | ||
| value="1984", | ||
| semantic_id=reference | ||
| ) | ||
| ] | ||
| ) | ||
| file_store = DictSupplementaryFileContainer() | ||
|
|
||
| with open(Path(__file__).parent.parent / 'basyx' / 'tutorial' / 'data' / 'TestFile.pdf', 'rb') as f: | ||
| actual_file_name = file_store.add_file("/aasx/suppl/MyExampleFile.pdf", f, "application/pdf") | ||
|
|
||
| if submodel.submodel_elements is not None: | ||
| submodel.submodel_elements.append(aas_types.File(id_short="documentationFile", | ||
| content_type="application/pdf", | ||
| value=actual_file_name)) | ||
|
|
||
| aas = aas_types.AssetAdministrationShell(id="https://acplt.org/Test_AssetAdministrationShell", | ||
| asset_information=aas_types.AssetInformation( | ||
| asset_kind=aas_types.AssetKind.TYPE), | ||
| submodels=[reference]) | ||
| obj_store: ObjectStore[model.Identifiable] = ObjectStore() | ||
| obj_store.add(aas) | ||
| obj_store.add(submodel) | ||
| return obj_store |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.