Fixed invalid names

Fixed camel case, too long and too short variable and function names.
This commit is contained in:
Marta Marczykowska-Górecka 2017-11-08 16:53:49 +01:00
parent d7fbacf0d7
commit 6e5d611f70
No known key found for this signature in database
GPG Key ID: 9A752C30B26FD04B
7 changed files with 117 additions and 107 deletions

View File

@ -85,7 +85,7 @@ variable-rgx=[a-z_][a-z0-9_]{2,30}$
inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$
# Good variable names which should always be accepted, separated by a comma
good-names=e,i,j,k,m,p,v,ex,Run,_,log,vm
good-names=e,i,j,k,m,p,v,ex,Run,_,log,vm,ok
# Bad variable names which should always be refused, separated by a comma
bad-names=foo,bar,baz,toto,tutu,tata

View File

@ -61,11 +61,11 @@ class AppmenuSelectManager:
'--get-available', '--i-understand-format-is-unstable',
self.vm.name]).decode().splitlines()]
for a in available_appmenus:
if a.ident in self.whitelisted:
self.app_list.selected_list.addItem(a)
for app in available_appmenus:
if app.ident in self.whitelisted:
self.app_list.selected_list.addItem(app)
else:
self.app_list.available_list.addItem(a)
self.app_list.available_list.addItem(app)
self.app_list.available_list.sortItems()
self.app_list.selected_list.sortItems()

View File

@ -74,7 +74,7 @@ class NewFwRuleDlg(QtGui.QDialog, ui_newfwruledlg.Ui_NewFwRuleDlg):
super(NewFwRuleDlg, self).__init__(parent)
self.setupUi(self)
self.set_ok_enabled(False)
self.set_ok_state(False)
self.addressComboBox.setValidator(QIPAddressValidator())
self.addressComboBox.editTextChanged.connect(
self.address_editing_finished)
@ -117,12 +117,12 @@ class NewFwRuleDlg(QtGui.QDialog, ui_newfwruledlg.Ui_NewFwRuleDlg):
self.serviceComboBox.addItem(service)
def address_editing_finished(self):
self.set_ok_enabled(True)
self.set_ok_state(True)
def set_ok_enabled(self, on):
def set_ok_state(self, ok_state):
ok_button = self.buttonBox.button(QtGui.QDialogButtonBox.Ok)
if ok_button is not None:
ok_button.setEnabled(on)
ok_button.setEnabled(ok_state)
def on_tcp_radio_toggled(self, checked):
if checked:
@ -140,19 +140,19 @@ class QubesFirewallRulesModel(QtCore.QAbstractItemModel):
def __init__(self, parent=None):
QtCore.QAbstractItemModel.__init__(self, parent)
self.__columnNames = {0: "Address", 1: "Service", 2: "Protocol", }
self.__column_names = {0: "Address", 1: "Service", 2: "Protocol", }
self.__services = list()
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')
for line in f:
file = open('/etc/services', 'r')
for line in file:
match = pattern.match(line)
if match is not None:
service = match.groupdict()
self.__services.append(
(service["name"], int(service["port"]),))
f.close()
file.close()
self.fw_changed = False
@ -164,7 +164,7 @@ class QubesFirewallRulesModel(QtCore.QAbstractItemModel):
, reverse=rev)
index1 = self.createIndex(0, 0)
index2 = self.createIndex(len(self)-1, len(self.__columnNames)-1)
index2 = self.createIndex(len(self) - 1, len(self.__column_names) - 1)
self.dataChanged.emit(index1, index2)
@ -219,8 +219,8 @@ class QubesFirewallRulesModel(QtCore.QAbstractItemModel):
'rules': [],
}
allowDns = False
allowIcmp = False
allow_dns = False
allow_icmp = False
common_action = None
reversed_rules = list(reversed(vm.firewall.rules))
@ -241,11 +241,11 @@ class QubesFirewallRulesModel(QtCore.QAbstractItemModel):
rule = reversed_rules.pop(0)
if rule == dns_rule:
allowDns = True
allow_dns = True
continue
if rule.proto == icmp_rule:
allowIcmp = True
allow_icmp = True
continue
if rule.specialtarget is not None or rule.icmptype is not None:
@ -268,10 +268,10 @@ class QubesFirewallRulesModel(QtCore.QAbstractItemModel):
conf['allow'] = (common_action == 'accept')
if not allowIcmp and not conf['allow']:
if not allow_icmp and not conf['allow']:
raise FirewallModifiedOutsideError('ICMP must be allowed.')
if not allowDns and not conf['allow']:
if not allow_dns and not conf['allow']:
raise FirewallModifiedOutsideError('DNS must be allowed')
return conf
@ -302,26 +302,26 @@ class QubesFirewallRulesModel(QtCore.QAbstractItemModel):
def set_vm(self, vm):
self.__vm = vm
self.clearChildren()
self.clear_children()
conf = self.get_firewall_conf(vm)
self.allow = conf["allow"]
self.tempFullAccessExpireTime = conf['expire']
self.temp_full_access_expire_time = conf['expire']
for rule in conf["rules"]:
self.appendChild(rule)
self.append_child(rule)
def get_vm_name(self):
return self.__vm.name
def apply_rules(self, allow, tempFullAccess=False,
tempFullAccessTime=None):
def apply_rules(self, allow, temp_full_access=False,
temp_full_access_time=None):
assert self.__vm is not None
if self.allow != allow or \
(self.tempFullAccessExpireTime != 0) != tempFullAccess:
(self.temp_full_access_expire_time != 0) != temp_full_access:
self.fw_changed = True
conf = {"allow": allow,
@ -330,10 +330,12 @@ class QubesFirewallRulesModel(QtCore.QAbstractItemModel):
conf['rules'].extend(self.children)
if tempFullAccess and not allow:
conf["rules"].append(qubesadmin.firewall.Rule(None, action='accept'
, expire=int(datetime.datetime.now().strftime("%s"))+\
tempFullAccessTime*60))
if temp_full_access and not allow:
conf["rules"].append(qubesadmin.firewall.Rule(
None,
action='accept',
expire=int(datetime.datetime.now().strftime("%s")) +
temp_full_access_time * 60))
if self.fw_changed:
self.write_firewall_conf(self.__vm, conf)
@ -397,9 +399,9 @@ class QubesFirewallRulesModel(QtCore.QAbstractItemModel):
.format(service))
if row is not None:
self.setChild(row, rule)
self.set_child(row, rule)
else:
self.appendChild(rule)
self.append_child(rule)
def index(self, row, column, parent=QtCore.QModelIndex()):
if not self.hasIndex(row, column, parent):
@ -410,15 +412,18 @@ class QubesFirewallRulesModel(QtCore.QAbstractItemModel):
def parent(self, child):
return QtCore.QModelIndex()
# pylint: disable=invalid-name
def rowCount(self, parent=QtCore.QModelIndex()):
return len(self)
# pylint: disable=invalid-name
def columnCount(self, parent=QtCore.QModelIndex()):
return len(self.__columnNames)
return len(self.__column_names)
# pylint: disable=invalid-name
def hasChildren(self, index=QtCore.QModelIndex()):
parentItem = index.internalPointer()
if parentItem is not None:
parent_item = index.internalPointer()
if parent_item is not None:
return False
else:
return True
@ -428,17 +433,18 @@ class QubesFirewallRulesModel(QtCore.QAbstractItemModel):
return self.get_column_string(index.column(),
self.children[index.row()])
# pylint: disable=invalid-name
def headerData(self, section, orientation, role=QtCore.Qt.DisplayRole):
if section < len(self.__columnNames) \
if section < len(self.__column_names) \
and orientation == QtCore.Qt.Horizontal \
and role == QtCore.Qt.DisplayRole:
return self.__columnNames[section]
return self.__column_names[section]
@property
def children(self):
return self.__children
def appendChild(self, child):
def append_child(self, child):
row = len(self)
self.beginInsertRows(QtCore.QModelIndex(), row, row)
self.children.append(child)
@ -447,7 +453,7 @@ class QubesFirewallRulesModel(QtCore.QAbstractItemModel):
self.dataChanged.emit(index, index)
self.fw_changed = True
def removeChild(self, i):
def remove_child(self, i):
if i >= len(self):
return
@ -458,13 +464,13 @@ class QubesFirewallRulesModel(QtCore.QAbstractItemModel):
self.dataChanged.emit(index, index)
self.fw_changed = True
def setChild(self, i, child):
def set_child(self, i, child):
self.children[i] = child
index = self.createIndex(i, 0, child)
self.dataChanged.emit(index, index)
self.fw_changed = True
def clearChildren(self):
def clear_children(self):
self.__children = list()
def __len__(self):

View File

@ -240,20 +240,20 @@ class GlobalSettingsWindow(ui_globalsettingsdlg.Ui_GlobalSettings,
config_lines = []
qmemman_config_file = open(qmemman_config_path, 'r')
for l in qmemman_config_file:
if l.strip().startswith('vm-min-mem'):
for line in qmemman_config_file:
if line.strip().startswith('vm-min-mem'):
config_lines.append(lines_to_add['vm-min-mem'])
del lines_to_add['vm-min-mem']
elif l.strip().startswith('dom0-mem-boost'):
elif line.strip().startswith('dom0-mem-boost'):
config_lines.append(lines_to_add['dom0-mem-boost'])
del lines_to_add['dom0-mem-boost']
else:
config_lines.append(l)
config_lines.append(line)
qmemman_config_file.close()
for l in lines_to_add:
config_lines.append(l)
for line in lines_to_add:
config_lines.append(line)
qmemman_config_file = open(qmemman_config_path, 'w')
qmemman_config_file.writelines(config_lines)

View File

@ -24,8 +24,8 @@ class MultiSelectWidget(
selected = src.selectedItems()
items = []
for s in selected:
row = src.indexFromItem(s).row()
for selected_item in selected:
row = src.indexFromItem(selected_item).row()
item = src.takeItem(row)
dst.addItem(item)
items.append(item)

View File

@ -89,14 +89,14 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
###### advanced tab
self.__init_advanced_tab__()
self.include_in_balancing.stateChanged.connect(
self.include_in_balancing_state_changed)
self.include_in_balancing_changed)
self.connect(self.init_mem,
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_device_button.clicked.connect(
self.boot_from_cdrom_button_pressed)
###### firewall tab
@ -105,16 +105,16 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
try:
model.set_vm(vm)
self.set_fw_model(model)
self.firewallModifiedOutsidelabel.setVisible(False)
self.firewall_modified_outside_label.setVisible(False)
except firewall.FirewallModifiedOutsideError as ex:
self.disable_all_fw_conf()
self.newRuleButton.clicked.connect(self.new_rule_button_pressed)
self.editRuleButton.clicked.connect(self.edit_rule_button_pressed)
self.deleteRuleButton.clicked.connect(
self.new_rule_button.clicked.connect(self.new_rule_button_pressed)
self.edit_rule_button.clicked.connect(self.edit_rule_button_pressed)
self.delete_rule_button.clicked.connect(
self.delete_rule_button_pressed)
self.policyDenyRadioButton.clicked.connect(self.policy_changed)
self.policyAllowRadioButton.clicked.connect(self.policy_changed)
self.policy_deny_radio_button.clicked.connect(self.policy_changed)
self.policy_allow_radio_button.clicked.connect(self.policy_changed)
####### devices tab
self.__init_devices_tab__()
@ -131,7 +131,7 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
if self.tabWidget.isTabEnabled(self.tabs_indices["applications"]):
self.app_list = multiselectwidget.MultiSelectWidget(self)
self.apps_layout.addWidget(self.app_list)
self.AppListManager = AppmenuSelectManager(self.vm, self.app_list)
self.app_list_manager = AppmenuSelectManager(self.vm, self.app_list)
self.refresh_apps_button.clicked.connect(
self.refresh_apps_button_pressed)
@ -195,11 +195,11 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
ret.append(repr(ex))
try:
if self.policyAllowRadioButton.isEnabled():
if self.policy_allow_radio_button.isEnabled():
self.fw_model.apply_rules(
self.policyAllowRadioButton.isChecked(),
self.tempFullAccess.isChecked(),
self.tempFullAccessTime.value())
self.policy_allow_radio_button.isChecked(),
self.temp_full_access.isChecked(),
self.temp_full_access_time.value())
if self.fw_model.fw_changed:
# might modified vm.services
self.anything_changed = True
@ -210,7 +210,7 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
try:
if self.tabWidget.isTabEnabled(self.tabs_indices["applications"]):
self.AppListManager.save_appmenu_select_changes()
self.app_list_manager.save_appmenu_select_changes()
except qubesadmin.exc.QubesException as qex:
ret += [self.tr("Applications tab:"), str(qex)]
except Exception as ex: # pylint: disable=broad-except
@ -700,9 +700,9 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
return msg
def include_in_balancing_state_changed(self, state):
for r in range(self.services_list.count()):
item = self.services_list.item(r)
def include_in_balancing_changed(self, state):
for i in range(self.services_list.count()):
item = self.services_list.item(i)
if str(item.text()) == 'meminfo-writer':
item.setCheckState(state)
break
@ -762,7 +762,7 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
self.qapp.processEvents()
time.sleep(0.1)
self.AppListManager = AppmenuSelectManager(self.vm, self.app_list)
self.app_list_manager = AppmenuSelectManager(self.vm, self.app_list)
self.refresh_apps_button.setEnabled(True)
self.refresh_apps_button.setText(self.tr('Refresh Applications'))
@ -833,8 +833,8 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
msg = []
try:
for r in range(self.services_list.count()):
item = self.services_list.item(r)
for i in range(self.services_list.count()):
item = self.services_list.item(i)
self.new_srv_dict[str(item.text())] = \
(item.checkState() == ui_settingsdlg.QtCore.Qt.Checked)
@ -875,37 +875,41 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
QtGui.QHeaderView.ResizeToContents)
self.rulesTreeView.header().setResizeMode(0, QtGui.QHeaderView.Stretch)
self.set_allow(model.allow)
if model.tempFullAccessExpireTime:
self.tempFullAccess.setChecked(True)
self.tempFullAccessTime.setValue(
(model.tempFullAccessExpireTime -
if model.temp_full_access_expire_time:
self.temp_full_access.setChecked(True)
self.temp_full_access_time.setValue(
(model.temp_full_access_expire_time -
int(firewall.datetime.datetime.now().strftime("%s"))) / 60)
def disable_all_fw_conf(self):
self.firewallModifiedOutsidelabel.setVisible(True)
self.policyAllowRadioButton.setEnabled(False)
self.policyDenyRadioButton.setEnabled(False)
self.firewall_modified_outside_label.setVisible(True)
self.policy_allow_radio_button.setEnabled(False)
self.policy_deny_radio_button.setEnabled(False)
self.rulesTreeView.setEnabled(False)
self.newRuleButton.setEnabled(False)
self.editRuleButton.setEnabled(False)
self.deleteRuleButton.setEnabled(False)
self.firewalRulesLabel.setEnabled(False)
self.new_rule_button.setEnabled(False)
self.edit_rule_button.setEnabled(False)
self.delete_rule_button.setEnabled(False)
self.firewal_rules_label.setEnabled(False)
self.tempFullAccessWidget.setEnabled(False)
def set_allow(self, allow):
self.policyAllowRadioButton.setChecked(allow)
self.policyDenyRadioButton.setChecked(not allow)
self.policy_allow_radio_button.setChecked(allow)
self.policy_deny_radio_button.setChecked(not allow)
self.policy_changed(allow)
def policy_changed(self, checked):
self.rulesTreeView.setEnabled(self.policyDenyRadioButton.isChecked())
self.newRuleButton.setEnabled(self.policyDenyRadioButton.isChecked())
self.editRuleButton.setEnabled(self.policyDenyRadioButton.isChecked())
self.deleteRuleButton.setEnabled(self.policyDenyRadioButton.isChecked())
self.firewalRulesLabel.setEnabled(
self.policyDenyRadioButton.isChecked())
def policy_changed(self):
self.rulesTreeView.setEnabled(
self.policy_deny_radio_button.isChecked())
self.new_rule_button.setEnabled(
self.policy_deny_radio_button.isChecked())
self.edit_rule_button.setEnabled(
self.policy_deny_radio_button.isChecked())
self.delete_rule_button.setEnabled(
self.policy_deny_radio_button.isChecked())
self.firewal_rules_label.setEnabled(
self.policy_deny_radio_button.isChecked())
self.tempFullAccessWidget.setEnabled(
self.policyDenyRadioButton.isChecked())
self.policy_deny_radio_button.isChecked())
def new_rule_button_pressed(self):
dialog = firewall.NewFwRuleDlg()
@ -917,7 +921,7 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
if len(selected) > 0:
dialog = firewall.NewFwRuleDlg()
dialog.set_ok_enabled(True)
dialog.set_ok_state(True)
row = self.rulesTreeView.selectedIndexes().pop().row()
self.fw_model.populate_edit_dialog(dialog, row)
self.fw_model.run_rule_dialog(dialog, row)
@ -925,7 +929,7 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
def delete_rule_button_pressed(self):
for i in set([index.row() for index
in self.rulesTreeView.selectedIndexes()]):
self.fw_model.removeChild(i)
self.fw_model.remove_child(i)
# Bases on the original code by:

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>773</width>
<height>581</height>
<height>609</height>
</rect>
</property>
<property name="windowTitle">
@ -29,7 +29,7 @@
<locale language="English" country="UnitedStates"/>
</property>
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="basic_tab">
<property name="locale">
@ -487,7 +487,7 @@ border-width: 1px;</string>
<widget class="QComboBox" name="default_dispvm"/>
</item>
<item row="2" column="0" colspan="2">
<widget class="QPushButton" name="bootFromDeviceButton">
<widget class="QPushButton" name="boot_from_device_button">
<property name="text">
<string>Boot qube from CDROM</string>
</property>
@ -678,14 +678,14 @@ border-width: 1px;</string>
<item row="1" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QRadioButton" name="policyAllowRadioButton">
<widget class="QRadioButton" name="policy_allow_radio_button">
<property name="text">
<string>Allow all outgoing Internet connections</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="policyDenyRadioButton">
<widget class="QRadioButton" name="policy_deny_radio_button">
<property name="text">
<string>Limit outgoing Internet connections to ...</string>
</property>
@ -714,7 +714,7 @@ border-width: 1px;</string>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="firewalRulesLabel">
<widget class="QLabel" name="firewal_rules_label">
<property name="text">
<string>List of allowed (whitelisted) addresses:</string>
</property>
@ -736,14 +736,14 @@ border-width: 1px;</string>
<number>0</number>
</property>
<item row="1" column="0">
<widget class="QCheckBox" name="tempFullAccess">
<widget class="QCheckBox" name="temp_full_access">
<property name="text">
<string>Allow full access for </string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="tempFullAccessTime">
<widget class="QSpinBox" name="temp_full_access_time">
<property name="suffix">
<string> min</string>
</property>
@ -811,7 +811,7 @@ border-width: 1px;</string>
<item>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="QPushButton" name="newRuleButton">
<widget class="QPushButton" name="new_rule_button">
<property name="text">
<string/>
</property>
@ -828,7 +828,7 @@ border-width: 1px;</string>
</widget>
</item>
<item>
<widget class="QPushButton" name="editRuleButton">
<widget class="QPushButton" name="edit_rule_button">
<property name="text">
<string/>
</property>
@ -845,7 +845,7 @@ border-width: 1px;</string>
</widget>
</item>
<item>
<widget class="QPushButton" name="deleteRuleButton">
<widget class="QPushButton" name="delete_rule_button">
<property name="text">
<string/>
</property>
@ -879,7 +879,7 @@ border-width: 1px;</string>
</layout>
</item>
<item row="0" column="0">
<widget class="QLabel" name="firewallModifiedOutsidelabel">
<widget class="QLabel" name="firewall_modified_outside_label">
<property name="palette">
<palette>
<active>
@ -1117,10 +1117,10 @@ border-width: 1px;</string>
<tabstop>vcpus</tabstop>
<tabstop>include_in_balancing</tabstop>
<tabstop>kernel</tabstop>
<tabstop>newRuleButton</tabstop>
<tabstop>new_rule_button</tabstop>
<tabstop>rulesTreeView</tabstop>
<tabstop>editRuleButton</tabstop>
<tabstop>deleteRuleButton</tabstop>
<tabstop>edit_rule_button</tabstop>
<tabstop>delete_rule_button</tabstop>
<tabstop>service_line_edit</tabstop>
<tabstop>add_srv_button</tabstop>
<tabstop>services_list</tabstop>