# bifrost-common
A library of commonly used functions to interact with BIFROST. Useful for module developers.
## Installation
```
pip install bifrost-common-py
```
## Components
### Log
A module to print nice logging information to the console and, optionally, to files.
```
from bifrost_common_py.Log import Log
log = Log('myComponent', 'myApplication', options={'maxLogFileSize':1e4, 'enableLogFiles':True})
log.write(`Abandon ship`, Log.WARNING)
log.write(`Run like hell`, Log.INFO)
```
Log levels are `DEBUG`, `INFO`, `WARNING`, `ERROR`, `FAILURE`
Allowed `options` are:
- `enableLogFiles` (default: `false`): log to files as well as the console
- `logDir` (default: `log`): the log file directory (will be created as necessary)
- `maxLogFileSize` (default: `0`): maximum byte size of the log files, after which a new file will be started, default =`0` never rollover
- `maxArchiveSize`(default: 5): maximum number of log files to keep
### time
Some useful operations involving time, mostly for formatting `Log` output.
### idOfRef
Resolve the ID contained in an object. If no 'id' field is found in the
object pointed to with `ref`, the last part of the reference is returned instead.
```
from bifrost_common_py.idOfRef import idOfRef
print(idOfRef({ 'A': { 'id': '1' }}, '/A')) // '1'
```
### tokens
An object collecting string tokens commonly used in the BIFROST state.
```
import bifrost_common_py.tokens as tokens
print(tokens.tkId) // "id"
```
### select
Selectors returning fully-qualified JSON paths into the BIFROST state.
```
import bifrost_common_py.pathSelectors as select
print(select.meta()) # "/meta"
print(select.dynamicId('DYNAMIC-1')) # "/dynamics/byId/DYNAMIC-1"
print(select.eventParentRef('EVENT-1')) # "/events/byId/EVENT-1/parentRef"
```
### safepointer
A wrapper that allows to specify default values if paths can not be resolved. This is best used in conjunction with `select` and a copy of the BIFROST state.
#### API
```
import bifrost_common_py.safepointer
```
##### .has(obj, path)
Determine whether the fully-qualified JSON pointer `path` points to something in `obj`.
```
safepointer.has({ 'A': { 'B': 1} }, '/A/B') # true
safepointer.has({ 'A': { 'B': 1} }, '/A/C') # false
```
##### .get(obj, path, def = null)
Resolve `path` against `obj`. If the path does not exist, `def` is returned instead.
```
safepointer.get({ 'A': { 'B': 1} }, '/A/B', 0) # 1
safepointer.get({ 'A': { 'B': 1} }, '/A/C', 0) # 0
import bifrost_common_py.pathSelectors as select
safepointer.get(state, select.meta(), {}) // { id: ... }
```
### SelectFrom
A declarative state selection library. Use this to select elements from the BIFROST state or from module subscription data.
```
from bifrost_common_py.SelectFrom import SelectFrom
SelectFrom(state).allDynamics().ofType('VOLTAGE-3P').asValueMap()
SelectFrom(subs).allEntries().ofType('CLIMATE-MODEL').asValueList()
SelectFrom(subs, state).allEntries().withParentOfType('WEATHER').asValueMap()
```
Raw data
{
"_id": null,
"home_page": "https://bifrost.siemens.com/en",
"name": "bifrost-common-py",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "bifrost,bifrost-common",
"author": "Manuel Matzinger",
"author_email": "bifrost.at@siemens.com",
"download_url": "https://files.pythonhosted.org/packages/95/3e/a6e9221c9edc2bb007db5ff985fe8184c202a3f0747f23de56066ef0eb1d/bifrost_common_py-0.8.tar.gz",
"platform": null,
"description": "# bifrost-common\r\n\r\nA library of commonly used functions to interact with BIFROST. Useful for module developers.\r\n\r\n## Installation\r\n\r\n```\r\npip install bifrost-common-py\r\n```\r\n\r\n## Components\r\n\r\n### Log\r\n\r\nA module to print nice logging information to the console and, optionally, to files.\r\n\r\n```\r\nfrom bifrost_common_py.Log import Log\r\n\r\nlog = Log('myComponent', 'myApplication', options={'maxLogFileSize':1e4, 'enableLogFiles':True})\r\n\r\nlog.write(`Abandon ship`, Log.WARNING)\r\nlog.write(`Run like hell`, Log.INFO)\r\n```\r\n\r\nLog levels are `DEBUG`, `INFO`, `WARNING`, `ERROR`, `FAILURE`\r\n\r\nAllowed `options` are:\r\n- `enableLogFiles` (default: `false`): log to files as well as the console\r\n- `logDir` (default: `log`): the log file directory (will be created as necessary)\r\n- `maxLogFileSize` (default: `0`): maximum byte size of the log files, after which a new file will be started, default =`0` never rollover\r\n- `maxArchiveSize`(default: 5): maximum number of log files to keep\r\n\r\n### time\r\n\r\nSome useful operations involving time, mostly for formatting `Log` output.\r\n\r\n### idOfRef\r\n\r\nResolve the ID contained in an object. If no 'id' field is found in the\r\nobject pointed to with `ref`, the last part of the reference is returned instead.\r\n\r\n```\r\nfrom bifrost_common_py.idOfRef import idOfRef\r\n\r\nprint(idOfRef({ 'A': { 'id': '1' }}, '/A')) // '1'\r\n\r\n```\r\n\r\n### tokens\r\n\r\nAn object collecting string tokens commonly used in the BIFROST state.\r\n\r\n```\r\nimport bifrost_common_py.tokens as tokens\r\n\r\nprint(tokens.tkId) // \"id\"\r\n```\r\n\r\n### select\r\n\r\nSelectors returning fully-qualified JSON paths into the BIFROST state.\r\n\r\n```\r\nimport bifrost_common_py.pathSelectors as select\r\n\r\nprint(select.meta()) # \"/meta\"\r\nprint(select.dynamicId('DYNAMIC-1')) # \"/dynamics/byId/DYNAMIC-1\"\r\nprint(select.eventParentRef('EVENT-1')) # \"/events/byId/EVENT-1/parentRef\"\r\n```\r\n\r\n### safepointer\r\n\r\nA wrapper that allows to specify default values if paths can not be resolved. This is best used in conjunction with `select` and a copy of the BIFROST state.\r\n\r\n#### API\r\n\r\n```\r\nimport bifrost_common_py.safepointer\r\n```\r\n\r\n##### .has(obj, path)\r\n\r\nDetermine whether the fully-qualified JSON pointer `path` points to something in `obj`.\r\n\r\n```\r\nsafepointer.has({ 'A': { 'B': 1} }, '/A/B') # true\r\nsafepointer.has({ 'A': { 'B': 1} }, '/A/C') # false\r\n```\r\n\r\n##### .get(obj, path, def = null)\r\n\r\nResolve `path` against `obj`. If the path does not exist, `def` is returned instead.\r\n\r\n```\r\nsafepointer.get({ 'A': { 'B': 1} }, '/A/B', 0) # 1\r\nsafepointer.get({ 'A': { 'B': 1} }, '/A/C', 0) # 0\r\n\r\nimport bifrost_common_py.pathSelectors as select\r\n\r\nsafepointer.get(state, select.meta(), {}) // { id: ... }\r\n```\r\n\r\n### SelectFrom\r\n\r\nA declarative state selection library. Use this to select elements from the BIFROST state or from module subscription data.\r\n\r\n```\r\n from bifrost_common_py.SelectFrom import SelectFrom\r\n\r\n SelectFrom(state).allDynamics().ofType('VOLTAGE-3P').asValueMap()\r\n\r\n SelectFrom(subs).allEntries().ofType('CLIMATE-MODEL').asValueList()\r\n\r\n SelectFrom(subs, state).allEntries().withParentOfType('WEATHER').asValueMap()\r\n```\r\n",
"bugtrack_url": null,
"license": "",
"summary": "Common python library functions for interacting with BIFROST.",
"version": "0.8",
"split_keywords": [
"bifrost",
"bifrost-common"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f25db2ff8d95067d943cf11fb5b6ff5e7dfe0fa07d8e53a4c1fe91e430070a96",
"md5": "0a344f4e1a7b3b431e7f26a534041f35",
"sha256": "accc2800fd6d705fde52e98b67e11b86850def3fec4a7b19e9431d00c186f64b"
},
"downloads": -1,
"filename": "bifrost_common_py-0.8-py3-none-any.whl",
"has_sig": false,
"md5_digest": "0a344f4e1a7b3b431e7f26a534041f35",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 20096,
"upload_time": "2023-04-14T10:43:57",
"upload_time_iso_8601": "2023-04-14T10:43:57.638912Z",
"url": "https://files.pythonhosted.org/packages/f2/5d/b2ff8d95067d943cf11fb5b6ff5e7dfe0fa07d8e53a4c1fe91e430070a96/bifrost_common_py-0.8-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "953ea6e9221c9edc2bb007db5ff985fe8184c202a3f0747f23de56066ef0eb1d",
"md5": "e577f4fdf33c74b8050e5d8b82f5e5a5",
"sha256": "5f0993acc3eacb81680e0faf183b35da7b0acb9058753e3f796ca79a89d87ebf"
},
"downloads": -1,
"filename": "bifrost_common_py-0.8.tar.gz",
"has_sig": false,
"md5_digest": "e577f4fdf33c74b8050e5d8b82f5e5a5",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 18434,
"upload_time": "2023-04-14T10:44:04",
"upload_time_iso_8601": "2023-04-14T10:44:04.023494Z",
"url": "https://files.pythonhosted.org/packages/95/3e/a6e9221c9edc2bb007db5ff985fe8184c202a3f0747f23de56066ef0eb1d/bifrost_common_py-0.8.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-04-14 10:44:04",
"github": false,
"gitlab": false,
"bitbucket": false,
"lcname": "bifrost-common-py"
}