linuxmuster/linuxmuster-base7

View on GitHub
lib/functions.py

Summary

Maintainability
F
5 days
Test Coverage

File functions.py has 853 lines of code (exceeds 250 allowed). Consider refactoring.
Open

#!/usr/bin/python3
#
# functions.py
#
# thomas@linuxmuster.net
Severity: Major
Found in lib/functions.py - About 2 days to fix

    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
    Severity: Minor
    Found in lib/functions.py - About 5 hrs to fix

    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)')
    Severity: Minor
    Found in lib/functions.py - About 2 hrs to fix

    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:
    Severity: Minor
    Found in lib/functions.py - About 2 hrs to fix

    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:
    Severity: Minor
    Found in lib/functions.py - About 2 hrs to fix

    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
    Severity: Minor
    Found in lib/functions.py - About 1 hr to fix

    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)
    Severity: Minor
    Found in lib/functions.py - About 1 hr to fix

    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)
    Severity: Minor
    Found in lib/functions.py - About 1 hr to fix

    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
    Severity: Minor
    Found in lib/functions.py - About 55 mins to fix

    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
    Severity: Minor
    Found in lib/functions.py - About 55 mins to fix

    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 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def scpTransfer(ip, mode, sourcefile, targetfile, secret='', sshuser='root'):
    Severity: Minor
    Found in lib/functions.py - About 45 mins to fix

      Function printScript has 6 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def printScript(msg='', header='', lf=True, noleft=False, noright=False,
      Severity: Minor
      Found in lib/functions.py - About 45 mins to fix

        Function getSftp has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        def getSftp(ip, remotefile, localfile, secret='', sshuser='root'):
        Severity: Minor
        Found in lib/functions.py - About 35 mins to fix

          Function getDevicesArray has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          def getDevicesArray(fieldnrs='', subnet='', pxeflag='', stype=False,
          Severity: Minor
          Found in lib/functions.py - About 35 mins to fix

            Function putSftp has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

            def putSftp(ip, localfile, remotefile, secret='', sshuser='root'):
            Severity: Minor
            Found in lib/functions.py - About 35 mins to fix

              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)
              Severity: Minor
              Found in lib/functions.py - About 35 mins to fix

              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 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
              Severity: Minor
              Found in lib/functions.py - About 35 mins to fix

              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='')
              Severity: Minor
              Found in lib/functions.py - About 35 mins to fix

              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 False
              Severity: Major
              Found in lib/functions.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                        return True
                Severity: Major
                Found in lib/functions.py - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                      return True
                  Severity: Major
                  Found in lib/functions.py - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                        return 'unknown'
                    Severity: Major
                    Found in lib/functions.py - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                  return False
                      Severity: Major
                      Found in lib/functions.py - About 30 mins to fix

                        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'
                        Severity: Minor
                        Found in lib/functions.py - About 25 mins to fix

                        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
                        Severity: Minor
                        Found in lib/functions.py - About 25 mins to fix

                        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 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)
                        Severity: Minor
                        Found in lib/functions.py - About 25 mins to fix

                        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
                        Severity: Minor
                        Found in lib/functions.py - About 25 mins to fix

                        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:
                        Severity: Minor
                        Found in lib/functions.py - About 25 mins to fix

                        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

                        There are no issues that match your filters.

                        Category
                        Status