Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
170 commits
Select commit Hold shift + click to select a range
0dd9016
compliance_tool: add tests for check_schema and check_deserialization
TorbenD Feb 21, 2020
921715b
fixed missing schema for test
TorbenD Feb 21, 2020
fb3154a
compliance_tool: add tests for check example and check two json file
TorbenD Feb 26, 2020
9410dda
compliance_tool: add unittests for MessageLogger
TorbenD Feb 26, 2020
b9e02cc
compliance tool: add script with arg parser
TorbenD Feb 28, 2020
3cede4b
fixing merge request review comments
TorbenD Mar 2, 2020
5d32eda
compliance_tool: Fixing merge request comments
TorbenD Mar 3, 2020
36c4de0
compliance_tool: add test for state_manager
TorbenD Mar 3, 2020
fe7fd00
compliance_tool: adding docstrings and introduce class Step
TorbenD Mar 3, 2020
7fbb502
compliance_tool: fixed merge request comments
TorbenD Mar 3, 2020
811c648
compliance_tool: fixed review comments
TorbenD Mar 9, 2020
3ff0339
compliance_tool: fixed build error
TorbenD Mar 10, 2020
ce90c63
compliance_tool: fixed review comments
TorbenD Mar 10, 2020
d28249c
compliance_tool: fixed build error
TorbenD Mar 10, 2020
19b16d7
compliance_tool: add unittests for compliance_tool script
TorbenD Mar 12, 2020
bf0dec5
compliance_tool: change subprocess.run parameter for python3.6
TorbenD Mar 12, 2020
17c1519
test: Use python version 3 explicitly for testing cli as subprocess
mhthies Mar 12, 2020
67aa9f2
compliance_tool: separate tests for better skipping
TorbenD Mar 12, 2020
a1e5786
compliance_tool: Rename cli module, make it a function, add setuptool…
mhthies Mar 12, 2020
81a7561
compliance_tool: add test for logfile output
TorbenD Mar 12, 2020
c09745e
aas.examples.data: Add Identification and BoM submodels to Test_Asset…
mhthies Mar 24, 2020
2517ede
test.compliance_tool: Fix JSON schema path on unixoid os
mhthies Mar 24, 2020
85434d8
json: update to schema 2.0.1
Apr 9, 2020
dd58547
Merge branch 'feature/updateJSONSchema' into 'master'
mhthies Apr 9, 2020
1ebfb53
adapter: re-publish reader/writer functions
jkhsjdhjs Apr 9, 2020
7c3ebfa
Merge branch 'improve/republish_adapter_functions' into 'master'
mhthies Apr 14, 2020
b2918e0
set correct copyright year for all files
jkhsjdhjs Apr 17, 2020
e7a4775
compliance_tool: Add xml extension including tests
TorbenD Apr 27, 2020
6d2ee9d
compliance_tool: add schema path as argument and fixed review comments
TorbenD Apr 30, 2020
da70f9f
compliance_tool: add schema_path to all files
TorbenD Apr 30, 2020
fc1a428
compliance_tool: fixed review comments
TorbenD Apr 30, 2020
ae541dd
Merge branch 'feature/compliance_tool_xml_extension' into 'master'
mhthies Apr 30, 2020
8125931
adapter.xml_version_201: update test files
TorbenD May 13, 2020
c89eb39
compliance_tool: update files to v2.0.1
TorbenD May 19, 2020
c88e2a8
compliance_tool: update json files to V2.0.1
TorbenD May 20, 2020
bad1c26
adapter, cli: add json schema and change path
TorbenD May 26, 2020
8731804
test.compliance_tool: change demo files for schema v2.0.1
jkhsjdhjs May 26, 2020
7744c07
adapter: Improve path handling of Schema files
mhthies May 27, 2020
aeb0543
cli: add aasx functionality
TorbenD Sep 25, 2020
3e73a3e
fixed pycodestyle errors
TorbenD Sep 25, 2020
ec59915
add missing aasx test file
TorbenD Sep 25, 2020
e8f4c15
add step for distinguish between open and reading file
TorbenD Oct 5, 2020
45ffbe1
examples.data: Add File object with absolute URI reference (non-local…
mhthies Oct 5, 2020
dd59205
Merge branch 'fix/aasx_file_absolute_uri' into 'master'
TorbenD Oct 6, 2020
0421f9e
examples.data: Add File object with absolute URI reference (non-local…
mhthies Oct 5, 2020
a7db671
update to new master, add new example with objects bind to at least o…
TorbenD Oct 6, 2020
a11fc23
make mypy happy and fixed codestyle errors
TorbenD Oct 6, 2020
1e380ed
compliance_tool: add pretty printing for example files
TorbenD Oct 7, 2020
6d2749a
Merge branch 'feature/compliance_tool_pretty_printing_example_files' …
mhthies Oct 7, 2020
3b196aa
merge master and pritty print of example files
TorbenD Oct 27, 2020
d2dd267
cli_aasx: add tests for core properties
TorbenD Oct 30, 2020
1c899df
cli_aas: Update test output
TorbenD Oct 30, 2020
e0f726f
compliance_tool_aasx: Use single file creation for example
TorbenD Oct 30, 2020
95eb452
cli: delete schema check function
TorbenD Nov 19, 2020
f39b6f1
model.referable: add displayName to model and change corresponding fi…
TorbenD Dec 1, 2020
cd2483d
testfiles: add new test files for v3.0RC01 and fix minor error handli…
TorbenD Dec 8, 2020
bcf7d9b
xml, json: change DataSpecificationIEC61360/3/0 to DataSpecificationI…
TorbenD Dec 29, 2020
3d470a6
bugfixes: fixes findings in merge request
TorbenD Dec 29, 2020
f77aa51
model.namespace: create namespaces for unique id_short, semantic_id a…
TorbenD Jan 7, 2021
0fae078
model.submodelelementcollection: add new types to support attribute a…
TorbenD Jan 12, 2021
30fed31
model.compliance_tool: add new files for testing xml and json example…
TorbenD Jan 13, 2021
11cd668
model.aasx: add files for compliance tool
TorbenD Jan 13, 2021
e870ddb
Update license headers for EPL-2.0 dual-licensing
mhthies Feb 2, 2021
15dcf60
examples: two minor spelling mistakes
TorbenD Mar 15, 2021
5be1928
Merge branch 'master' into improve/V30RC01
jkhsjdhjs Oct 28, 2021
0d0a013
remove Asset
jkhsjdhjs Oct 28, 2021
bd5e1b8
remove View
jkhsjdhjs Nov 1, 2021
be15ec6
examples: change AAS submodel reference keys to local=True
jkhsjdhjs Nov 3, 2021
d6d1805
Merge branch 'fix/testfile_references' into 'master'
TorbenD Nov 4, 2021
912c39d
Rebrand project code PyI40AAS → Eclipse BaSyx Python SDK
mhthies Nov 15, 2021
db6a7bb
Move Python package aas → basyx.aas
mhthies Nov 15, 2021
2cd2544
Fix test data for exampled data changed while rebranding project
mhthies Nov 15, 2021
04f0898
docs: Fix minor formatting syntax issues
mhthies Feb 2, 2022
eacf356
Merge pull request #2 from acplt/prepare-release
FrankSchnicke Feb 3, 2022
3a4ff23
Merge branch 'main' into improve/V30RC02
jkhsjdhjs Mar 3, 2022
315ed52
aas.compliance_tool: Extract the check_schema core methods to their o…
s-heppner Mar 4, 2022
bfaaed9
aas.compliance_tool.compliance_check_aasx: Add function to check schema
s-heppner Mar 4, 2022
791eab3
aas.compliance_tool.compliance_check_aasx: Fix some bugs and remove u…
s-heppner Mar 4, 2022
20085e3
aas.compliance_tool.compliance_check_aasx: Fix codestyle
s-heppner Apr 4, 2022
1dcd364
test.compliance_tool.test_compliance_check_aasx: Skip schema test for…
s-heppner Apr 6, 2022
dfaa05f
remove AssetInformation/billOfMaterial
jkhsjdhjs Apr 2, 2022
28d4af9
rename BasicEvent to BasicEventElement
jkhsjdhjs Apr 5, 2022
1e56118
Merge branch 'main' into improve/V30RC02
jkhsjdhjs Apr 13, 2022
de45af3
Update license headers for MIT license
jkhsjdhjs Apr 19, 2022
c77b321
Merge pull request #11 from acplt/feature/mit_license
FrankSchnicke May 4, 2022
22031e4
Added missing loggers
bjoern-otto Apr 22, 2022
ea74e46
test: set PYTHONPATH when running the compliance tool
jkhsjdhjs May 10, 2022
5d89ca8
Merge pull request #16 from acplt/update/readme
FrankSchnicke May 18, 2022
324c270
Merge branch 'main' into improve/V30RC02
jkhsjdhjs Jun 1, 2022
e41cff0
change type of AssetInformation/defaultThumbnail from File to Resource
jkhsjdhjs Jun 22, 2022
17ac82d
rename Blob/mimeType File/mimeType to /contentType
jkhsjdhjs Jun 22, 2022
3dcbbc7
rename Identifiable/identification to Identifiable/id
jkhsjdhjs Jun 25, 2022
b2122d4
change type of Identifiable/id to str
jkhsjdhjs Jul 18, 2022
17eb576
rename IdentifierKeyValuePair to SpecificAssetId
jkhsjdhjs Jul 20, 2022
ded12e9
change type of Extension/refersTo from Reference to ModelReference
jkhsjdhjs Jul 20, 2022
b764523
compliance_tool: except KeyError when reading AASX package
jkhsjdhjs Jul 22, 2022
ba0d048
add whitespace after assert keyword
jkhsjdhjs Aug 13, 2022
15b020d
Merge pull request #30 from acplt/fix/pycodestyle_warnings
FrankSchnicke Aug 16, 2022
4a96503
Merge pull request #26 from acplt/fix/compliance_tool_crash
FrankSchnicke Aug 16, 2022
7a333ec
Merge branch 'main' into improve/V30RC02
jkhsjdhjs Aug 16, 2022
e66ec0d
model: update SubmodelElementCollection
jkhsjdhjs Oct 17, 2022
adf8219
add SubmodelElementList
jkhsjdhjs Oct 20, 2022
d20fb0d
test.compliance_tool: improve wrong_attribute test strictness
jkhsjdhjs Oct 21, 2022
b02c820
test: remove skipping of a test on Python < 3.7
jkhsjdhjs Oct 23, 2022
3c43c5a
Merge pull request #39 from acplt/improve/compliance_tool_test_strict…
FrankSchnicke Oct 26, 2022
aa5b85f
Merge branch 'main' into improve/V30RC02
jkhsjdhjs Oct 27, 2022
f90b237
add missing attributes to BasicEventElement
jkhsjdhjs Jan 6, 2023
d1c6eb6
begin integration of new XML and JSON schemata
jkhsjdhjs Mar 20, 2023
fc7de77
update implementation and adapters for new DataSpecification classes …
jkhsjdhjs Apr 7, 2023
8640b4a
adapter.xml: support deserialization of `Qualifier.kind`
jkhsjdhjs Apr 7, 2023
c9594d5
Merge pull request #18 from acplt/improve/V30RC02
s-heppner Apr 17, 2023
b181e1c
test.compliance_tool: re-enable disabled assertion
jkhsjdhjs May 15, 2023
40a2d7f
Merge branch 'main' into merge/main_in_v30
jkhsjdhjs May 15, 2023
e02ec78
test.compliance_tool: enable another disabled assertion
jkhsjdhjs May 15, 2023
d61f0c6
Merge pull request #78 from acplt/merge/main_in_v30
s-heppner May 27, 2023
4bd17b9
examples, test: adjust AdministrativeInformation version and revision…
jkhsjdhjs Jun 27, 2023
6cfc670
model.base: raise `AASConstraintViolation` in `AdministrativeInformat…
jkhsjdhjs Jun 27, 2023
baf5204
update XML/JSON schemata, adapter and test files for updated `AssetIn…
jkhsjdhjs May 15, 2023
8a8110e
change type of `Entity.global_asset_id` to `Identifier`
jkhsjdhjs Jul 20, 2023
01e3fc4
examples, test: add exemplary usages of new `AdministrativeInformatio…
jkhsjdhjs Aug 20, 2023
c543837
test.compliance_tool.files: replace `GlobalReference` with `ExternalR…
jkhsjdhjs Aug 20, 2023
ad37ce0
Merge branch 'improve/V30' into Rename/GlobalReference
jkhsjdhjs Aug 23, 2023
ef3c867
examples, test: rename `AdministrativeInformation.creator` references…
jkhsjdhjs Aug 23, 2023
f2fc279
Merge pull request #106 from rwth-iat/Rename/GlobalReference
s-heppner Aug 24, 2023
35fb5d0
test: update compliance tool files for new `LangStringSet` serialization
jkhsjdhjs Aug 24, 2023
306838f
Remove the www. subdomain in AASX namespace (#122)
zrgt Oct 10, 2023
6017931
Remove DataSpecificationPhysicalUnit (#137)
zrgt Oct 12, 2023
020388d
test: update compliance tool test-files
jkhsjdhjs Oct 4, 2023
9bcdc6b
Update compliance tool test files
zrgt Oct 17, 2023
32e64bc
test: update compliance tool test-files
jkhsjdhjs Oct 4, 2023
2fb722e
test.compliance_tool: Manually update test aasx files
s-heppner Oct 18, 2023
38c6793
Merge pull request #139 from rwth-iat/fix/id_short
s-heppner Oct 19, 2023
5f60a15
Update compliance tool test files
zrgt Oct 17, 2023
5878cf4
Fix the implementation of DataSpecificationIEC61360
zrgt Oct 17, 2023
eec297a
Remove binary files from test files for compliance tool (#143)
zrgt Oct 20, 2023
9b76d24
Update test files
zrgt Oct 27, 2023
bf52267
make `Operation` a `Namespace`
jkhsjdhjs Nov 3, 2023
876657b
test: remove null values from example files
jkhsjdhjs Nov 14, 2023
4e313ee
test: add schema validation of wrong attribute JSON/XML files
jkhsjdhjs Nov 14, 2023
748505f
adapter.xml: Update XSD of `valueDataType` and `Extension`
s-heppner Nov 14, 2023
a48ab44
adapter.xml: Change order of `SubmodelElementList` objects
s-heppner Nov 14, 2023
97298c7
adapter.xml: Remove `<aas:kind>` from `SubmodelElement`s in XSD
s-heppner Nov 14, 2023
16408e9
adapter.xml: Fix deserialization for `Extension`
s-heppner Nov 15, 2023
9d8312c
compliance_tool: add verification of `Extensions`
jkhsjdhjs Nov 16, 2023
f17bcff
Merge pull request #174 from eclipse-basyx/improve/V30
s-heppner Nov 25, 2023
bdffe49
fixed half the broken doc links
Frosty2500 Dec 20, 2023
ba6f53a
massive docstring overhaul
jkhsjdhjs Dec 23, 2023
c57bf5e
adapter.aasx: improve error messages
jkhsjdhjs Jan 14, 2024
54af5d9
Extract compliance_tool from BaSyx Python SDK
s-heppner Mar 9, 2024
32079aa
Add basic project files
s-heppner Mar 9, 2024
03edeee
Adapt import statements to new paths
s-heppner Mar 9, 2024
481be26
Add missing requirement jsonschema
s-heppner Mar 9, 2024
5acc06c
Do not ship packaged .aasx test files
s-heppner Mar 9, 2024
2830d26
test_compliance_check_aasx: Fix outdated test-case
s-heppner Mar 9, 2024
23750f0
CI: Fix mypy call
s-heppner Mar 9, 2024
c62ecfd
compliance_check_xml: Fix codestyle
s-heppner Mar 9, 2024
302312f
Add NOTICE for third party files inside the repository
s-heppner Mar 9, 2024
c976e4d
Update Release CI Pipeline to use PyPI's new trusted publishing
s-heppner Mar 15, 2024
978b3bc
Update README.md
s-heppner Apr 2, 2024
200ac64
Merge remote-tracking branch 'compliance-tool/main' into add_complian…
Frosty2500 Sep 16, 2024
0540a3a
Add compliance-tool to basyx-python-sdk
Frosty2500 Sep 16, 2024
30df863
Merge branch 'eclipse-basyx:main' into add_compliance-tool
Frosty2500 Sep 17, 2024
14d520b
Merge branch 'eclipse-basyx:main' into add_compliance-tool
Frosty2500 Oct 22, 2024
5fb5286
Merge branch 'eclipse-basyx:main' into add_compliance-tool
Frosty2500 Nov 5, 2024
00243b1
adapt ci
Frosty2500 Nov 5, 2024
d814e3d
adapt ci
Frosty2500 Nov 5, 2024
2205615
adapt ci mypy
Frosty2500 Nov 5, 2024
9ce9861
adapt ci remove hyphen
Frosty2500 Nov 5, 2024
103f14d
Merge branch 'eclipse-basyx:main' into add_compliance-tool
Frosty2500 Nov 28, 2024
42a4e19
Merge branch 'main' into add_compliance-tool
Frosty2500 Dec 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,110 @@ jobs:
run: |
python -m build


compliance-tool-test:
# This job runs the unittests on the python versions specified down at the matrix
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.10", "3.12"]
defaults:
run:
working-directory: ./compliance_tool

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install coverage
pip install -r requirements.txt
- name: Test with coverage + unittest
run: |
coverage run --source=aas_compliance_tool -m unittest
- name: Report test coverage
if: ${{ always() }}
run: |
coverage report -m

compliance-tool-static-analysis:
# This job runs static code analysis, namely pycodestyle and mypy
runs-on: ubuntu-latest

defaults:
run:
working-directory: ./compliance_tool
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ env.X_PYTHON_VERSION }}
uses: actions/setup-python@v2
with:
python-version: ${{ env.X_PYTHON_VERSION }}
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install pycodestyle mypy
pip install -r requirements.txt
- name: Check typing with MyPy
run: |
mypy ./aas_compliance_tool test
- name: Check code style with PyCodestyle
run: |
pycodestyle --count --max-line-length 120 ./aas_compliance_tool test

compliance-tool-readme-codeblocks:
# This job runs the same static code analysis (mypy and pycodestyle) on the codeblocks in our docstrings.
runs-on: ubuntu-latest

defaults:
run:
working-directory: ./compliance_tool
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ env.X_PYTHON_VERSION }}
uses: actions/setup-python@v2
with:
python-version: ${{ env.X_PYTHON_VERSION }}
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install pycodestyle mypy codeblocks
pip install -r requirements.txt
- name: Check typing with MyPy
run: |
mypy <(codeblocks python README.md)
- name: Check code style with PyCodestyle
run: |
codeblocks --wrap python README.md | pycodestyle --count --max-line-length 120 -
- name: Run readme codeblocks with Python
run: |
codeblocks python README.md | python

compliance-tool-package:
# This job checks if we can build our compliance_tool package
runs-on: ubuntu-latest

defaults:
run:
working-directory: ./compliance_tool
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ env.X_PYTHON_VERSION }}
uses: actions/setup-python@v2
with:
python-version: ${{ env.X_PYTHON_VERSION }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel
- name: Create source and wheel dist
run: |
python setup.py sdist bdist_wheel

server-package:
# This job checks if we can build our server package
runs-on: ubuntu-latest
Expand Down Expand Up @@ -212,3 +316,4 @@ jobs:
- name: Stop and remove the container
run: |
docker stop basyx-python-server && docker rm basyx-python-server

27 changes: 27 additions & 0 deletions compliance_tool/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Python caching
**/__pycache__/
*.pyc
/.mypy_cache/

# Typical virtualenv dir
/venv/

# IDE settings
/.idea/

# Python distribution artifacts
/build/
/dist/
/*.egg-info/
/docs/build/

# Coverage artifacts
/.coverage
/htmlcov/
/docs/build/

# customized config files
/test/test_config.ini

# Do not ship the dynamicylly packaged aasx files in the `test/files`
/test/files/*.aasx
21 changes: 21 additions & 0 deletions compliance_tool/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 IAT, RWTH Aachen University

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
18 changes: 18 additions & 0 deletions compliance_tool/NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Declared Project License
------------------------
The artifacts of this project are made available under the terms of the MIT License.
Please refer to the LICENSE file for more information.


Third-party Work in this Repository
-----------------------------------
This project includes XSD and JSON Schema files, developed by IDTA and published
at https://github.com/admin-shell-io/aas-specs/

under the terms of the Creative Commons Attribution 4.0 International (CC-BY-4.0)
https://github.com/admin-shell-io/aas-specs/?tab=CC-BY-4.0-1-ov-file#readme

These files are located at
- `aas_compliance_tool/schemas/aasJSONSchema.json` and
- `aas_compliance_tool/schemas/aasXMLSchema.xsd`.

17 changes: 17 additions & 0 deletions compliance_tool/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# AAS Compliance Tool
An AAS compliance checker based on the [Eclipse BaSyx Python SDK](https://github.com/eclipse-basyx/basyx-python-sdk) for testing XML and JSON files.
Following functionalities are supported:

* create an xml or json file compliant to the official schema containing example Asset Administration Shell elements
* create an aasx file with xml or json files compliant to the official schema containing example Asset Administration
Shell elements
* check if a given xml or json file is compliant to the official schema
* check if a given xml, json or aasx file is readable even if it is not compliant to the offical schema
* check if the data in a given xml, json or aasx file is the same as the example data
* check if two given xml, json or aasx files contain the same Asset Administration Shell elements in any order

Invoking should work with either `python -m aas_compliance_tool.cli` or (when installed correctly and PATH is set
correctly) with `aas-compliance-check` on the command line.

For further usage information consider the `aas_compliance_tool`-package or invoke with
`python -m aas_compliance_tool.cli --help` respectively `aas-compliance-check --help`.
Empty file added compliance_tool/__init__.py
Empty file.
Empty file.
195 changes: 195 additions & 0 deletions compliance_tool/aas_compliance_tool/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
# Copyright (c) 2020 the Eclipse BaSyx Authors
#
# This program and the accompanying materials are made available under the terms of the MIT License, available in
# the LICENSE file of this project.
#
# SPDX-License-Identifier: MIT

"""
Command line script which is a compliance tool for creating and checking json and xml files in compliance with
"Details of the Asset Administration Shell" specification of Plattform Industrie 4.0. It uses the create_example() from
examples.data.__init__.py
"""
import argparse
import datetime

import logging

import pyecma376_2

from basyx.aas.adapter import aasx
from basyx.aas.adapter.xml import write_aas_xml_file
from basyx.aas.compliance_tool import compliance_check_xml as compliance_tool_xml, \
compliance_check_json as compliance_tool_json, compliance_check_aasx as compliance_tool_aasx
from basyx.aas.adapter.json import write_aas_json_file
from basyx.aas.examples.data import create_example, create_example_aas_binding, TEST_PDF_FILE
from basyx.aas.compliance_tool.state_manager import ComplianceToolStateManager, Status


def parse_cli_arguments() -> argparse.ArgumentParser:
"""
This function returns the argument-parser for the cli
"""
parser = argparse.ArgumentParser(
prog='compliance_tool',
description='Compliance tool for creating and checking json and xml files in compliance with "Details of the '
'Asset Administration Shell" specification of Plattform Industrie 4.0. \n\n'
'This tool has five features: \n'
'1. create a xml or json file or an AASX file using xml or json files with example aas elements\n'
'2. check if a given xml or json file is compliant with the official json or xml aas schema and '
'is deserializable\n'
'3. check if the data in a given xml, json or aasx file is the same as the example data\n'
'4. check if two given xml, json or aasx files contain the same aas elements in any order\n\n'
'As a first argument, the feature must be specified (create, schema, deserialization, example, '
'files) or in short (c, s, d, e or f).\n'
'Depending the chosen feature, different additional arguments must be specified:\n'
'create or c: path to the file which shall be created (file_1)\n'
'deseriable or d: file to be checked (file_1)\n'
'example or e: file to be checked (file_1)\n'
'file_compare or f: files to compare (file_1, file_2)\n,'
'In any case, it must be specified whether the (given or created) files are json (--json) or '
'xml (--xml).\n'
'All features except "schema" support reading/writing AASX packages instead of plain XML or JSON '
'files via the --aasx option.\n\n'
'Additionally, the tool offers some extra features for more convenient usage:\n\n'
'a. Different levels of verbosity:\n'
' Default output is just the status for each step performed. With -v or --verbose, additional '
'information in case of status = FAILED will be provided. With one more -v or --verbose, additional'
' information even in case of status = SUCCESS or WARNINGS will be provided.\n'
'b. Suppressing output on success:\n'
' With -q or --quite no output will be generated if the status = SUCCESS.\n'
'c. Save log additionally in a logfile:\n'
' With -l or --logfile, a path to the file where the logfiles shall be created can be specified.',
formatter_class=argparse.RawTextHelpFormatter)

parser.add_argument('action', choices=['create', 'c', 'schema', 's', 'deserialization', 'd', 'example', 'e',
'files', 'f'],
help='c or create: creates a file with example data\n'
'd or deserialization: checks if a given file is compliance with the official schema and '
'is deserializable\n'
'e or example: checks if a given file contains the example aas elements\n'
'f or file_compare: checks if two given files contain the same aas elements in any order')
parser.add_argument('file_1', help="path to file 1")
parser.add_argument('file_2', nargs='?', default=None, help="path to file 2: is required if action f or files is "
"choosen")
parser.add_argument('-v', '--verbose', help="Print detailed information for each check. Multiple -v options "
"increase the verbosity. 1: Detailed error information, 2: Additional "
"detailed success information", action='count', default=0)
parser.add_argument('-q', '--quite', help="no information output if successful", action='store_true')
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument('--json', help="Use AAS json format when checking or creating files", action='store_true')
group.add_argument('--xml', help="Use AAS xml format when checking or creating files", action='store_true')
parser.add_argument('-l', '--logfile', help="Log file to be created in addition to output to stdout", default=None)
parser.add_argument('--aasx', help="Create or read AASX files", action='store_true')
parser.add_argument('--dont-check-extensions', help="Don't compare Extensions", action='store_false')
return parser


def main():
parser = parse_cli_arguments()
args = parser.parse_args()

# Todo try to find out in which format the file is if not --json or --xml

manager = ComplianceToolStateManager()
logger = logging.getLogger(__name__)
logger.propagate = False
logger.addHandler(manager)

data_checker_kwargs = {
'check_extensions': args.dont_check_extensions
}

if args.action == 'create' or args.action == 'c':
manager.add_step('Create example data')
if args.aasx:
data = create_example_aas_binding()
else:
data = create_example()
manager.set_step_status(Status.SUCCESS)
try:
manager.add_step('Open file')
if args.aasx:
with aasx.AASXWriter(args.file_1) as writer:
manager.set_step_status(Status.SUCCESS)
manager.add_step('Write data to file')

files = aasx.DictSupplementaryFileContainer()
with open(TEST_PDF_FILE, 'rb') as f:
files.add_file("/TestFile.pdf", f, "application/pdf")

# Create OPC/AASX core properties
cp = pyecma376_2.OPCCoreProperties()
cp.created = datetime.datetime(2020, 1, 1, 0, 0, 0)
cp.creator = "Eclipse BaSyx Python Testing Framework"
cp.description = "Test_Description"
cp.lastModifiedBy = "Eclipse BaSyx Python Testing Framework Compliance Tool"
cp.modified = datetime.datetime(2020, 1, 1, 0, 0, 1)
cp.revision = "1.0"
cp.version = "2.0.1"
cp.title = "Test Title"

writer.write_aas_objects("/aasx/data.json" if args.json else "/aasx/data.xml",
[obj.id for obj in data], data, files,
write_json=args.json)
writer.write_core_properties(cp)
manager.set_step_status(Status.SUCCESS)
elif args.json:
with open(args.file_1, 'w', encoding='utf-8-sig') as file:
manager.set_step_status(Status.SUCCESS)
manager.add_step('Write data to file')
write_aas_json_file(file=file, data=data, indent=4)
manager.set_step_status(Status.SUCCESS)
elif args.xml:
with open(args.file_1, 'wb') as file:
manager.set_step_status(Status.SUCCESS)
manager.add_step('Write data to file')
write_aas_xml_file(file=file, data=data, pretty_print=True)
manager.set_step_status(Status.SUCCESS)
except IOError as error:
logger.error(error)
manager.set_step_status(Status.FAILED)
elif args.action == 'deserialization' or args.action == 'd':
if args.aasx:
compliance_tool_aasx.check_deserialization(args.file_1, manager)
elif args.json:
compliance_tool_json.check_deserialization(args.file_1, manager)
elif args.xml:
compliance_tool_xml.check_deserialization(args.file_1, manager)
elif args.action == 'example' or args.action == 'e':
if args.aasx:
compliance_tool_aasx.check_aas_example(args.file_1, manager, **data_checker_kwargs)
elif args.json:
compliance_tool_json.check_aas_example(args.file_1, manager, **data_checker_kwargs)
elif args.xml:
compliance_tool_xml.check_aas_example(args.file_1, manager, **data_checker_kwargs)
elif args.action == 'files' or args.action == 'f':
if args.file_2:
if args.aasx:
compliance_tool_aasx.check_aasx_files_equivalence(args.file_1, args.file_2, manager,
**data_checker_kwargs)
elif args.json:
compliance_tool_json.check_json_files_equivalence(args.file_1, args.file_2, manager,
**data_checker_kwargs)
elif args.xml:
compliance_tool_xml.check_xml_files_equivalence(args.file_1, args.file_2, manager,
**data_checker_kwargs)
else:
parser.error("f or files requires two file path.")
exit()

if manager.status is Status.SUCCESS and args.quite:
exit()

print(manager.format_state_manager(args.verbose))

if args.logfile:
try:
with open(args.logfile, 'w', encoding='utf-8-sig') as file:
file.write(manager.format_state_manager(args.verbose))
except IOError as error:
print('Could not open logfile: \n{}'.format(error))


if __name__ == "__main__":
main()
Loading
Loading