From 893c5c23b3d704ea1353bbe43ce751c331e9a6f4 Mon Sep 17 00:00:00 2001 From: Carlo Vanini Date: Fri, 23 Nov 2018 20:56:23 +0100 Subject: [RFC PATCH] Use DBus backend to make changes --- software-properties-qt | 7 --- softwareproperties/SoftwareProperties.py | 3 ++ softwareproperties/qt/SoftwarePropertiesQt.py | 47 ++++++++++++------- 3 files changed, 34 insertions(+), 23 deletions(-) diff --git a/software-properties-qt b/software-properties-qt index 4e368ff..6adc733 100755 --- a/software-properties-qt +++ b/software-properties-qt @@ -98,13 +98,6 @@ if __name__ == '__main__': parser.addOption(dataDirOption); parser.process(app) - # Check for root permissions - if os.geteuid() != 0: - text = "Please run this software with administrative rights. To do so, run this program with pkexec." - title = "Need administrative powers" - msgbox = QMessageBox.critical(None, title, text) - sys.exit(1) - localesApp="software-properties" localesDir="/usr/share/locale" gettext.bindtextdomain(localesApp, localesDir) diff --git a/softwareproperties/SoftwareProperties.py b/softwareproperties/SoftwareProperties.py index 20d20e9..02bce0f 100644 --- a/softwareproperties/SoftwareProperties.py +++ b/softwareproperties/SoftwareProperties.py @@ -878,7 +878,10 @@ class SoftwareProperties(object): # Livepatch # def init_snapd(self): + try: self.snapd_client = Snapd.Client() + except NameError: + self.snapd_client = None def get_livepatch_snap_async(self, callback): assert self.snapd_client diff --git a/softwareproperties/qt/SoftwarePropertiesQt.py b/softwareproperties/qt/SoftwarePropertiesQt.py index 38b7ad9..b040edb 100644 --- a/softwareproperties/qt/SoftwarePropertiesQt.py +++ b/softwareproperties/qt/SoftwarePropertiesQt.py @@ -31,11 +31,13 @@ import tempfile from gettext import gettext as _ import os import subprocess +import logging from PyQt5 import uic from PyQt5.QtCore import * from PyQt5.QtGui import * from PyQt5.QtWidgets import * +from PyQt5 import QtDBus import softwareproperties import softwareproperties.distro @@ -68,6 +70,9 @@ class SoftwarePropertiesQt(SoftwareProperties): kapp = QApplication.instance() kapp.setWindowIcon(QIcon.fromTheme("applications-other")) + bus = QtDBus.QDBusConnection.systemBus() + self.backend = QtDBus.QDBusInterface("com.ubuntu.SoftwareProperties", "/", "com.ubuntu.SoftwareProperties", bus) + self.userinterface = SoftwarePropertiesQtUI(datadir) self.userinterface.setWindowIcon(QIcon.fromTheme("applications-other")) self.userinterface.button_auth_restore.setIcon(QIcon.fromTheme("edit-undo")) @@ -93,7 +98,6 @@ class SoftwarePropertiesQt(SoftwareProperties): self.init_popcon() self.init_auto_update() self.init_release_upgrades() - self.show_auto_update_level() # Setup the key list self.init_keys() self.show_keys() @@ -190,6 +194,8 @@ class SoftwarePropertiesQt(SoftwareProperties): self.userinterface.radiobutton_updates_download.setEnabled(False) self.userinterface.radiobutton_updates_notify.setEnabled(False) + self.show_auto_update_level() + self.userinterface.radiobutton_updates_download.toggled.connect(self.set_update_automation_level) self.userinterface.radiobutton_updates_inst_sec.toggled.connect(self.set_update_automation_level) self.userinterface.radiobutton_updates_notify.toggled.connect(self.set_update_automation_level) @@ -378,12 +384,25 @@ class SoftwarePropertiesQt(SoftwareProperties): def set_update_automation_level(self, selected): """Call the backend to set the update automation level to the given value""" + state = -1 if self.userinterface.radiobutton_updates_download.isChecked(): - SoftwareProperties.set_update_automation_level(self, softwareproperties.UPDATE_DOWNLOAD) + state = softwareproperties.UPDATE_DOWNLOAD elif self.userinterface.radiobutton_updates_inst_sec.isChecked(): - SoftwareProperties.set_update_automation_level(self, softwareproperties.UPDATE_INST_SEC) + state = softwareproperties.UPDATE_INST_SEC elif self.userinterface.radiobutton_updates_notify.isChecked(): - SoftwareProperties.set_update_automation_level(self, softwareproperties.UPDATE_NOTIFY) + state = softwareproperties.UPDATE_NOTIFY + if state != -1 and state != self.get_update_automation_level(): + reply = self.backend.call("SetUpdateAutomationLevel", state) + if reply.type() == QtDBus.QDBusMessage.ErrorMessage: + if reply.errorName() == "com.ubuntu.SoftwareProperties.PermissionDeniedByPolicy": + # Authentication canceled by user, + # retry after wrong password is handled by PolicyKit + logging.error("Authentication canceled, changes have not been saved") + else: + logging.error( + "Error '{errorName}' in the backend: {errorMessage}".format( + errorName = reply.errorName(), + errorMessage = reply.errorMessage())) self.set_modified_config() def on_combobox_release_upgrades_changed(self, combobox): @@ -405,8 +424,7 @@ class SoftwarePropertiesQt(SoftwareProperties): dialogue = DialogMirror(self.userinterface, self.datadir, self.distro, self.custom_mirrors) res = dialogue.run() if res != None: - self.distro.change_server(res) - self.set_modified_sourceslist() + self.backend.call("ChangeMainDownloadServer", res) self.init_mirrors() # update combobox else: combobox.setCurrentIndex(self.active_server) @@ -414,10 +432,9 @@ class SoftwarePropertiesQt(SoftwareProperties): uri = self.mirror_urls[index] if uri != None and len(self.distro.used_servers) > 0: self.active_server = index - self.distro.change_server(uri) - self.set_modified_sourceslist() + self.backend.call("ChangeMainDownloadServer", uri) else: - self.distro.default_server = uri + combobox.setCurrentIndex(self.active_server) def on_component_toggled(self): """ @@ -427,10 +444,9 @@ class SoftwarePropertiesQt(SoftwareProperties): # FIXME: I find it rather questionable whether sender will work with pyqt doing weird signal handling tickBox = kapp.sender() if tickBox.checkState() == Qt.Checked: - self.enable_component(str(tickBox.objectName())) + self.backend.call("EnableComponent", str(tickBox.objectName())) elif tickBox.checkState() == Qt.Unchecked: - self.disable_component(str(tickBox.objectName())) - self.set_modified_sourceslist() + self.backend.call("DisableComponent", str(tickBox.objectName())) # no way to set back to mixed state so turn off tristate tickBox.setTristate(False) @@ -452,9 +468,9 @@ class SoftwarePropertiesQt(SoftwareProperties): def on_checkbutton_source_code_toggled(self): """ Disable or enable the source code for all sources """ if self.userinterface.checkbutton_source_code.checkState() == Qt.Checked: - self.enable_source_code_sources() + self.backend.call("EnableSourceCodeSources") elif self.userinterface.checkbutton_source_code.checkState() == Qt.Unchecked: - self.disable_source_code_sources() + self.backend.call("DisableSourceCodeSources") self.userinterface.checkbutton_source_code.setTristate(False) def on_checkbutton_popcon_toggled(self, state): @@ -532,8 +548,7 @@ class SoftwarePropertiesQt(SoftwareProperties): self.modified_sourceslist = False def set_modified_config(self): - """The config was changed and now needs to be saved and reloaded""" - SoftwareProperties.set_modified_config(self) + """The config was changed. Chages are saved by the backend, here we update the UI.""" self.userinterface.buttonBox.button(QDialogButtonBox.Reset).setEnabled(True) def set_modified_sourceslist(self): -- 2.17.1