File functions.py
has 853 lines of code (exceeds 250 allowed). Consider refactoring. Open
#!/usr/bin/python3
#
# functions.py
#
# thomas@linuxmuster.net
Function getDevicesArray
has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring. Open
def getDevicesArray(fieldnrs='', subnet='', pxeflag='', stype=False,
school='default-school'):
devices_array = []
if school == "default-school":
infile = open(constants.SOPHOSYSDIR
- 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 scpTransfer
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
def scpTransfer(ip, mode, sourcefile, targetfile, secret='', sshuser='root'):
if mode == 'get' or mode == 'put':
printScript(mode + ' ' + ip + ' ' + sourcefile + ' ' + targetfile)
else:
print('Usage: scpTransfer(ip, mode, sourcefile, targetfile, secret, sshuser)')
- 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 getStartconfOsValues
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def getStartconfOsValues(startconf):
rc, content = readStartconf(startconf)
if not rc:
return None
try:
- 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 getSubnetArray
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def getSubnetArray(fieldnrs=''):
infile = open(constants.SUBNETSCSV, newline='')
content = csv.reader(infile, delimiter=';', quoting=csv.QUOTE_NONE)
subnet_array = []
for row in content:
- 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 printScript
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
def printScript(msg='', header='', lf=True, noleft=False, noright=False,
offset=0):
linelen = 78
borderlen = 4
border = '#' * borderlen
- 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 enterPassword
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def enterPassword(pwtype='the', validate=True, repeat=True):
msg = '#### Enter ' + pwtype + ' password: '
re_msg = '#### Please re-enter ' + pwtype + ' password: '
while True:
password = getpass.getpass(msg)
- 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 subProc
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def subProc(cmd, logfile=None, hideopts=False):
try:
rc = True
p = Popen(cmd, shell=True, universal_newlines=True,
stdout=PIPE, stderr=PIPE)
- 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 ipMatchSubnet
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def ipMatchSubnet(ip, subnet):
if ip == 'DHCP' and subnet == 'all':
return True
if ip == 'DHCP':
return False
- 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 isValidHostIpv4
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def isValidHostIpv4(ip):
try:
ipv4 = IP(ip)
if not ipv4.version() == 4:
return False
- 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 printScript
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def printScript(msg='', header='', lf=True, noleft=False, noright=False,
Function scpTransfer
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def scpTransfer(ip, mode, sourcefile, targetfile, secret='', sshuser='root'):
Function getSftp
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def getSftp(ip, remotefile, localfile, secret='', sshuser='root'):
Function putSftp
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def putSftp(ip, localfile, remotefile, secret='', sshuser='root'):
Function getDevicesArray
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def getDevicesArray(fieldnrs='', subnet='', pxeflag='', stype=False,
Function sshExec
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def sshExec(ip, cmd, secret=''):
printScript('Executing ssh command on ' + ip + ':')
printScript('* -> "' + cmd + '"')
sshcmd = 'ssh -q -oNumberOfPasswordPrompts=0 -oStrictHostkeyChecking=no -l root ' + ip
# first test connection
- 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 getHostname
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def getHostname(devices, search):
try:
hostname = None
hostrow = None
f = open(devices, newline='')
- 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 firewallApi
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def firewallApi(request, path, data=''):
domainname = getSetupValue('domainname')
fwapi = configparser.RawConfigParser(
delimiters=('='), inline_comment_prefixes=('#', ';'))
fwapi.read(constants.FWAPIKEYS)
- 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 too many return
statements within this function. Open
return 'unknown'
Avoid too many return
statements within this function. Open
return True
Avoid too many return
statements within this function. Open
return False
Avoid too many return
statements within this function. Open
return True
Avoid too many return
statements within this function. Open
return False
Function getGrubPart
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def getGrubPart(partition, systemtype):
try:
partition = partition.replace('/dev/', '')
if re.findall(r'[hsv]d[a-z]', partition):
partnr = re.sub(r'[hsv]d[a-z]', '', partition)
- 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 getDefaultIface
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def getDefaultIface():
# first try to get a single interface
iface_list, iface_default = detectedInterfaces()
if iface_default != '':
return iface_list, iface_default
- 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 getBootImage
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def getBootImage(systemtype):
if systemtype is None or systemtype == '':
return None
if 'bios' in systemtype:
bootimage = 'i386-pc/core.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 getGrubOstype
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def getGrubOstype(osname):
osname = osname.lower()
if 'windows 10' in osname:
return 'win10'
if 'windows' in osname:
- 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 waitForFw
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def waitForFw(timeout=300, wait=0):
printScript('Waiting for opnsense to come up')
firewallip = getSetupValue('firewallip')
time.sleep(wait)
count = 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"