| 1 |
Provisioning (advanced) |
| 2 |
======================= |
| 3 |
|
| 4 |
Plugins can be configured by talking to the bot with:: |
| 5 |
|
| 6 |
!plugin config my_plugin {'key': 'value'} |
| 7 |
|
| 8 |
Also plugins can store values in the storage as key value pairs. |
| 9 |
|
| 10 |
Sometimes, you need to inject those values either config or plugin state |
| 11 |
ahead of time for example at errbot installation (also called provisioning). |
| 12 |
|
| 13 |
It is useful for installation scripts and deployments. |
| 14 |
|
| 15 |
.. note:: |
| 16 |
When using the default "Shelf storage", errbot may not be running when |
| 17 |
attempting to get or set data. Any attempt to do so while the bot is |
| 18 |
running will result in the error "Storage does not appear to have been |
| 19 |
opened yet" being returned. This is caused by the fact that the python |
| 20 |
`shelve` module only allows a single process to hold the database open. |
| 21 |
For further details, see the |
| 22 |
`shelve docs <https://docs.python.org/3/library/shelve.html#restrictions>`_. |
| 23 |
|
| 24 |
|
| 25 |
Reading stored values |
| 26 |
--------------------- |
| 27 |
|
| 28 |
To read the current stored plugin configs you can do from the command line:: |
| 29 |
|
| 30 |
errbot --storage-get core |
| 31 |
|
| 32 |
It will give you on stdout a python dictionary of the core namespace like:: |
| 33 |
|
| 34 |
{'configs': {'Webserver': {'PORT': 8888}}} |
| 35 |
|
| 36 |
To read the values from a plugin storage, for example here from alimac/err-factoid you can do:: |
| 37 |
|
| 38 |
errbot --storage-get Factoid |
| 39 |
|
| 40 |
It will give you on stdout a similar output:: |
| 41 |
|
| 42 |
{'FACTOID': {'fire': 'burns', 'water': 'wet'}} |
| 43 |
|
| 44 |
|
| 45 |
Writing values |
| 46 |
-------------- |
| 47 |
|
| 48 |
To add or change specific values without touching others you can merge a dictionary like that:: |
| 49 |
|
| 50 |
echo "{'configs': {'Webserver': {'PORT': 9999}}}" | errbot --storage-merge core |
| 51 |
|
| 52 |
Checking back:: |
| 53 |
|
| 54 |
errbot --storage-get core |
| 55 |
{'configs': {'Webserver': {'PORT': 9999}}} |
| 56 |
|
| 57 |
Changing facts in Factoid (note the merge is only on the first level so we change all FACTOID here):: |
| 58 |
|
| 59 |
echo "{'FACTOID': {'errbot': 'awesome'}}" | errbot --storage-merge Factoid |
| 60 |
|
| 61 |
>>> !errbot? |
| 62 |
errbot is awesome |
| 63 |
|
| 64 |
You can use --storage-set in the same fashion but it will erase first the namespace before writing your values. |