Fixed too-long lines

Fixed lines over 80 characters.
This commit is contained in:
Marta Marczykowska-Górecka 2017-11-06 23:18:18 +01:00
parent c252e9ec3c
commit 91572eea2d
No known key found for this signature in database
GPG Key ID: 9A752C30B26FD04B
7 changed files with 179 additions and 91 deletions

View File

@ -50,7 +50,9 @@ class AppmenuSelectManager:
).decode().strip().split('\n') if line] ).decode().strip().split('\n') if line]
# Check if appmenu entry is really installed # Check if appmenu entry is really installed
# whitelisted = [a for a in whitelisted if os.path.exists('%s/apps/%s-%s' % (self.vm.dir_path, self.vm.name, a))] # whitelisted = [a for a in whitelisted
# if os.path.exists('%s/apps/%s-%s' %
# (self.vm.dir_path, self.vm.name, a))]
self.app_list.clear() self.app_list.clear()

View File

@ -34,9 +34,13 @@ class VMBootFromDeviceWindow(ui_bootfromdevice.Ui_BootDialog, QtGui.QDialog):
self.qapp = qapp self.qapp = qapp
self.setupUi(self) self.setupUi(self)
self.setWindowTitle(self.tr("Boot {vm} from device").format(vm=self.vm.name)) self.setWindowTitle(
self.tr("Boot {vm} from device").format(vm=self.vm.name))
self.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), self.save_and_apply) self.connect(
self.buttonBox,
QtCore.SIGNAL("accepted()"),
self.save_and_apply)
self.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), self.reject) self.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), self.reject)
# populate buttons and such # populate buttons and such
@ -50,11 +54,13 @@ class VMBootFromDeviceWindow(ui_bootfromdevice.Ui_BootDialog, QtGui.QDialog):
if self.blockDeviceRadioButton.isChecked(): if self.blockDeviceRadioButton.isChecked():
cdrom_location = self.blockDeviceComboBox.currentText() cdrom_location = self.blockDeviceComboBox.currentText()
elif self.fileRadioButton.isChecked(): elif self.fileRadioButton.isChecked():
cdrom_location = str(self.vm_list[self.fileVM.currentIndex()]) + ":" + self.pathText.text() cdrom_location = str(
self.vm_list[self.fileVM.currentIndex()]) + \
":" + self.pathText.text()
else: else:
QtGui.QMessageBox.warning(None, QtGui.QMessageBox.warning(
self.tr( None,
"ERROR!"), self.tr("ERROR!"),
self.tr("No file or block device selected; please select one.")) self.tr("No file or block device selected; please select one."))
return return
qvm_start.main(['--cdrom', cdrom_location, self.vm.name]) qvm_start.main(['--cdrom', cdrom_location, self.vm.name])
@ -87,7 +93,8 @@ class VMBootFromDeviceWindow(ui_bootfromdevice.Ui_BootDialog, QtGui.QDialog):
) )
def radio_button_clicked(self): def radio_button_clicked(self):
self.blockDeviceComboBox.setEnabled(self.blockDeviceRadioButton.isChecked()) self.blockDeviceComboBox.setEnabled(
self.blockDeviceRadioButton.isChecked())
self.fileVM.setEnabled(self.fileRadioButton.isChecked()) self.fileVM.setEnabled(self.fileRadioButton.isChecked())
self.selectFileButton.setEnabled(self.fileRadioButton.isChecked()) self.selectFileButton.setEnabled(self.fileRadioButton.isChecked())
self.pathText.setEnabled(self.fileRadioButton.isChecked()) self.pathText.setEnabled(self.fileRadioButton.isChecked())

View File

@ -46,7 +46,8 @@ class NewVmDlg(QtGui.QDialog, Ui_NewVMDlg):
self.app = app self.app = app
# Theoretically we should be locking for writing here and unlock # Theoretically we should be locking for writing here and unlock
# only after the VM creation finished. But the code would be more messy... # only after the VM creation finished. But the code would be
# more messy...
# Instead we lock for writing in the actual worker thread # Instead we lock for writing in the actual worker thread
self.label_list, self.label_idx = utils.prepare_label_choice( self.label_list, self.label_idx = utils.prepare_label_choice(
self.label, self.label,
@ -94,7 +95,8 @@ class NewVmDlg(QtGui.QDialog, Ui_NewVMDlg):
self.done(0) self.done(0)
def accept(self): def accept(self):
vmclass = ('AppVM' if self.vm_type.currentIndex() == 0 else 'StandaloneVM') vmclass = ('AppVM' if self.vm_type.currentIndex() == 0
else 'StandaloneVM')
name = str(self.name.text()) name = str(self.name.text())
try: try:

View File

@ -76,8 +76,11 @@ class NewFwRuleDlg (QtGui.QDialog, ui_newfwruledlg.Ui_NewFwRuleDlg):
self.set_ok_enabled(False) self.set_ok_enabled(False)
self.addressComboBox.setValidator(QIPAddressValidator()) self.addressComboBox.setValidator(QIPAddressValidator())
self.addressComboBox.editTextChanged.connect(self.address_editing_finished) self.addressComboBox.editTextChanged.connect(
self.serviceComboBox.setValidator(QtGui.QRegExpValidator(QtCore.QRegExp("[a-z][a-z0-9-]+|[0-9]+(-[0-9]+)?", QtCore.Qt.CaseInsensitive), None)) self.address_editing_finished)
self.serviceComboBox.setValidator(QtGui.QRegExpValidator(
QtCore.QRegExp("[a-z][a-z0-9-]+|[0-9]+(-[0-9]+)?",
QtCore.Qt.CaseInsensitive), None))
self.serviceComboBox.setEnabled(False) self.serviceComboBox.setEnabled(False)
self.serviceComboBox.setInsertPolicy(QtGui.QComboBox.InsertAtBottom) self.serviceComboBox.setInsertPolicy(QtGui.QComboBox.InsertAtBottom)
self.populate_combos() self.populate_combos()
@ -88,7 +91,8 @@ class NewFwRuleDlg (QtGui.QDialog, ui_newfwruledlg.Ui_NewFwRuleDlg):
if len(self.serviceComboBox.currentText()) == 0: if len(self.serviceComboBox.currentText()) == 0:
msg = QtGui.QMessageBox() msg = QtGui.QMessageBox()
msg.warning(self, self.tr("Firewall rule"), msg.warning(self, self.tr("Firewall rule"),
self.tr("You need to fill service name/port for TCP/UDP rule")) self.tr("You need to fill service "
"name/port for TCP/UDP rule"))
return return
QtGui.QDialog.accept(self) QtGui.QDialog.accept(self)
@ -138,13 +142,16 @@ class QubesFirewallRulesModel(QtCore.QAbstractItemModel):
self.__columnNames = {0: "Address", 1: "Service", 2: "Protocol", } self.__columnNames = {0: "Address", 1: "Service", 2: "Protocol", }
self.__services = list() self.__services = list()
pattern = re.compile("(?P<name>[a-z][a-z0-9-]+)\s+(?P<port>[0-9]+)/(?P<protocol>[a-z]+)", re.IGNORECASE) pattern = re.compile(
"(?P<name>[a-z][a-z0-9-]+)\s+(?P<port>[0-9]+)/(?P<protocol>[a-z]+)",
re.IGNORECASE)
f = open('/etc/services', 'r') f = open('/etc/services', 'r')
for line in f: for line in f:
match = pattern.match(line) match = pattern.match(line)
if match is not None: if match is not None:
service = match.groupdict() service = match.groupdict()
self.__services.append( (service["name"], int(service["port"]),) ) self.__services.append(
(service["name"], int(service["port"]),) )
f.close() f.close()
self.fw_changed = False self.fw_changed = False
@ -372,7 +379,9 @@ class QubesFirewallRulesModel(QtCore.QAbstractItemModel):
try: try:
rule.dstports = service rule.dstports = service
except ValueError: except ValueError:
QtGui.QMessageBox.warning(None, self.tr("Invalid port or service"), QtGui.QMessageBox.warning(
None,
self.tr("Invalid port or service"),
self.tr("Port number or service '{0}' is invalid.") self.tr("Port number or service '{0}' is invalid.")
.format(service)) .format(service))
elif service is not None: elif service is not None:
@ -421,7 +430,8 @@ class QubesFirewallRulesModel(QtCore.QAbstractItemModel):
def headerData(self, section, orientation, role=QtCore.Qt.DisplayRole): def headerData(self, section, orientation, role=QtCore.Qt.DisplayRole):
if section < len(self.__columnNames) \ if section < len(self.__columnNames) \
and orientation == QtCore.Qt.Horizontal and role == QtCore.Qt.DisplayRole: and orientation == QtCore.Qt.Horizontal \
and role == QtCore.Qt.DisplayRole:
return self.__columnNames[section] return self.__columnNames[section]
@property @property

View File

@ -34,7 +34,8 @@ from configparser import ConfigParser
qmemman_config_path = '/etc/qubes/qmemman.conf' qmemman_config_path = '/etc/qubes/qmemman.conf'
class GlobalSettingsWindow(ui_globalsettingsdlg.Ui_GlobalSettings, QtGui.QDialog): class GlobalSettingsWindow(ui_globalsettingsdlg.Ui_GlobalSettings,
QtGui.QDialog):
def __init__(self, app, qvm_collection, parent=None): def __init__(self, app, qvm_collection, parent=None):
super(GlobalSettingsWindow, self).__init__(parent) super(GlobalSettingsWindow, self).__init__(parent)
@ -44,7 +45,10 @@ class GlobalSettingsWindow(ui_globalsettingsdlg.Ui_GlobalSettings, QtGui.QDialog
self.setupUi(self) self.setupUi(self)
self.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), self.save_and_apply) self.connect(
self.buttonBox,
QtCore.SIGNAL("accepted()"),
self.save_and_apply)
self.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), self.reject) self.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), self.reject)
self.__init_system_defaults__() self.__init_system_defaults__()
@ -87,7 +91,8 @@ class GlobalSettingsWindow(ui_globalsettingsdlg.Ui_GlobalSettings, QtGui.QDialog
self.clock_vm_combo.setCurrentIndex(self.clockvm_idx) self.clock_vm_combo.setCurrentIndex(self.clockvm_idx)
# default netvm # default netvm
netvms = [vm for vm in all_vms if getattr(vm, 'provides_network', False)] netvms = [vm for vm in all_vms
if getattr(vm, 'provides_network', False)]
self.netvm_idx = -1 self.netvm_idx = -1
current_netvm = self.qvm_collection.default_netvm current_netvm = self.qvm_collection.default_netvm
@ -150,7 +155,8 @@ class GlobalSettingsWindow(ui_globalsettingsdlg.Ui_GlobalSettings, QtGui.QDialog
def __init_kernel_defaults__(self): def __init_kernel_defaults__(self):
kernel_list = [] kernel_list = []
# TODO system_path["qubes_kernels_base_dir"] idea: qubes.pulls['linux-kernel'].volumes # TODO system_path["qubes_kernels_base_dir"]
# idea: qubes.pulls['linux-kernel'].volumes
for k in os.listdir('/var/lib/qubes/vm-kernels'): for k in os.listdir('/var/lib/qubes/vm-kernels'):
kernel_list.append(k) kernel_list.append(k)
@ -181,8 +187,10 @@ class GlobalSettingsWindow(ui_globalsettingsdlg.Ui_GlobalSettings, QtGui.QDialog
self.qmemman_config.read(qmemman_config_path) self.qmemman_config.read(qmemman_config_path)
if self.qmemman_config.has_section('global'): if self.qmemman_config.has_section('global'):
self.vm_min_mem_val = self.qmemman_config.get('global', 'vm-min-mem') self.vm_min_mem_val = \
self.dom0_mem_boost_val = self.qmemman_config.get('global', 'dom0-mem-boost') self.qmemman_config.get('global', 'vm-min-mem')
self.dom0_mem_boost_val = \
self.qmemman_config.get('global', 'dom0-mem-boost')
self.vm_min_mem_val = parse_size(self.vm_min_mem_val) 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.dom0_mem_boost_val = parse_size(self.dom0_mem_boost_val)
@ -197,7 +205,8 @@ class GlobalSettingsWindow(ui_globalsettingsdlg.Ui_GlobalSettings, QtGui.QDialog
current_min_vm_mem = self.min_vm_mem.value() current_min_vm_mem = self.min_vm_mem.value()
current_dom0_mem_boost = self.dom0_mem_boost.value() current_dom0_mem_boost = self.dom0_mem_boost.value()
if current_min_vm_mem*1024*1024 != self.vm_min_mem_val or current_dom0_mem_boost*1024*1024 != self.dom0_mem_boost_val: if current_min_vm_mem*1024*1024 != self.vm_min_mem_val \
or current_dom0_mem_boost*1024*1024 != self.dom0_mem_boost_val:
current_min_vm_mem = str(current_min_vm_mem)+'M' current_min_vm_mem = str(current_min_vm_mem)+'M'
current_dom0_mem_boost = str(current_dom0_mem_boost)+'M' current_dom0_mem_boost = str(current_dom0_mem_boost)+'M'
@ -205,20 +214,28 @@ class GlobalSettingsWindow(ui_globalsettingsdlg.Ui_GlobalSettings, QtGui.QDialog
if not self.qmemman_config.has_section('global'): if not self.qmemman_config.has_section('global'):
#add the whole section #add the whole section
self.qmemman_config.add_section('global') self.qmemman_config.add_section('global')
self.qmemman_config.set('global', 'vm-min-mem', current_min_vm_mem) self.qmemman_config.set(
self.qmemman_config.set('global', 'dom0-mem-boost', current_dom0_mem_boost) 'global', 'vm-min-mem', current_min_vm_mem)
self.qmemman_config.set('global', 'cache-margin-factor', str(1.3)) # removed qmemman_algo.CACHE_FACTOR 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
qmemman_config_file = open(qmemman_config_path, 'a') qmemman_config_file = open(qmemman_config_path, 'a')
self.qmemman_config.write(qmemman_config_file) self.qmemman_config.write(qmemman_config_file)
qmemman_config_file.close() qmemman_config_file.close()
else: else:
#If there already is a 'global' section, we don't use SafeConfigParser.write() - it would get rid of all the comments... #If there already is a 'global' section, we don't use
# SafeConfigParser.write() - it would get rid of
# all the comments...
lines_to_add = {} lines_to_add = {}
lines_to_add['vm-min-mem'] = "vm-min-mem = " + current_min_vm_mem + "\n" lines_to_add['vm-min-mem'] = \
lines_to_add['dom0-mem-boost'] = "dom0-mem-boost = " + current_dom0_mem_boost +"\n" "vm-min-mem = " + current_min_vm_mem + "\n"
lines_to_add['dom0-mem-boost'] = \
"dom0-mem-boost = " + current_dom0_mem_boost +"\n"
config_lines = [] config_lines = []
@ -256,11 +273,13 @@ class GlobalSettingsWindow(ui_globalsettingsdlg.Ui_GlobalSettings, QtGui.QDialog
def __apply_updates__(self): def __apply_updates__(self):
if self.updates_dom0.isChecked() != self.updates_dom0_val: if self.updates_dom0.isChecked() != self.updates_dom0_val:
# TODO updates_dom0_toggle(self.qvm_collection, self.updates_dom0.isChecked()) # TODO updates_dom0_toggle(
# self.qvm_collection, self.updates_dom0.isChecked())
raise NotImplementedError('Toggle dom0 updates not implemented') raise NotImplementedError('Toggle dom0 updates not implemented')
if self.updates_vm.checkState() != QtCore.Qt.PartiallyChecked: if self.updates_vm.checkState() != QtCore.Qt.PartiallyChecked:
for vm in self.qvm_collection.domains: for vm in self.qvm_collection.domains:
vm.features['check-updates'] = bool(self.updates_vm.checkState()) vm.features['check-updates'] = \
bool(self.updates_vm.checkState())
def reject(self): def reject(self):
self.done(0) self.done(0)
@ -285,11 +304,12 @@ def handle_exception( exc_type, exc_value, exc_traceback ):
filename = os.path.basename( filename ) filename = os.path.basename( filename )
error = "%s: %s" % ( exc_type.__name__, exc_value ) error = "%s: %s" % ( exc_type.__name__, exc_value )
QtGui.QMessageBox.critical(None, "Houston, we have a problem...", QtGui.QMessageBox.critical(
None,
"Houston, we have a problem...",
"Whoops. A critical error has occured. This is most likely a bug " "Whoops. A critical error has occured. This is most likely a bug "
"in Qubes Global Settings application.<br><br>" "in Qubes Global Settings application.<br><br><b><i>%s</i></b>" %
"<b><i>%s</i></b>" % error + error + "at <b>line %d</b> of file <b>%s</b>.<br/><br/>"
"at <b>line %d</b> of file <b>%s</b>.<br/><br/>"
% ( line, filename )) % ( line, filename ))

View File

@ -1,7 +1,8 @@
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
from . import ui_multiselectwidget from . import ui_multiselectwidget
class MultiSelectWidget(ui_multiselectwidget.Ui_MultiSelectWidget, QtGui.QWidget): class MultiSelectWidget(
ui_multiselectwidget.Ui_MultiSelectWidget, QtGui.QWidget):
__pyqtSignals__ = ("selected_changed()",) __pyqtSignals__ = ("selected_changed()",)
__pyqtSignals__ = ("items_added(PyQt_PyObject)",) __pyqtSignals__ = ("items_added(PyQt_PyObject)",)
@ -14,8 +15,10 @@ class MultiSelectWidget(ui_multiselectwidget.Ui_MultiSelectWidget, QtGui.QWidget
self.add_all_button.clicked.connect(self.add_all) self.add_all_button.clicked.connect(self.add_all)
self.remove_selected_button.clicked.connect(self.remove_selected) self.remove_selected_button.clicked.connect(self.remove_selected)
self.remove_all_button.clicked.connect(self.remove_all) self.remove_all_button.clicked.connect(self.remove_all)
self.available_list.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection) self.available_list.setSelectionMode(
self.selected_list.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection) QtGui.QAbstractItemView.ExtendedSelection)
self.selected_list.setSelectionMode(
QtGui.QAbstractItemView.ExtendedSelection)
def switch_selected(self, src, dst): def switch_selected(self, src, dst):
selected = src.selectedItems() selected = src.selectedItems()

View File

@ -69,7 +69,9 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
assert (idx in range(self.tabWidget.count())) assert (idx in range(self.tabWidget.count()))
self.tabWidget.setCurrentIndex(idx) self.tabWidget.setCurrentIndex(idx)
self.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), self.save_and_apply) self.connect(self.buttonBox,
QtCore.SIGNAL("accepted()"),
self.save_and_apply)
self.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), self.reject) self.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), self.reject)
self.tabWidget.currentChanged.connect(self.current_tab_changed) self.tabWidget.currentChanged.connect(self.current_tab_changed)
@ -85,10 +87,16 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
###### advanced tab ###### advanced tab
self.__init_advanced_tab__() self.__init_advanced_tab__()
self.include_in_balancing.stateChanged.connect(self.include_in_balancing_state_changed) self.include_in_balancing.stateChanged.connect(
self.connect(self.init_mem, QtCore.SIGNAL("editingFinished()"), self.check_mem_changes) self.include_in_balancing_state_changed)
self.connect(self.max_mem_size, QtCore.SIGNAL("editingFinished()"), self.check_mem_changes) self.connect(self.init_mem,
self.bootFromDeviceButton.clicked.connect(self.boot_from_cdrom_button_pressed) QtCore.SIGNAL("editingFinished()"),
self.check_mem_changes)
self.connect(self.max_mem_size,
QtCore.SIGNAL("editingFinished()"),
self.check_mem_changes)
self.bootFromDeviceButton.clicked.connect(
self.boot_from_cdrom_button_pressed)
###### firewall tab ###### firewall tab
if self.tabWidget.isTabEnabled(self.tabs_indices['firewall']): if self.tabWidget.isTabEnabled(self.tabs_indices['firewall']):
@ -102,13 +110,16 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
self.newRuleButton.clicked.connect(self.new_rule_button_pressed) self.newRuleButton.clicked.connect(self.new_rule_button_pressed)
self.editRuleButton.clicked.connect(self.edit_rule_button_pressed) self.editRuleButton.clicked.connect(self.edit_rule_button_pressed)
self.deleteRuleButton.clicked.connect(self.delete_rule_button_pressed) self.deleteRuleButton.clicked.connect(
self.delete_rule_button_pressed)
self.policyDenyRadioButton.clicked.connect(self.policy_changed) self.policyDenyRadioButton.clicked.connect(self.policy_changed)
self.policyAllowRadioButton.clicked.connect(self.policy_changed) self.policyAllowRadioButton.clicked.connect(self.policy_changed)
####### devices tab ####### devices tab
self.__init_devices_tab__() self.__init_devices_tab__()
self.connect(self.dev_list, QtCore.SIGNAL("selected_changed()"), self.devices_selection_changed) self.connect(self.dev_list,
QtCore.SIGNAL("selected_changed()"),
self.devices_selection_changed)
####### services tab ####### services tab
self.__init_services_tab__() self.__init_services_tab__()
@ -120,7 +131,8 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
self.app_list = multiselectwidget.MultiSelectWidget(self) self.app_list = multiselectwidget.MultiSelectWidget(self)
self.apps_layout.addWidget(self.app_list) self.apps_layout.addWidget(self.app_list)
self.AppListManager = AppmenuSelectManager(self.vm, self.app_list) self.AppListManager = AppmenuSelectManager(self.vm, self.app_list)
self.refresh_apps_button.clicked.connect(self.refresh_apps_button_pressed) self.refresh_apps_button.clicked.connect(
self.refresh_apps_button_pressed)
def reject(self): def reject(self):
self.done(0) self.done(0)
@ -131,12 +143,14 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
def save_and_apply(self): def save_and_apply(self):
t_monitor = thread_monitor.ThreadMonitor() t_monitor = thread_monitor.ThreadMonitor()
thread = threading.Thread(target=self.__save_changes__, args=(t_monitor,)) thread = threading.Thread(target=self.__save_changes__,
args=(t_monitor,))
thread.daemon = True thread.daemon = True
thread.start() thread.start()
progress = QtGui.QProgressDialog( progress = QtGui.QProgressDialog(
self.tr("Applying settings to <b>{0}</b>...").format(self.vm.name), "", 0, 0) self.tr("Applying settings to <b>{0}</b>...").format(self.vm.name),
"", 0, 0)
progress.setCancelButton(None) progress.setCancelButton(None)
progress.setModal(True) progress.setModal(True)
progress.show() progress.show()
@ -148,8 +162,10 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
progress.hide() progress.hide()
if not t_monitor.success: if not t_monitor.success:
QtGui.QMessageBox.warning(None, QtGui.QMessageBox.warning(
self.tr("Error while changing settings for {0}!").format(self.vm.name), None,
self.tr("Error while changing settings for {0}!"
).format(self.vm.name),
self.tr("ERROR: {0}").format(t_monitor.error_msg)) self.tr("ERROR: {0}").format(t_monitor.error_msg))
self.done(0) self.done(0)
@ -177,7 +193,8 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
try: try:
if self.policyAllowRadioButton.isEnabled(): if self.policyAllowRadioButton.isEnabled():
self.fw_model.apply_rules(self.policyAllowRadioButton.isChecked(), self.fw_model.apply_rules(
self.policyAllowRadioButton.isChecked(),
self.tempFullAccess.isChecked(), self.tempFullAccess.isChecked(),
self.tempFullAccessTime.value()) self.tempFullAccessTime.value())
if self.fw_model.fw_changed: if self.fw_model.fw_changed:
@ -203,8 +220,11 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
if idx == self.tabs_indices["firewall"]: if idx == self.tabs_indices["firewall"]:
netvm = self.vm.netvm netvm = self.vm.netvm
if netvm is not None and \ if netvm is not None and \
not netvm.features.check_with_template('qubes-firewall', False): not netvm.features.check_with_template(
QtGui.QMessageBox.warning(None, 'qubes-firewall',
False):
QtGui.QMessageBox.warning(
None,
self.tr("VM configuration problem!"), self.tr("VM configuration problem!"),
self.tr("The '{vm}' AppVM is network connected to " self.tr("The '{vm}' AppVM is network connected to "
"'{netvm}', which does not support firewall!<br/>" "'{netvm}', which does not support firewall!<br/>"
@ -230,7 +250,10 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
def __init_basic_tab__(self): def __init_basic_tab__(self):
self.vmname.setText(self.vm.name) self.vmname.setText(self.vm.name)
self.vmname.setValidator(QtGui.QRegExpValidator(QtCore.QRegExp("[a-zA-Z0-9-]*", QtCore.Qt.CaseInsensitive), None)) self.vmname.setValidator(
QtGui.QRegExpValidator(
QtCore.QRegExp("[a-zA-Z0-9-]*",
QtCore.Qt.CaseInsensitive), None))
self.vmname.setEnabled(False) self.vmname.setEnabled(False)
self.rename_vm_button.setEnabled(not self.vm.is_running()) self.rename_vm_button.setEnabled(not self.vm.is_running())
self.delete_vm_button.setEnabled(not self.vm.is_running()) self.delete_vm_button.setEnabled(not self.vm.is_running())
@ -341,7 +364,8 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
#include in backups #include in backups
try: try:
if self.vm.include_in_backups != self.include_in_backups.isChecked(): if self.vm.include_in_backups != \
self.include_in_backups.isChecked():
self.vm.include_in_backups = self.include_in_backups.isChecked() self.vm.include_in_backups = self.include_in_backups.isChecked()
self.anything_changed = True self.anything_changed = True
except Exception as ex: except Exception as ex:
@ -388,14 +412,18 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
def check_mem_changes(self): def check_mem_changes(self):
if self.max_mem_size.value() < self.init_mem.value(): if self.max_mem_size.value() < self.init_mem.value():
QtGui.QMessageBox.warning(None, QtGui.QMessageBox.warning(
None,
self.tr("Warning!"), self.tr("Warning!"),
self.tr("Max memory can not be less than initial memory.<br>" self.tr("Max memory can not be less than initial memory.<br>"
"Setting max memory to equal initial memory.")) "Setting max memory to equal initial memory."))
self.max_mem_size.setValue(self.init_mem.value()) self.max_mem_size.setValue(self.init_mem.value())
# Linux specific limit: init memory must not be below max_mem_size/10.79 in order to allow scaling up to max_mem_size (or else "add_memory() failed: -17" problem) # Linux specific limit: init memory must not be below
# max_mem_size/10.79 in order to allow scaling up to
# max_mem_size (or else "add_memory() failed: -17" problem)
if self.init_mem.value() * 10 < self.max_mem_size.value(): if self.init_mem.value() * 10 < self.max_mem_size.value():
QtGui.QMessageBox.warning(None, QtGui.QMessageBox.warning(
None,
self.tr("Warning!"), self.tr("Warning!"),
self.tr("Initial memory can not be less than one tenth " self.tr("Initial memory can not be less than one tenth "
"Max memory.<br>Setting initial memory to the minimum " "Max memory.<br>Setting initial memory to the minimum "
@ -432,10 +460,10 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
def rename_vm(self): def rename_vm(self):
new_vm_name, ok = QtGui.QInputDialog.getText(self, new_vm_name, ok = QtGui.QInputDialog.getText(
self,
self.tr('Rename VM'), self.tr('Rename VM'),
self.tr('New name: (WARNING: ' self.tr('New name: (WARNING: all other changes will be discarded)'))
'all other changes will be discarded)'))
if ok: if ok:
self._run_in_thread(self._rename_vm, new_vm_name) self._run_in_thread(self._rename_vm, new_vm_name)
@ -565,7 +593,8 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
if hasattr(self.vm, "kernel") and self.kernel_groupbox.isVisible(): if hasattr(self.vm, "kernel") and self.kernel_groupbox.isVisible():
try: try:
if self.kernel.currentIndex() != self.kernel_idx: if self.kernel.currentIndex() != self.kernel_idx:
self.vm.kernel = self.kernel_list[self.kernel.currentIndex()] self.vm.kernel = self.kernel_list[
self.kernel.currentIndex()]
self.anything_changed = True self.anything_changed = True
except Exception as ex: except Exception as ex:
msg.append(str(ex)) msg.append(str(ex))
@ -613,7 +642,8 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
self.dev_list.available_list.addItem( self.dev_list.available_list.addItem(
DevListWidgetItem(name, ident)) DevListWidgetItem(name, ident))
if self.dev_list.selected_list.count() > 0 and self.include_in_balancing.isChecked(): if self.dev_list.selected_list.count() > 0\
and self.include_in_balancing.isChecked():
self.dmm_warning_adv.show() self.dmm_warning_adv.show()
self.dmm_warning_dev.show() self.dmm_warning_dev.show()
else: else:
@ -709,7 +739,9 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
self.refresh_apps_button.setText(self.tr('Refresh in progress...')) self.refresh_apps_button.setText(self.tr('Refresh in progress...'))
t_monitor = thread_monitor.ThreadMonitor() t_monitor = thread_monitor.ThreadMonitor()
thread = threading.Thread(target=self.refresh_apps_in_vm, args=(t_monitor,)) thread = threading.Thread(
target=self.refresh_apps_in_vm,
args=(t_monitor,))
thread.daemon = True thread.daemon = True
thread.start() thread.start()
@ -732,17 +764,23 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
service = feature[len('service.'):] service = feature[len('service.'):]
item = QtGui.QListWidgetItem(service) item = QtGui.QListWidgetItem(service)
item.setCheckState(ui_settingsdlg.QtCore.Qt.Checked item.setCheckState(ui_settingsdlg.QtCore.Qt.Checked
if self.vm.features[feature] else ui_settingsdlg.QtCore.Qt.Unchecked) if self.vm.features[feature]
else ui_settingsdlg.QtCore.Qt.Unchecked)
self.services_list.addItem(item) self.services_list.addItem(item)
self.new_srv_dict[service] = self.vm.features[feature] self.new_srv_dict[service] = self.vm.features[feature]
self.connect(self.services_list, QtCore.SIGNAL("itemClicked(QListWidgetItem *)"), self.services_item_clicked) self.connect(
self.services_list,
QtCore.SIGNAL("itemClicked(QListWidgetItem *)"),
self.services_item_clicked)
def __add_service__(self): def __add_service__(self):
srv = str(self.service_line_edit.text()).strip() srv = str(self.service_line_edit.text()).strip()
if srv != "": if srv != "":
if srv in self.new_srv_dict: if srv in self.new_srv_dict:
QtGui.QMessageBox.information(None, '', QtGui.QMessageBox.information(
None,
'',
self.tr('Service already on the list!')) self.tr('Service already on the list!'))
else: else:
item = QtGui.QListWidgetItem(srv) item = QtGui.QListWidgetItem(srv)
@ -756,9 +794,11 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
if not item: if not item:
return return
if str(item.text()) == 'meminfo-writer': if str(item.text()) == 'meminfo-writer':
QtGui.QMessageBox.information(None, QtGui.QMessageBox.information(
None,
self.tr('Service can not be removed'), self.tr('Service can not be removed'),
self.tr('Service meminfo-writer can not be removed from the list.')) self.tr('Service meminfo-writer can not '
'be removed from the list.'))
return return
row = self.services_list.currentRow() row = self.services_list.currentRow()
@ -782,11 +822,14 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
try: try:
for r in range(self.services_list.count()): for r in range(self.services_list.count()):
item = self.services_list.item(r) item = self.services_list.item(r)
self.new_srv_dict[str(item.text())] = (item.checkState() == ui_settingsdlg.QtCore.Qt.Checked) self.new_srv_dict[str(item.text())] = \
(item.checkState() == ui_settingsdlg.QtCore.Qt.Checked)
balancing_was_checked = self.vm.features.get('service.meminfo-writer', True) balancing_was_checked = self.vm.features.get(
'service.meminfo-writer', True)
balancing_is_checked = self.include_in_balancing.isChecked() balancing_is_checked = self.include_in_balancing.isChecked()
meminfo_writer_checked = self.new_srv_dict.get('meminfo-writer', True) meminfo_writer_checked = self.new_srv_dict.get(
'meminfo-writer', True)
if balancing_is_checked != meminfo_writer_checked: if balancing_is_checked != meminfo_writer_checked:
if balancing_is_checked != balancing_was_checked: if balancing_is_checked != balancing_was_checked:
@ -815,7 +858,8 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
def set_fw_model(self, model): def set_fw_model(self, model):
self.fw_model = model self.fw_model = model
self.rulesTreeView.setModel(model) self.rulesTreeView.setModel(model)
self.rulesTreeView.header().setResizeMode(QtGui.QHeaderView.ResizeToContents) self.rulesTreeView.header().setResizeMode(
QtGui.QHeaderView.ResizeToContents)
self.rulesTreeView.header().setResizeMode(0, QtGui.QHeaderView.Stretch) self.rulesTreeView.header().setResizeMode(0, QtGui.QHeaderView.Stretch)
self.set_allow(model.allow) self.set_allow(model.allow)
if model.tempFullAccessExpireTime: if model.tempFullAccessExpireTime:
@ -894,8 +938,8 @@ def handle_exception(exc_type, exc_value, exc_traceback):
msg_box.setDetailedText(strace) msg_box.setDetailedText(strace)
msg_box.setIcon(QtGui.QMessageBox.Critical) msg_box.setIcon(QtGui.QMessageBox.Critical)
msg_box.setWindowTitle("Houston, we have a problem...") msg_box.setWindowTitle("Houston, we have a problem...")
msg_box.setText("Whoops. A critical error has occured. This is most likely a bug " msg_box.setText("Whoops. A critical error has occured. "
"in Qubes Manager.<br><br>" "This is most likely a bug in Qubes Manager.<br><br>"
"<b><i>%s</i></b>" % error + "<b><i>%s</i></b>" % error +
"<br/>at line <b>%d</b><br/>of file %s.<br/><br/>" "<br/>at line <b>%d</b><br/>of file %s.<br/><br/>"
% ( line, filename )) % ( line, filename ))