Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuration settable from outside #157

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

herrfrei
Copy link

Added config argument to DbusService.init() to set the config file to use from outside

This is necessary for SetupHelper installation method (config file is located in /data/conf/dbus-opendtu.ini to be preserverd during updates)

Added config argument to DbusService.__init__() to set the config file to use from outside

This is necessary for SetupHelper installation method (config file is located in /data/conf/dbus-opendtu.ini to be preserverd during updates)
Copy link
Collaborator

@0x7878 0x7878 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add some verification if a config from outside is not reachable or similar. Otherwise it looks good to me. I assume you tested it beforehand, right?

@herrfrei
Copy link
Author

Yes, I tested it.

What du you mean with verification? Should I add a check for the instance like below?

def _get_config(self):
    '''return the cached configuration object, read it before if not already done'''
    if self._config is None or not isinstance(self._config, configparser.ConfigParser):
        self._config = configparser.ConfigParser()
        self._config.read(f"{(os.path.dirname(os.path.realpath(__file__)))}/config.ini")
    return self._config

@dsteinkopf
Copy link
Collaborator

Some plausibility check will be helpful for some users E.g. file is readably and contains more than x bytes... Maybe something more...

@herrfrei
Copy link
Author

I didn't see any validation in the code before. So I just added the init() argument...
Since the configuration file is parsed in dbus-opendtu.py beforehand, I think there should be a check, if any.

Btw, the ConfigParser itself does not perform any checks; the documentation states: If none of the named files exist, the instance ConfigParser contains an empty data set.

@0x7878
Copy link
Collaborator

0x7878 commented Apr 15, 2024

That's right. Since you started editing this part of the code, it might be a good idea to have checks in it. Don't you agree? I was only asking for it. Our software does not run without a config. Just check if the file is there and readable. No content checks.

@stlorenz
Copy link
Contributor

Just as a quick crosscheck? Wouldn't it be much easier to rename the example config.ini to config.example to preserve overwriting during updates?

The implementation here breaks my installation with more than one DTU.
I have two DTUs, one is configured in the folder /data/dbsu-opendtu/ and one in /data/dbus-opendtu-hmt/

In this MR; there is no option to query more than one DTU without changing the code after each update.

@herrfrei
Copy link
Author

When SetupHelper updates a package, a release archive is downdloaded and the old directory gets renamed (and removed when extraction was successful). So, during last update I lost my config inside the /data/dbus-opendtu directory... That's why I wanted to move the config out of the code directory.
@stlorenz I don't know how to handle your case with two DTU's right now. May be we'll find a solution?

@stlorenz
Copy link
Contributor

@stlorenz I don't know how to handle your case with two DTU's right now. May be we'll find a solution?

@herrfrei could you please take a look at my PR #163 , I think that would solve your and my problem at the same time?

@herrfrei
Copy link
Author

Did you read my comment above? SetupHelper removes the whole old version directory including your config.ini. Your PR is similar to one I did before I knew this behavior.

I'll see if there is a solution with SetupHelper.

@stlorenz
Copy link
Contributor

I did, but I was not aware of the SetupHelper Package so I misunderstood it.
This is very helpful, so thanks for pointing me at this. I did that manually so far.

So your approach is trying to make this addon SetupHelper compatible?
I need more time on the code of SetupHelper to understand this but it looks like it provides a mechanism to backup existing configs.

Is this always approached by moving the config out of the Folder?
Are there any other methods like flagging the file?
I found this in https://github.com/kwindrem/SetupHelper/blob/81a1bbf8e4c28deb7c68835ab2854acb3ac4d530/PackageManager.py

	PackageManager has a mechnism for backing up and restoring settings:
#		SOME dbus Settings
#		custom icons
#		backing up gui, SetupHelper and PackageManager logs

But I could not find any other reference of it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants