# dsconfig-wrapper
[![pipeline status](https://gitlab.desy.de/cfel-sc-public/dsconfig-wrapper/badges/main/pipeline.svg)](https://gitlab.desy.de/cfel-sc-public/dsconfig-wrapper/-/commits/main)
[![coverage report](https://gitlab.desy.de/cfel-sc-public/dsconfig-wrapper/badges/main/coverage.svg)](https://gitlab.desy.de/cfel-sc-public/dsconfig-wrapper/-/commits/main)
This is a small Python library to complement [MAX IV's](https://www.maxiv.lu.se/) excellent [dsconfig](https://gitlab.com/MaxIV/lib-maxiv-dsconfig) library, which can make the database for the [Tango](https://www.tango-controls.org/) controls system *declarative* by updating it from a JSON file.
Usually, it looks like this:
```mermaid
flowchart TD
DatabaseDs[(Tango Database)]
DatabaseDs -->|dsconfig.dump| JsonFile[JSON file]
Human -->|vim/emacs| JsonFile
JsonFile -->|json2tango| DatabaseDs
```
With this tool, it looks like this:
```mermaid
flowchart TD
DatabaseDs[(Tango Database)]
Human -->|vim/emacs| PythonFile[Python file]
DsconfigWrapper[dsconfig-wrapper] -->|import| PythonFile
PythonFile -->|dsconfig-wrapper| JsonFile
JsonFile -->|json2tango| DatabaseDs
```
This way, we can have our configuration not in JSON, but in Python! And in Python, we can have, for instance, `argparse`, to create a little program that can generate a configuration with parameters. You can also use Python DRY elements in your configuration (say, you have the same motor, but with various different properties set).
## Usage
Just do
```
pip install dsconfig-wrapper
```
and then use it to create a config JSON. Example:
```python
test_servers = [
Server(
instance_name="my_instance_name",
class_name="my_class_name",
devices=[
Device(
identifier=Identifier(
domain="my_domain",
family="my_family",
member="my_member",
host="my_host:10000",
),
properties={
"prop_str": "strvalue",
"prop_list_str": ["value1", "value2"],
"prop_list_int": [2000, 3000],
"prop_int": 2000,
},
polled_commands={"update": 1000},
attribute_properties={
"State": AttributeProperties(archive_period_ms=1001),
"velocity_mm_per_s": AttributeProperties(
archive_abs_change=(-0.5, 0.5),
archive_period_ms=5000,
rel_change=(-0.05, 0.05),
),
},
)
],
)
]
test_config = Config(servers=test_servers)
print(config_to_json(test_config))
```
Here, we create a config for a device server with class `my_class_name` and one instance running at `tango://myhost:10000/my_domain/my_family/my_member`. The `update` command is polled every second, and we also set some properties and attribute properties.
We now run this program (say it's stored in `main.py`) and pipe it into dsconfig:
```
python main.py | json2tango
```
Voila!
Raw data
{
"_id": null,
"home_page": "https://gitlab.desy.de/cfel-sc-public/dsconfig-wrapper",
"name": "dsconfig-wrapper",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.10,<3.12",
"maintainer_email": "",
"keywords": "Tango",
"author": "CFEL-SC",
"author_email": "sc@cfel.de",
"download_url": "https://files.pythonhosted.org/packages/71/16/9558ce281b566e0f1e1d75600f752994157e278cfaa6f682ed451eb5e505/dsconfig_wrapper-1.1.0.tar.gz",
"platform": null,
"description": "# dsconfig-wrapper\n\n[![pipeline status](https://gitlab.desy.de/cfel-sc-public/dsconfig-wrapper/badges/main/pipeline.svg)](https://gitlab.desy.de/cfel-sc-public/dsconfig-wrapper/-/commits/main) \n[![coverage report](https://gitlab.desy.de/cfel-sc-public/dsconfig-wrapper/badges/main/coverage.svg)](https://gitlab.desy.de/cfel-sc-public/dsconfig-wrapper/-/commits/main)\n\nThis is a small Python library to complement [MAX IV's](https://www.maxiv.lu.se/) excellent [dsconfig](https://gitlab.com/MaxIV/lib-maxiv-dsconfig) library, which can make the database for the [Tango](https://www.tango-controls.org/) controls system *declarative* by updating it from a JSON file.\n\nUsually, it looks like this:\n\n```mermaid\nflowchart TD\n DatabaseDs[(Tango Database)]\n DatabaseDs -->|dsconfig.dump| JsonFile[JSON file]\n Human -->|vim/emacs| JsonFile\n JsonFile -->|json2tango| DatabaseDs\n```\n\nWith this tool, it looks like this:\n\n```mermaid\nflowchart TD\n DatabaseDs[(Tango Database)]\n Human -->|vim/emacs| PythonFile[Python file]\n DsconfigWrapper[dsconfig-wrapper] -->|import| PythonFile\n PythonFile -->|dsconfig-wrapper| JsonFile\n JsonFile -->|json2tango| DatabaseDs\n```\n\nThis way, we can have our configuration not in JSON, but in Python! And in Python, we can have, for instance, `argparse`, to create a little program that can generate a configuration with parameters. You can also use Python DRY elements in your configuration (say, you have the same motor, but with various different properties set).\n\n## Usage\n\nJust do\n\n```\npip install dsconfig-wrapper\n```\n\nand then use it to create a config JSON. Example:\n\n```python\ntest_servers = [\n Server(\n instance_name=\"my_instance_name\",\n class_name=\"my_class_name\",\n devices=[\n Device(\n identifier=Identifier(\n domain=\"my_domain\",\n family=\"my_family\",\n member=\"my_member\",\n host=\"my_host:10000\",\n ),\n properties={\n \"prop_str\": \"strvalue\",\n \"prop_list_str\": [\"value1\", \"value2\"],\n \"prop_list_int\": [2000, 3000],\n \"prop_int\": 2000,\n },\n polled_commands={\"update\": 1000},\n attribute_properties={\n \"State\": AttributeProperties(archive_period_ms=1001),\n \"velocity_mm_per_s\": AttributeProperties(\n archive_abs_change=(-0.5, 0.5),\n archive_period_ms=5000,\n rel_change=(-0.05, 0.05),\n ),\n },\n )\n ],\n )\n]\ntest_config = Config(servers=test_servers)\nprint(config_to_json(test_config))\n```\n\nHere, we create a config for a device server with class `my_class_name` and one instance running at `tango://myhost:10000/my_domain/my_family/my_member`. The `update` command is polled every second, and we also set some properties and attribute properties.\n\nWe now run this program (say it's stored in `main.py`) and pipe it into dsconfig:\n\n```\npython main.py | json2tango\n```\n\nVoila!\n",
"bugtrack_url": null,
"license": "GPL-3.0-or-later",
"summary": "Wraps MAX IV's dsconfig JSON generator to let the user use Python to generate the config",
"version": "1.1.0",
"project_urls": {
"Homepage": "https://gitlab.desy.de/cfel-sc-public/dsconfig-wrapper",
"Repository": "https://gitlab.desy.de/cfel-sc-public/dsconfig-wrapper"
},
"split_keywords": [
"tango"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "66fe174f693216ed47a5e53eab73d0a5e47a13b79fa5421f1a5e773debf295fe",
"md5": "4c755e2da81553fa8b709b25e1dca481",
"sha256": "41ba2cd8b8055007978570f631c07743bb70398afb10e5d820f77d855068fc87"
},
"downloads": -1,
"filename": "dsconfig_wrapper-1.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "4c755e2da81553fa8b709b25e1dca481",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10,<3.12",
"size": 16325,
"upload_time": "2023-08-29T08:57:27",
"upload_time_iso_8601": "2023-08-29T08:57:27.584517Z",
"url": "https://files.pythonhosted.org/packages/66/fe/174f693216ed47a5e53eab73d0a5e47a13b79fa5421f1a5e773debf295fe/dsconfig_wrapper-1.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "71169558ce281b566e0f1e1d75600f752994157e278cfaa6f682ed451eb5e505",
"md5": "cbc2d9f9f4b0d50cebdd6e28e8bfab97",
"sha256": "03c35c7a1896c6cdc35bb532b9c25a200acc0ad6b01cc8d628974d388c0609b2"
},
"downloads": -1,
"filename": "dsconfig_wrapper-1.1.0.tar.gz",
"has_sig": false,
"md5_digest": "cbc2d9f9f4b0d50cebdd6e28e8bfab97",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10,<3.12",
"size": 17098,
"upload_time": "2023-08-29T08:57:28",
"upload_time_iso_8601": "2023-08-29T08:57:28.786119Z",
"url": "https://files.pythonhosted.org/packages/71/16/9558ce281b566e0f1e1d75600f752994157e278cfaa6f682ed451eb5e505/dsconfig_wrapper-1.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-08-29 08:57:28",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "dsconfig-wrapper"
}