2017-06-25 16:39:30 +02:00
|
|
|
#!/usr/bin/python3
|
2012-01-31 17:29:00 +01:00
|
|
|
#
|
|
|
|
# The Qubes OS Project, http://www.qubes-os.org
|
|
|
|
#
|
|
|
|
# Copyright (C) 2012 Agnieszka Kostrzewa <agnieszka.kostrzewa@gmail.com>
|
|
|
|
# Copyright (C) 2012 Marek Marczykowski <marmarek@mimuw.edu.pl>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
2017-11-06 21:06:30 +01:00
|
|
|
# You should have received a copy of the GNU Lesser General Public License along
|
|
|
|
# with this program; if not, see <http://www.gnu.org/licenses/>.
|
2012-01-31 17:29:00 +01:00
|
|
|
#
|
|
|
|
#
|
|
|
|
|
2019-04-08 09:19:07 +02:00
|
|
|
import subprocess
|
2019-11-08 23:35:26 +01:00
|
|
|
from PyQt5 import QtWidgets, QtCore, QtGui # pylint: disable=import-error
|
2012-01-31 17:29:00 +01:00
|
|
|
|
2018-03-02 01:04:02 +01:00
|
|
|
from qubesadmin.utils import parse_size
|
2012-01-31 17:29:00 +01:00
|
|
|
|
2017-11-14 15:29:57 +01:00
|
|
|
from . import ui_globalsettingsdlg # pylint: disable=no-name-in-module
|
2018-01-25 22:03:07 +01:00
|
|
|
from . import utils
|
2012-01-31 17:29:00 +01:00
|
|
|
|
2017-06-25 16:39:30 +02:00
|
|
|
from configparser import ConfigParser
|
2012-01-31 17:29:00 +01:00
|
|
|
|
2012-04-14 17:58:29 +02:00
|
|
|
qmemman_config_path = '/etc/qubes/qmemman.conf'
|
2012-03-15 00:22:06 +01:00
|
|
|
|
2019-04-08 18:08:47 +02:00
|
|
|
def _run_qrexec_repo(service, arg=''):
|
|
|
|
# Fake up a "qrexec call" to dom0 because dom0 can't qrexec to itself yet
|
|
|
|
cmd = '/etc/qubes-rpc/' + service
|
|
|
|
p = subprocess.run(
|
|
|
|
['sudo', cmd, arg],
|
|
|
|
stdout=subprocess.PIPE,
|
2019-09-26 22:40:40 +02:00
|
|
|
stderr=subprocess.PIPE,
|
|
|
|
check=False
|
2019-04-08 18:08:47 +02:00
|
|
|
)
|
2019-07-02 03:04:28 +02:00
|
|
|
if p.stderr:
|
2019-10-23 18:18:39 +02:00
|
|
|
raise RuntimeError(
|
|
|
|
QtCore.QCoreApplication.translate(
|
|
|
|
"GlobalSettings", 'qrexec call stderr was not empty'),
|
|
|
|
{'stderr': p.stderr.decode('utf-8')})
|
2019-07-02 03:04:28 +02:00
|
|
|
if p.returncode != 0:
|
2019-10-23 18:18:39 +02:00
|
|
|
raise RuntimeError(
|
|
|
|
QtCore.QCoreApplication.translate(
|
|
|
|
"GlobalSettings",
|
|
|
|
'qrexec call exited with non-zero return code'),
|
|
|
|
{'returncode': p.returncode})
|
2019-04-08 18:08:47 +02:00
|
|
|
return p.stdout.decode('utf-8')
|
2019-05-22 23:10:09 +02:00
|
|
|
|
2019-10-23 18:18:39 +02:00
|
|
|
|
2018-03-02 01:04:02 +01:00
|
|
|
# pylint: disable=too-many-instance-attributes
|
2017-11-06 23:18:18 +01:00
|
|
|
class GlobalSettingsWindow(ui_globalsettingsdlg.Ui_GlobalSettings,
|
2019-05-22 23:10:09 +02:00
|
|
|
QtWidgets.QDialog):
|
2012-01-31 17:29:00 +01:00
|
|
|
|
2012-03-15 00:22:06 +01:00
|
|
|
def __init__(self, app, qvm_collection, parent=None):
|
2012-01-31 17:29:00 +01:00
|
|
|
super(GlobalSettingsWindow, self).__init__(parent)
|
|
|
|
|
2012-03-15 00:22:06 +01:00
|
|
|
self.app = app
|
|
|
|
self.qvm_collection = qvm_collection
|
|
|
|
|
2012-01-31 17:29:00 +01:00
|
|
|
self.setupUi(self)
|
2017-11-06 23:54:33 +01:00
|
|
|
|
2019-05-22 23:10:09 +02:00
|
|
|
self.buttonBox.accepted.connect(self.save_and_apply)
|
|
|
|
self.buttonBox.rejected.connect(self.reject)
|
2017-11-06 22:46:35 +01:00
|
|
|
|
2012-03-15 00:22:06 +01:00
|
|
|
self.__init_system_defaults__()
|
|
|
|
self.__init_kernel_defaults__()
|
|
|
|
self.__init_mem_defaults__()
|
2014-04-11 07:07:31 +02:00
|
|
|
self.__init_updates__()
|
2012-03-15 00:22:06 +01:00
|
|
|
|
2019-11-08 23:35:26 +01:00
|
|
|
def setup_application(self):
|
|
|
|
self.qt_app.setApplicationName(self.tr("Qubes Global Settings"))
|
|
|
|
self.qt_app.setWindowIcon(QtGui.QIcon.fromTheme("qubes-manager"))
|
|
|
|
|
2012-03-15 00:22:06 +01:00
|
|
|
def __init_system_defaults__(self):
|
2018-01-25 22:25:58 +01:00
|
|
|
# set up updatevm choice
|
2018-01-25 22:49:01 +01:00
|
|
|
self.update_vm_vmlist, self.update_vm_idx = utils.prepare_vm_choice(
|
2018-01-25 22:03:07 +01:00
|
|
|
self.update_vm_combo, self.qvm_collection, 'updatevm',
|
2018-07-12 21:22:15 +02:00
|
|
|
None, allow_none=True,
|
|
|
|
filter_function=(lambda vm: vm.klass != 'TemplateVM')
|
2018-01-25 22:03:07 +01:00
|
|
|
)
|
2012-03-15 00:22:06 +01:00
|
|
|
|
2018-01-25 22:25:58 +01:00
|
|
|
# set up clockvm choice
|
2018-01-25 22:49:01 +01:00
|
|
|
self.clock_vm_vmlist, self.clock_vm_idx = utils.prepare_vm_choice(
|
2018-01-25 22:25:58 +01:00
|
|
|
self.clock_vm_combo, self.qvm_collection, 'clockvm',
|
2018-07-12 21:22:15 +02:00
|
|
|
None, allow_none=True,
|
|
|
|
filter_function=(lambda vm: vm.klass != 'TemplateVM')
|
2018-01-25 22:25:58 +01:00
|
|
|
)
|
2012-03-15 00:22:06 +01:00
|
|
|
|
2018-01-25 22:49:01 +01:00
|
|
|
# set up default netvm
|
|
|
|
self.default_netvm_vmlist, self.default_netvm_idx = \
|
|
|
|
utils.prepare_vm_choice(
|
|
|
|
self.default_netvm_combo,
|
|
|
|
self.qvm_collection, 'default_netvm',
|
|
|
|
None,
|
|
|
|
filter_function=(lambda vm: vm.provides_network),
|
|
|
|
allow_none=True)
|
2012-03-15 00:22:06 +01:00
|
|
|
|
2018-01-25 22:57:58 +01:00
|
|
|
# default template
|
|
|
|
self.default_template_vmlist, self.default_template_idx = \
|
|
|
|
utils.prepare_vm_choice(
|
|
|
|
self.default_template_combo,
|
|
|
|
self.qvm_collection, 'default_template',
|
|
|
|
None,
|
2018-07-22 23:57:50 +02:00
|
|
|
filter_function=(lambda vm: vm.klass == 'TemplateVM'),
|
|
|
|
allow_none=True
|
2018-01-25 22:57:58 +01:00
|
|
|
)
|
2012-03-15 00:22:06 +01:00
|
|
|
|
2018-03-14 22:21:33 +01:00
|
|
|
# default dispvm
|
|
|
|
self.default_dispvm_vmlist, self.default_dispvm_idx = \
|
|
|
|
utils.prepare_vm_choice(
|
|
|
|
self.default_dispvm_combo,
|
|
|
|
self.qvm_collection, 'default_dispvm',
|
|
|
|
None,
|
2018-07-22 23:55:09 +02:00
|
|
|
(lambda vm: getattr(vm, 'template_for_dispvms', False)),
|
|
|
|
allow_none=True
|
2018-03-14 22:21:33 +01:00
|
|
|
)
|
|
|
|
|
2012-03-15 00:22:06 +01:00
|
|
|
def __apply_system_defaults__(self):
|
2019-04-08 09:18:16 +02:00
|
|
|
# updatevm
|
2018-03-02 14:30:56 +01:00
|
|
|
if self.qvm_collection.updatevm != \
|
|
|
|
self.update_vm_vmlist[self.update_vm_combo.currentIndex()]:
|
|
|
|
self.qvm_collection.updatevm = \
|
|
|
|
self.update_vm_vmlist[self.update_vm_combo.currentIndex()]
|
2012-03-15 00:22:06 +01:00
|
|
|
|
2018-01-25 22:25:58 +01:00
|
|
|
# clockvm
|
2018-03-02 14:30:56 +01:00
|
|
|
if self.qvm_collection.clockvm !=\
|
|
|
|
self.clock_vm_vmlist[self.clock_vm_combo.currentIndex()]:
|
|
|
|
self.qvm_collection.clockvm = \
|
|
|
|
self.clock_vm_vmlist[self.clock_vm_combo.currentIndex()]
|
2012-03-15 00:22:06 +01:00
|
|
|
|
2018-01-25 22:49:01 +01:00
|
|
|
# default netvm
|
2018-03-02 14:30:56 +01:00
|
|
|
if self.qvm_collection.default_netvm !=\
|
|
|
|
self.default_netvm_vmlist[
|
|
|
|
self.default_netvm_combo.currentIndex()]:
|
|
|
|
self.qvm_collection.default_netvm = \
|
|
|
|
self.default_netvm_vmlist[
|
|
|
|
self.default_netvm_combo.currentIndex()]
|
2012-03-15 00:22:06 +01:00
|
|
|
|
2018-01-25 22:57:58 +01:00
|
|
|
# default template
|
2018-03-02 14:30:56 +01:00
|
|
|
if self.qvm_collection.default_template != \
|
|
|
|
self.default_template_vmlist[
|
|
|
|
self.default_template_combo.currentIndex()]:
|
|
|
|
self.qvm_collection.default_template = \
|
|
|
|
self.default_template_vmlist[
|
|
|
|
self.default_template_combo.currentIndex()]
|
2012-03-15 00:22:06 +01:00
|
|
|
|
2018-03-14 22:21:33 +01:00
|
|
|
# default_dispvm
|
|
|
|
if self.qvm_collection.default_dispvm != \
|
|
|
|
self.default_dispvm_vmlist[
|
|
|
|
self.default_dispvm_combo.currentIndex()]:
|
|
|
|
self.qvm_collection.default_dispvm = \
|
|
|
|
self.default_dispvm_vmlist[
|
|
|
|
self.default_dispvm_combo.currentIndex()]
|
|
|
|
|
2012-03-15 00:22:06 +01:00
|
|
|
def __init_kernel_defaults__(self):
|
2018-01-25 23:33:51 +01:00
|
|
|
self.kernels_list, self.kernels_idx = utils.prepare_kernel_choice(
|
|
|
|
self.default_kernel_combo, self.qvm_collection, 'default_kernel',
|
|
|
|
None,
|
|
|
|
allow_none=True
|
|
|
|
)
|
2012-03-15 00:22:06 +01:00
|
|
|
|
|
|
|
def __apply_kernel_defaults__(self):
|
2018-03-02 14:30:56 +01:00
|
|
|
if self.qvm_collection.default_kernel != \
|
|
|
|
self.kernels_list[self.default_kernel_combo.currentIndex()]:
|
|
|
|
self.qvm_collection.default_kernel = \
|
|
|
|
self.kernels_list[self.default_kernel_combo.currentIndex()]
|
2017-11-06 23:54:33 +01:00
|
|
|
|
2012-03-15 00:22:06 +01:00
|
|
|
def __init_mem_defaults__(self):
|
2019-05-22 23:10:09 +02:00
|
|
|
# qmemman settings
|
2017-06-25 16:39:30 +02:00
|
|
|
self.qmemman_config = ConfigParser()
|
2019-05-22 23:10:09 +02:00
|
|
|
self.vm_min_mem_val = '200MiB' # str(qmemman_algo.MIN_PREFMEM)
|
|
|
|
self.dom0_mem_boost_val = '350MiB' # str(qmemman_algo.DOM0_MEM_BOOST)
|
2017-11-06 23:54:33 +01:00
|
|
|
|
2012-04-14 17:58:29 +02:00
|
|
|
self.qmemman_config.read(qmemman_config_path)
|
|
|
|
if self.qmemman_config.has_section('global'):
|
2017-11-06 23:18:18 +01:00
|
|
|
self.vm_min_mem_val = \
|
|
|
|
self.qmemman_config.get('global', 'vm-min-mem')
|
|
|
|
self.dom0_mem_boost_val = \
|
|
|
|
self.qmemman_config.get('global', 'dom0-mem-boost')
|
2012-04-14 17:58:29 +02:00
|
|
|
|
|
|
|
self.vm_min_mem_val = parse_size(self.vm_min_mem_val)
|
|
|
|
self.dom0_mem_boost_val = parse_size(self.dom0_mem_boost_val)
|
|
|
|
|
|
|
|
self.min_vm_mem.setValue(self.vm_min_mem_val/1024/1024)
|
|
|
|
self.dom0_mem_boost.setValue(self.dom0_mem_boost_val/1024/1024)
|
|
|
|
|
2012-03-15 00:22:06 +01:00
|
|
|
def __apply_mem_defaults__(self):
|
2012-04-14 17:58:29 +02:00
|
|
|
|
2019-05-22 23:10:09 +02:00
|
|
|
# qmemman settings
|
2012-04-14 17:58:29 +02:00
|
|
|
current_min_vm_mem = self.min_vm_mem.value()
|
|
|
|
current_dom0_mem_boost = self.dom0_mem_boost.value()
|
|
|
|
|
2017-11-06 23:18:18 +01:00
|
|
|
if current_min_vm_mem*1024*1024 != self.vm_min_mem_val \
|
|
|
|
or current_dom0_mem_boost*1024*1024 != self.dom0_mem_boost_val:
|
2012-04-14 17:58:29 +02:00
|
|
|
|
2019-01-17 03:10:26 +01:00
|
|
|
current_min_vm_mem = str(current_min_vm_mem)+'MiB'
|
|
|
|
current_dom0_mem_boost = str(current_dom0_mem_boost)+'MiB'
|
2012-04-14 17:58:29 +02:00
|
|
|
|
|
|
|
if not self.qmemman_config.has_section('global'):
|
2019-05-22 23:10:09 +02:00
|
|
|
# add the whole section
|
2012-04-14 17:58:29 +02:00
|
|
|
self.qmemman_config.add_section('global')
|
2017-11-06 23:18:18 +01:00
|
|
|
self.qmemman_config.set(
|
|
|
|
'global', 'vm-min-mem', current_min_vm_mem)
|
|
|
|
self.qmemman_config.set(
|
|
|
|
'global', 'dom0-mem-boost', current_dom0_mem_boost)
|
|
|
|
self.qmemman_config.set(
|
|
|
|
'global', 'cache-margin-factor', str(1.3))
|
|
|
|
# removed qmemman_algo.CACHE_FACTOR
|
2012-04-14 17:58:29 +02:00
|
|
|
|
|
|
|
qmemman_config_file = open(qmemman_config_path, 'a')
|
|
|
|
self.qmemman_config.write(qmemman_config_file)
|
|
|
|
qmemman_config_file.close()
|
|
|
|
|
|
|
|
else:
|
2019-05-22 23:10:09 +02:00
|
|
|
# If there already is a 'global' section, we don't use
|
2017-11-06 23:18:18 +01:00
|
|
|
# SafeConfigParser.write() - it would get rid of
|
|
|
|
# all the comments...
|
2017-11-06 23:54:33 +01:00
|
|
|
|
2012-04-14 17:58:29 +02:00
|
|
|
lines_to_add = {}
|
2017-11-06 23:18:18 +01:00
|
|
|
lines_to_add['vm-min-mem'] = \
|
|
|
|
"vm-min-mem = " + current_min_vm_mem + "\n"
|
|
|
|
lines_to_add['dom0-mem-boost'] = \
|
2019-05-22 23:10:09 +02:00
|
|
|
"dom0-mem-boost = " + current_dom0_mem_boost + "\n"
|
2012-04-14 17:58:29 +02:00
|
|
|
|
|
|
|
config_lines = []
|
|
|
|
|
|
|
|
qmemman_config_file = open(qmemman_config_path, 'r')
|
2017-11-08 16:53:49 +01:00
|
|
|
for line in qmemman_config_file:
|
|
|
|
if line.strip().startswith('vm-min-mem'):
|
2012-04-14 17:58:29 +02:00
|
|
|
config_lines.append(lines_to_add['vm-min-mem'])
|
|
|
|
del lines_to_add['vm-min-mem']
|
2017-11-08 16:53:49 +01:00
|
|
|
elif line.strip().startswith('dom0-mem-boost'):
|
2012-04-14 17:58:29 +02:00
|
|
|
config_lines.append(lines_to_add['dom0-mem-boost'])
|
|
|
|
del lines_to_add['dom0-mem-boost']
|
|
|
|
else:
|
2017-11-08 16:53:49 +01:00
|
|
|
config_lines.append(line)
|
2017-11-06 23:54:33 +01:00
|
|
|
|
2012-04-14 17:58:29 +02:00
|
|
|
qmemman_config_file.close()
|
|
|
|
|
2017-11-08 16:53:49 +01:00
|
|
|
for line in lines_to_add:
|
|
|
|
config_lines.append(line)
|
2012-04-14 17:58:29 +02:00
|
|
|
|
|
|
|
qmemman_config_file = open(qmemman_config_path, 'w')
|
|
|
|
qmemman_config_file.writelines(config_lines)
|
|
|
|
qmemman_config_file.close()
|
|
|
|
|
2014-04-11 07:07:31 +02:00
|
|
|
def __init_updates__(self):
|
2018-01-26 17:18:07 +01:00
|
|
|
try:
|
2019-04-11 22:58:49 +02:00
|
|
|
self.updates_dom0_val = bool(self.qvm_collection.domains[
|
|
|
|
'dom0'].features['service.qubes-update-check'])
|
2019-03-18 19:02:47 +01:00
|
|
|
except KeyError:
|
2019-10-16 22:00:11 +02:00
|
|
|
self.updates_dom0_val = True
|
2018-01-26 17:18:07 +01:00
|
|
|
|
2014-04-11 07:07:31 +02:00
|
|
|
self.updates_dom0.setChecked(self.updates_dom0_val)
|
2018-01-26 17:18:07 +01:00
|
|
|
|
2018-01-26 22:36:54 +01:00
|
|
|
self.updates_vm.setChecked(self.qvm_collection.check_updates_vm)
|
|
|
|
self.enable_updates_all.clicked.connect(self.__enable_updates_all)
|
|
|
|
self.disable_updates_all.clicked.connect(self.__disable_updates_all)
|
|
|
|
|
2019-07-03 10:46:39 +02:00
|
|
|
self.repos = repos = dict()
|
2019-04-08 18:08:47 +02:00
|
|
|
for i in _run_qrexec_repo('qubes.repos.List').split('\n'):
|
2019-07-03 01:04:04 +02:00
|
|
|
lst = i.split('\0')
|
2019-04-08 09:19:07 +02:00
|
|
|
# Keyed by repo name
|
2019-07-03 01:04:04 +02:00
|
|
|
dct = repos[lst[0]] = dict()
|
|
|
|
dct['prettyname'] = lst[1]
|
|
|
|
dct['enabled'] = lst[2] == 'enabled'
|
2019-04-08 09:19:07 +02:00
|
|
|
|
|
|
|
if repos['qubes-dom0-unstable']['enabled']:
|
|
|
|
self.dom0_updates_repo.setCurrentIndex(3)
|
|
|
|
elif repos['qubes-dom0-current-testing']['enabled']:
|
|
|
|
self.dom0_updates_repo.setCurrentIndex(2)
|
|
|
|
elif repos['qubes-dom0-security-testing']['enabled']:
|
|
|
|
self.dom0_updates_repo.setCurrentIndex(1)
|
|
|
|
elif repos['qubes-dom0-current']['enabled']:
|
|
|
|
self.dom0_updates_repo.setCurrentIndex(0)
|
|
|
|
else:
|
2019-10-23 18:18:39 +02:00
|
|
|
raise Exception(
|
|
|
|
self.tr('Cannot detect enabled dom0 update repositories'))
|
2019-04-08 09:19:07 +02:00
|
|
|
|
|
|
|
if repos['qubes-templates-itl-testing']['enabled']:
|
|
|
|
self.itl_tmpl_updates_repo.setCurrentIndex(1)
|
|
|
|
elif repos['qubes-templates-itl']['enabled']:
|
|
|
|
self.itl_tmpl_updates_repo.setCurrentIndex(0)
|
|
|
|
else:
|
2019-10-23 18:18:39 +02:00
|
|
|
raise Exception(self.tr('Cannot detect enabled ITL template update '
|
|
|
|
'repositories'))
|
2019-04-08 09:19:07 +02:00
|
|
|
|
|
|
|
if repos['qubes-templates-community-testing']['enabled']:
|
|
|
|
self.comm_tmpl_updates_repo.setCurrentIndex(2)
|
|
|
|
elif repos['qubes-templates-community']['enabled']:
|
|
|
|
self.comm_tmpl_updates_repo.setCurrentIndex(1)
|
|
|
|
else:
|
|
|
|
self.comm_tmpl_updates_repo.setCurrentIndex(0)
|
|
|
|
|
2018-01-26 22:36:54 +01:00
|
|
|
def __enable_updates_all(self):
|
2019-05-22 23:10:09 +02:00
|
|
|
reply = QtWidgets.QMessageBox.question(
|
2018-01-26 22:36:54 +01:00
|
|
|
self, self.tr("Change state of all qubes"),
|
|
|
|
self.tr("Are you sure you want to set all qubes to check "
|
|
|
|
"for updates?"),
|
2019-05-22 23:10:09 +02:00
|
|
|
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.Cancel)
|
|
|
|
if reply == QtWidgets.QMessageBox.Cancel:
|
2018-01-26 22:36:54 +01:00
|
|
|
return
|
|
|
|
|
|
|
|
self.__set_updates_all(True)
|
|
|
|
|
|
|
|
def __disable_updates_all(self):
|
2019-05-22 23:10:09 +02:00
|
|
|
reply = QtWidgets.QMessageBox.question(
|
2018-01-26 22:36:54 +01:00
|
|
|
self, self.tr("Change state of all qubes"),
|
|
|
|
self.tr("Are you sure you want to set all qubes to not check "
|
|
|
|
"for updates?"),
|
2019-05-22 23:10:09 +02:00
|
|
|
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.Cancel)
|
|
|
|
if reply == QtWidgets.QMessageBox.Cancel:
|
2018-01-26 22:36:54 +01:00
|
|
|
return
|
|
|
|
|
|
|
|
self.__set_updates_all(False)
|
|
|
|
|
|
|
|
def __set_updates_all(self, state):
|
|
|
|
for vm in self.qvm_collection.domains:
|
2019-03-18 19:02:47 +01:00
|
|
|
if vm.klass != "AdminVM":
|
|
|
|
vm.features['service.qubes-update-check'] = state
|
2014-04-11 07:07:31 +02:00
|
|
|
|
|
|
|
def __apply_updates__(self):
|
|
|
|
if self.updates_dom0.isChecked() != self.updates_dom0_val:
|
2019-03-18 19:02:47 +01:00
|
|
|
self.qvm_collection.domains['dom0'].features[
|
|
|
|
'service.qubes-update-check'] = \
|
|
|
|
self.updates_dom0.isChecked()
|
2018-01-26 17:18:07 +01:00
|
|
|
|
2019-04-12 00:30:12 +02:00
|
|
|
if self.qvm_collection.check_updates_vm != self.updates_vm.isChecked():
|
|
|
|
self.qvm_collection.check_updates_vm = self.updates_vm.isChecked()
|
2012-04-14 17:58:29 +02:00
|
|
|
|
2019-07-02 21:46:51 +02:00
|
|
|
def _manage_repos(self, repolist, action):
|
2019-07-03 10:46:39 +02:00
|
|
|
for name in repolist:
|
|
|
|
if self.repos[name]['enabled'] and action == 'Enable' or \
|
|
|
|
not self.repos[name]['enabled'] and action == 'Disable':
|
|
|
|
continue
|
|
|
|
|
2019-07-02 21:46:51 +02:00
|
|
|
try:
|
2019-07-03 10:46:39 +02:00
|
|
|
result = _run_qrexec_repo('qubes.repos.' + action, name)
|
2019-07-02 21:46:51 +02:00
|
|
|
if result != 'ok\n':
|
|
|
|
raise RuntimeError(
|
2019-10-23 18:18:39 +02:00
|
|
|
self.tr('qrexec call stdout did not contain "ok"'
|
|
|
|
' as expected'),
|
2019-07-02 22:37:29 +02:00
|
|
|
{'stdout': result})
|
2019-07-02 21:46:51 +02:00
|
|
|
except RuntimeError as ex:
|
2019-07-02 22:37:29 +02:00
|
|
|
msg = '{desc}; {args}'.format(desc=ex.args[0], args=', '.join(
|
|
|
|
# This is kind of hard to mentally parse but really all
|
|
|
|
# it does is pretty-print args[1], which is a dictionary
|
|
|
|
['{key}: {val}'.format(key=i[0], val=i[1]) for i in
|
|
|
|
ex.args[1].items()]
|
|
|
|
))
|
2019-08-28 16:42:01 +02:00
|
|
|
QtWidgets.QMessageBox.warning(
|
2019-07-02 21:46:51 +02:00
|
|
|
None,
|
|
|
|
self.tr("ERROR!"),
|
2019-07-03 10:48:55 +02:00
|
|
|
self.tr("Error managing {repo} repository settings:"
|
|
|
|
" {msg}".format(repo=name, msg=msg)))
|
2019-07-02 21:46:51 +02:00
|
|
|
|
|
|
|
def _handle_dom0_updates_combobox(self, idx):
|
|
|
|
idx += 1
|
|
|
|
repolist = ['qubes-dom0-current', 'qubes-dom0-security-testing',
|
|
|
|
'qubes-dom0-current-testing', 'qubes-dom0-unstable']
|
|
|
|
enable = repolist[:idx]
|
|
|
|
disable = repolist[idx:]
|
|
|
|
self._manage_repos(enable, 'Enable')
|
|
|
|
self._manage_repos(disable, 'Disable')
|
|
|
|
|
|
|
|
# pylint: disable=invalid-name
|
|
|
|
def _handle_itl_tmpl_updates_combobox(self, idx):
|
|
|
|
idx += 1
|
|
|
|
repolist = ['qubes-templates-itl', 'qubes-templates-itl-testing']
|
|
|
|
enable = repolist[:idx]
|
|
|
|
disable = repolist[idx:]
|
|
|
|
self._manage_repos(enable, 'Enable')
|
|
|
|
self._manage_repos(disable, 'Disable')
|
|
|
|
|
|
|
|
# pylint: disable=invalid-name
|
|
|
|
def _handle_comm_tmpl_updates_combobox(self, idx):
|
|
|
|
# We don't increment idx by 1 because this is the only combobox that
|
|
|
|
# has an explicit "disable this repository entirely" option
|
|
|
|
repolist = ['qubes-templates-community',
|
|
|
|
'qubes-templates-community-testing']
|
|
|
|
enable = repolist[:idx]
|
|
|
|
disable = repolist[idx:]
|
|
|
|
self._manage_repos(enable, 'Enable')
|
|
|
|
self._manage_repos(disable, 'Disable')
|
|
|
|
|
2019-07-02 09:06:56 +02:00
|
|
|
def __apply_repos__(self):
|
2019-07-02 21:46:51 +02:00
|
|
|
self._handle_dom0_updates_combobox(
|
2019-07-02 09:06:56 +02:00
|
|
|
self.dom0_updates_repo.currentIndex())
|
2019-07-02 21:46:51 +02:00
|
|
|
self._handle_itl_tmpl_updates_combobox(
|
2019-07-02 09:06:56 +02:00
|
|
|
self.itl_tmpl_updates_repo.currentIndex())
|
2019-07-02 21:46:51 +02:00
|
|
|
self._handle_comm_tmpl_updates_combobox(
|
2019-07-02 09:06:56 +02:00
|
|
|
self.comm_tmpl_updates_repo.currentIndex())
|
|
|
|
|
2012-01-31 17:29:00 +01:00
|
|
|
def reject(self):
|
|
|
|
self.done(0)
|
|
|
|
|
|
|
|
def save_and_apply(self):
|
2017-06-25 16:39:30 +02:00
|
|
|
|
2017-11-06 23:54:33 +01:00
|
|
|
self.__apply_system_defaults__()
|
2012-03-15 00:22:06 +01:00
|
|
|
self.__apply_kernel_defaults__()
|
|
|
|
self.__apply_mem_defaults__()
|
2014-04-11 07:07:31 +02:00
|
|
|
self.__apply_updates__()
|
2019-07-02 09:06:56 +02:00
|
|
|
self.__apply_repos__()
|
2017-06-25 16:39:30 +02:00
|
|
|
|
2012-01-31 17:29:00 +01:00
|
|
|
|
|
|
|
def main():
|
2019-11-08 23:35:26 +01:00
|
|
|
utils.run_synchronous(GlobalSettingsWindow)
|
2012-01-31 17:29:00 +01:00
|
|
|
|
2019-05-22 23:10:09 +02:00
|
|
|
|
2012-01-31 17:29:00 +01:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|