File view.py
has 1274 lines of code (exceeds 250 allowed). Consider refactoring. Open
#!/usr/bin/env python
"""
LEGION (https://shanewilliamscott.com)
Copyright (c) 2024 Shane Scott
View
has 113 functions (exceeds 50 allowed). Consider refactoring. Open
class View(QtCore.QObject):
tick = QtCore.pyqtSignal(int, name="changed") # signal used to update the progress bar
def __init__(self, viewState: ViewState, ui, ui_mainwindow, shell: Shell, app, loop):
QtCore.QObject.__init__(self)
Function contextMenuServiceNamesTableView
has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring. Open
def contextMenuServiceNamesTableView(self, pos):
if len(self.ui.ServiceNamesTableView.selectionModel().selectedRows()) > 0:
row = self.ui.ServiceNamesTableView.selectionModel().selectedRows()[len(
self.ui.ServiceNamesTableView.selectionModel().selectedRows())-1].row()
self.viewState.service_clicked = self.ServiceNamesTableModel.getServiceNameForRow(row)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function callAddHosts
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
def callAddHosts(self):
hostListStr = str(self.adddialog.txtHostList.toPlainText()).replace(';',' ')
nmapOptions = []
scanMode = 'Unset'
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function contextMenuServicesTableView
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
def contextMenuServicesTableView(self, pos):
if len(self.ui.ServicesTableView.selectionModel().selectedRows()) > 0:
# if there is only one row selected, get service name
if len(self.ui.ServicesTableView.selectionModel().selectedRows()) == 1:
row = self.ui.ServicesTableView.selectionModel().selectedRows()[len(
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function toolHostsClick
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
def toolHostsClick(self):
if self.ui.ToolHostsTableView.selectionModel().selectedRows():
row = self.ui.ToolHostsTableView.selectionModel().selectedRows()[len(
self.ui.ToolHostsTableView.selectionModel().selectedRows())-1].row()
self.viewState.tool_host_clicked = self.ToolHostsTableModel.getProcessIdForRow(row)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function updateInformationView
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
def updateInformationView(self, hostIP):
if hostIP:
host = self.controller.getHostInformation(hostIP)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function saveProjectAs
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
def saveProjectAs(self):
self.ui.statusbar.showMessage('Saving..')
log.info('Saving project..')
self.controller.saveProject(self.viewState.lastHostIdClicked, self.ui.NotesTextEdit.toPlainText())
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function closeHostToolTab
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
def closeHostToolTab(self, index):
currentTabIndex = self.ui.ServicesTabWidget.currentIndex() # remember the currently selected tab
self.ui.ServicesTabWidget.setCurrentIndex(index) # select the tab for which the cross button was clicked
currentWidget = self.ui.ServicesTabWidget.currentWidget()
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function closeBruteTab
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def closeBruteTab(self, index):
currentTabIndex = self.ui.BruteTabWidget.currentIndex() # remember the currently selected tab
# select the tab for which the cross button was clicked
self.ui.BruteTabWidget.setCurrentIndex(index)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function contextToolHostsTableContextMenu
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def contextToolHostsTableContextMenu(self, pos):
if len(self.ui.ToolHostsTableView.selectionModel().selectedRows()) > 0:
row = self.ui.ToolHostsTableView.selectionModel().selectedRows()[len(
self.ui.ToolHostsTableView.selectionModel().selectedRows())-1].row()
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function openExistingProject
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def openExistingProject(self):
if self.dealWithCurrentProject():
filename = QtWidgets.QFileDialog.getOpenFileName(
self.ui.centralwidget, 'Open project', self.controller.getCWD(),
filter='Legion session (*.legion);; Sparta session (*.sprt)')[0]
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function startConnections
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
def startConnections(self): # signal initialisations (signals/slots, actions, etc)
### MENU ACTIONS ###
self.connectCreateNewProject()
self.connectOpenExistingProject()
self.connectSaveProject()
Function switchTabClick
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def switchTabClick(self):
if self.ServiceNamesTableModel: # fixes bug when switching tabs at start-up
selectedTab = self.ui.HostsTabWidget.tabText(self.ui.HostsTabWidget.currentIndex())
if selectedTab == 'Hosts':
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function initTables
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
def initTables(self): # this function prepares the default settings for each table
# hosts table (left)
headers = ["Id", "OS", "Accuracy", "Host", "IPv4", "IPv6", "Mac", "Status", "Hostname", "Vendor", "Uptime",
"Lastboot", "Distance", "CheckedHost", "Country Code", "State", "City", "Latitude", "Longitude",
"Count", "Closed"]
Function start
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
def start(self, title='*untitled'):
self.viewState = ViewState()
self.ui.keywordTextInput.setText('') # clear keyword filter
self.ProcessesTableModel = None # fixes bug when sorting processes for the first time
Function updateToolsTableView
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def updateToolsTableView(self):
if self.ui.MainTabWidget.tabText(self.ui.MainTabWidget.currentIndex()) == 'Scan' and \
self.ui.HostsTabWidget.tabText(self.ui.HostsTabWidget.currentIndex()) == 'Tools':
self.ToolsTableModel.setDataList(
self.controller.getProcessesFromDB(self.viewState.filters,
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function createNewTabForHost
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def createNewTabForHost(self, ip, tabTitle, restoring=False, content='', filename=''):
# TODO: use regex otherwise tools with 'screenshot' in the name are screwed.
if 'screenshot' in str(tabTitle):
tempWidget = ImageViewer()
tempWidget.setObjectName(str(tabTitle))
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function callHydra
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def callHydra(self, bWidget):
if validateNmapInput(bWidget.ipTextinput.text()) and validateNmapInput(bWidget.portTextinput.text()):
# check if host is already in scope
if not self.controller.isHostInDB(bWidget.ipTextinput.text()):
message = "This host is not in scope. Add it to scope and continue?"
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function restoreToolTabWidget
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def restoreToolTabWidget(self, clear=False):
if self.ui.DisplayWidget.findChild(QtWidgets.QPlainTextEdit) == self.ui.toolOutputTextView:
return
for host in self.viewState.hostTabs.keys():
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid deeply nested control flow statements. Open
if len(nmapOptionValueSplit) > 1:
nmapOptionValue = nmapOptionValueSplit[1].replace(']','')
nmapOptions.append(nmapOptionValue)
nmapOptions.append(str(self.adddialog.txtCustomOptList.text()))
Avoid deeply nested control flow statements. Open
if host in targets:
targets.remove(host)
Function restoreToolTabsForHost
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def restoreToolTabsForHost(self, ip):
if (self.viewState.hostTabs) and (ip in self.viewState.hostTabs):
tabs = self.viewState.hostTabs[ip] # use the ip as a key to retrieve its list of tooltabs
for tab in tabs:
# do not display hydra and nmap tabs when restoring for that host
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function restoreToolTabs
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def restoreToolTabs(self):
# false means we are fetching processes with display flag=False, which is the case for every process once
# a project is closed.
tools = self.controller.getProcessesFromDB(self.viewState.filters, showProcesses=False)
nbr = len(tools) # show a progress bar because this could take long
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function __init__
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def __init__(self, viewState: ViewState, ui, ui_mainwindow, shell: Shell, app, loop):
Function createNewTabForHost
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def createNewTabForHost(self, ip, tabTitle, restoring=False, content='', filename=''):
Function contextMenuProcessesTableView
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def contextMenuProcessesTableView(self, pos):
if self.ui.ProcessesTableView.selectionModel() and self.ui.ProcessesTableView.selectionModel().selectedRows():
menu = self.controller.getContextMenuForProcess()
menu.aboutToShow.connect(self.setVisible)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"