Skip to content
This repository has been archived by the owner on Sep 8, 2024. It is now read-only.

Use a static custom settings file to save user informationn #2712

Closed
damorosodaragona opened this issue Oct 1, 2020 · 6 comments
Closed
Labels
Status: For discussion Feature proposal in development. Community input and discussion is invited. Type: Enhancement - proposed New proposal for a feature that is not currently a priority on the roadmap.

Comments

@damorosodaragona
Copy link

damorosodaragona commented Oct 1, 2020

I'm in trouble with this problem: I need to create a user id card where put some information about it, like name, surname, age, and so on.
I tried to add my own custom file a the mycroft main level called userinfo.conf, i added a class in configuration.py, locations.py and init.py to load this conf file with the other mycroft configurations file.
The loading work very well, I just used the existent classes in configuration.py to create my class to load the file.
But I'm in trouble with the consistency of the information saved on my own configuration file.
Let me explain: if i have a skill to set the name of the user, the skill sets the name of the user, using the dict given by MycroftSkill (config_core) and then calling a mine own method in configuration.py class to save this info on my own conf file.
But the problem is that cause the dict where MycroftSkill save the configuration information is not static, if a change the value in that dict, all the others skills can't see the new value, because they load the configuration information at creation time so where the MycroftSkill constructor is called.
I need something that all skills can be seen and that is consistent over all the skills, so that if a skill changes the same value, then that value is visible by all other skills.

I know that all skills have a configuration file to save some value, but if i have a skill for the name, one for the age, and so on and i save each info on proper skill configuration file, then the access to the info is very useless because I have the info fragmented in different skills configuration files.

What is the right way to solve this problem? I also want to avoid access to this hypothetic file every time I need to read some info, For example, if all my skills use the name value to call the user by name during the interaction, i don't want that each skill every time open a stream to the file to read the value.
for this reason i tried to exploit the mycroft pattern about configuration.

@JarbasAl
Copy link
Contributor

JarbasAl commented Oct 1, 2020

i suggest that you do not edit the source code for such a trivial thing

maybe look into https://github.com/HelloChatterbox/json_database

but to answer your questions, you can send a bus message "configuration.patch", {"config": new_config} that updates all configs across mycroft (does not save to disk)

@damorosodaragona
Copy link
Author

damorosodaragona commented Oct 1, 2020

I agree with you.
I tried this solution but i don't want force the natural behaviour of Mycroft, so i retrace my steps.
to reload the conf i used "Configuration.patch() " but also in this way i'm changing the natural behaviour of Mycroft, and then this means that every time a skill have to call this configuration function.
Just for curiosity, about message bus can you explain better? What value i have to pass as "config" and what as "new_config" ?

About json database my problem is how to load this database across over the skills and have this database consistent over all the skills in each moment, also if a skill modify some values.

@forslund
Copy link
Collaborator

forslund commented Oct 1, 2020

You should be able to do like this from a skill:

Import the Message class

from mycroft.messagebus import Message¨

Then in the initialize method of your skill have

    patch = {'user': 'arthur dent', 'password': 'yellow42'}
    self.bus.emit(Message('configuration.patch', {'config': patch}))

@damorosodaragona
Copy link
Author

I'm thinking to create a my skill class that extends MycroftSkill Class and have in it a static dict only for the information about the user that i need, as well as a methods to load and write info on a file.

In this way i have just to put this myclass on the same folder of Mycroftskill such a way that all skills can see it and extend it.
In this way, been the dict static, all the skills have in each moment the same value, also if another skill modifies one value on the dict.

@krisgesling
Copy link
Contributor

It sounds like this will be a good use of the Skill API proposed in PR #1822

Rather than making the data structure available to all Skills, you could expose an API to interact with that data.

Would that address the use case you're looking at?

@krisgesling krisgesling added Status: For discussion Feature proposal in development. Community input and discussion is invited. Type: Enhancement - proposed New proposal for a feature that is not currently a priority on the roadmap. labels Dec 9, 2020
@forslund
Copy link
Collaborator

forslund commented Sep 8, 2024

Closing Issue since we're archiving the repo

@forslund forslund closed this as completed Sep 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Status: For discussion Feature proposal in development. Community input and discussion is invited. Type: Enhancement - proposed New proposal for a feature that is not currently a priority on the roadmap.
Projects
None yet
Development

No branches or pull requests

4 participants