saltstack/salt

View on GitHub
salt/modules/debuild_pkgbuild.py

Summary

Maintainability
F
1 wk
Test Coverage

Function make_repo has a Cognitive Complexity of 146 (exceeds 5 allowed). Consider refactoring.
Open

def make_repo(repodir,
              keyid=None,
              env=None,
              use_passphrase=False,
              gnupghome='/etc/salt/gpgkeys',
Severity: Minor
Found in salt/modules/debuild_pkgbuild.py - About 2 days 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

File debuild_pkgbuild.py has 743 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
'''
Debian Package builder system

.. versionadded:: 2015.8.0
Severity: Major
Found in salt/modules/debuild_pkgbuild.py - About 1 day to fix

    Cyclomatic complexity is too high in function make_repo. (55)
    Open

    def make_repo(repodir,
                  keyid=None,
                  env=None,
                  use_passphrase=False,
                  gnupghome='/etc/salt/gpgkeys',
    Severity: Minor
    Found in salt/modules/debuild_pkgbuild.py by radon

    Cyclomatic Complexity

    Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

    Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

    Construct Effect on CC Reasoning
    if +1 An if statement is a single decision.
    elif +1 The elif statement adds another decision.
    else +0 The else statement does not cause a new decision. The decision is at the if.
    for +1 There is a decision at the start of the loop.
    while +1 There is a decision at the while statement.
    except +1 Each except branch adds a new conditional path of execution.
    finally +0 The finally block is unconditionally executed.
    with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
    assert +1 The assert statement internally roughly equals a conditional statement.
    Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
    Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

    Source: http://radon.readthedocs.org/en/latest/intro.html

    Function _get_repo_dists_env has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
    Open

    def _get_repo_dists_env(env):
        '''
        Get repo environment overrides dictionary to use in repo distributions process
    
        env
    Severity: Minor
    Found in salt/modules/debuild_pkgbuild.py - About 4 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 build has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
    Open

    def build(runas,
              tgt,
              dest_dir,
              spec,
              sources,
    Severity: Minor
    Found in salt/modules/debuild_pkgbuild.py - About 3 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 make_src_pkg has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

    def make_src_pkg(dest_dir, spec, sources, env=None, saltenv='base', runas='root'):
        '''
        Create a platform specific source package from the given platform spec/control file and sources
    
        CLI Example:
    Severity: Minor
    Found in salt/modules/debuild_pkgbuild.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 make_src_pkg has 44 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    def make_src_pkg(dest_dir, spec, sources, env=None, saltenv='base', runas='root'):
        '''
        Create a platform specific source package from the given platform spec/control file and sources
    
        CLI Example:
    Severity: Minor
    Found in salt/modules/debuild_pkgbuild.py - About 1 hr to fix

      Function __virtual__ has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

      def __virtual__():
          '''
          Confirm this module is on a Debian-based system, and has required utilities
          '''
          if __grains__.get('os_family', False) in ('Kali', 'Debian'):
      Severity: Minor
      Found in salt/modules/debuild_pkgbuild.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

      Avoid deeply nested control flow statements.
      Open

                          if ((__grains__['os'] in ['Ubuntu'] and __grains__['osmajorrelease'] < 18)
                               or (__grains__['os'] in ['Debian'] and __grains__['osmajorrelease'] <= 8)):
                              cmd = 'debsign --re-sign -k {0} {1}'.format(keyid, abs_file)
                              try:
                                  proc = salt.utils.vt.Terminal(
      Severity: Major
      Found in salt/modules/debuild_pkgbuild.py - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                                if proc_exitstatus != 0:
                                    raise SaltInvocationError(
                                         'Reprepro includedsc for codename {0} and file {1} failed with proc.status {2}'.format(
                                            codename,
                                            abs_file,
        Severity: Major
        Found in salt/modules/debuild_pkgbuild.py - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                                  while proc.has_unread_data:
                                      stdout, _ = proc.recv()
                                      if stdout and REPREPRO_SIGN_PROMPT_RE.search(stdout):
                                          # have the prompt for inputting the passphrase
                                          proc.sendline(phrase)
          Severity: Major
          Found in salt/modules/debuild_pkgbuild.py - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                    if local_key_fingerprint == line_fingerprint:
                                        lkeygrip = next(local_keys2).split('=')
                                        local_keygrip_to_use = lkeygrip[1].lstrip().rstrip()
                                        break
                        except StopIteration:
            Severity: Major
            Found in salt/modules/debuild_pkgbuild.py - About 45 mins to fix

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

                                          while proc.has_unread_data:
                                              stdout, _ = proc.recv()
                                              if stdout and SIGN_PROMPT_RE.search(stdout):
                                                  # have the prompt for inputting the passphrase
                                                  proc.sendline(phrase)
              Severity: Major
              Found in salt/modules/debuild_pkgbuild.py and 1 other location - About 4 hrs to fix
              salt/modules/rpmbuild_pkgbuild.py on lines 567..580

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 93.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Identical blocks of code found in 2 locations. Consider refactoring.
              Open

                                  if ((__grains__['os'] in ['Ubuntu'] and __grains__['osmajorrelease'] < 18)
                                       or (__grains__['os'] in ['Debian'] and __grains__['osmajorrelease'] <= 8)):
              Severity: Major
              Found in salt/modules/debuild_pkgbuild.py and 1 other location - About 3 hrs to fix
              salt/modules/debuild_pkgbuild.py on lines 888..889

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 68.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Identical blocks of code found in 2 locations. Consider refactoring.
              Open

                              if ((__grains__['os'] in ['Ubuntu'] and __grains__['osmajorrelease'] < 18)
                                  or (__grains__['os'] in ['Debian'] and __grains__['osmajorrelease'] <= 8)):
              Severity: Major
              Found in salt/modules/debuild_pkgbuild.py and 1 other location - About 3 hrs to fix
              salt/modules/debuild_pkgbuild.py on lines 835..836

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 68.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Identical blocks of code found in 2 locations. Consider refactoring.
              Open

                      try:
                          __salt__['gpg.import_key'](user=runas, filename=pkg_pub_key_file, gnupghome=gnupghome)
                          __salt__['gpg.import_key'](user=runas, filename=pkg_priv_key_file, gnupghome=gnupghome)
              
                      except SaltInvocationError:
              Severity: Major
              Found in salt/modules/debuild_pkgbuild.py and 1 other location - About 3 hrs to fix
              salt/modules/rpmbuild_pkgbuild.py on lines 502..508

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 62.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

                      for efile in os.listdir(tree_base):
                          full = os.path.join(tree_base, efile)
                          trgt = os.path.join(dest_dir, efile)
                          shutil.copy(full, trgt)
                          ret.append(trgt)
              Severity: Major
              Found in salt/modules/debuild_pkgbuild.py and 1 other location - About 2 hrs to fix
              salt/modules/rpmbuild_pkgbuild.py on lines 252..256

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 59.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

                          for gpg_info_line in gpg_raw_info:
                              gpg_info_line = salt.utils.stringutils.to_unicode(gpg_info_line)
                              gpg_info = gpg_info_line.split('=')
                              env[gpg_info[0]] = gpg_info[1]
                              break
              Severity: Major
              Found in salt/modules/debuild_pkgbuild.py and 1 other location - About 1 hr to fix
              salt/modules/debuild_pkgbuild.py on lines 798..802

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 56.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

                          for gpg_tty_info_line in gpg_raw_info:
                              gpg_tty_info_line = salt.utils.stringutils.to_unicode(gpg_tty_info_line)
                              gpg_tty_info = gpg_tty_info_line.split('=')
                              env[gpg_tty_info[0]] = gpg_tty_info[1]
                              break
              Severity: Major
              Found in salt/modules/debuild_pkgbuild.py and 1 other location - About 1 hr to fix
              salt/modules/debuild_pkgbuild.py on lines 789..793

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 56.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Identical blocks of code found in 2 locations. Consider refactoring.
              Open

                                  try:
                                      proc = salt.utils.vt.Terminal(
                                              cmd,
                                              env=env,
                                              shell=True,
              Severity: Major
              Found in salt/modules/debuild_pkgbuild.py and 1 other location - About 1 hr to fix
              salt/modules/debuild_pkgbuild.py on lines 838..875

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 45.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Identical blocks of code found in 2 locations. Consider refactoring.
              Open

                                      try:
                                          proc = salt.utils.vt.Terminal(
                                              cmd,
                                              env=env,
                                              shell=True,
              Severity: Major
              Found in salt/modules/debuild_pkgbuild.py and 1 other location - About 1 hr to fix
              salt/modules/debuild_pkgbuild.py on lines 890..928

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 45.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 3 locations. Consider refactoring.
              Open

                      with salt.utils.files.fopen(repoconfdist, 'a') as fow:
                          fow.write(salt.utils.stringutils.to_str('SignWith: {0}\n'.format(keyid)))
              Severity: Major
              Found in salt/modules/debuild_pkgbuild.py and 2 other locations - About 40 mins to fix
              salt/modules/file.py on lines 3405..3406
              salt/modules/xbpspkg.py on lines 597..601

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 42.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              There are no issues that match your filters.

              Category
              Status