rgs1/zk_shell

View on GitHub
zk_shell/xclient.py

Summary

Maintainability
F
3 days
Test Coverage

File xclient.py has 418 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""
a decorated KazooClient with handy operations on a ZK datatree and its znodes
"""
from contextlib import contextmanager
import os
Severity: Minor
Found in zk_shell/xclient.py - About 6 hrs to fix

    XClient has 41 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class XClient():
        """ adds some extra methods to a wrapped KazooClient """
    
        class CmdFailed(Exception):
            """ 4 letter cmd failed """
    Severity: Minor
    Found in zk_shell/xclient.py - About 5 hrs to fix

      Function ephemerals_info has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

          def ephemerals_info(self, hosts):
              """Returns ClientInfo per path.
      
              :param hosts: comma separated lists of members of the ZK ensemble.
              :returns: A dictionary of (path, ClientInfo).
      Severity: Minor
      Found in zk_shell/xclient.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 do_grep has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          def do_grep(self, path, match):
              """ grep's work horse """
              try:
                  children = self.get_children(path)
              except (NoNodeError, NoAuthError):
      Severity: Minor
      Found in zk_shell/xclient.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 do_tree has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          def do_tree(self, path, max_depth, level, full_path, include_stat):
              """ tree's work horse """
              try:
                  children = self.get_children(path)
              except (NoNodeError, NoAuthError):
      Severity: Minor
      Found in zk_shell/xclient.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 _cmd has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          def _cmd(self, endpoint, cmd):
              """ endpoint is (host, port) """
              cmdbuf = "%s\n" % (cmd)
              # some cmds have large outputs and ZK closes the connection as soon as it
              # finishes writing. so read in huge chunks.
      Severity: Minor
      Found in zk_shell/xclient.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 diff has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          def diff(self, path_a, path_b):
              """ Performs a deep comparison of path_a/ and path_b/
      
                  For each child, it yields (rv, child) where rv:
                   -1 if doesn't exist in path_b (destination)
      Severity: Minor
      Found in zk_shell/xclient.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 create_async has 7 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def create_async(self, path, value=b"", acl=None, ephemeral=False, sequence=False, makepath=False):
      Severity: Major
      Found in zk_shell/xclient.py - About 50 mins to fix

        Function create has 7 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def create(self, path, value=b"", acl=None, ephemeral=False, sequence=False, makepath=False):
        Severity: Major
        Found in zk_shell/xclient.py - About 50 mins to fix

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

              def do_tree(self, path, max_depth, level, full_path, include_stat):
          Severity: Minor
          Found in zk_shell/xclient.py - About 45 mins to fix

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

                def __init__(self, sid=None, ip=None, port=None, server_ip=None, server_port=None):
            Severity: Minor
            Found in zk_shell/xclient.py - About 35 mins to fix

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

                  def create(self, path, value=b"", acl=None, ephemeral=False,
              Severity: Minor
              Found in zk_shell/xclient.py - About 35 mins to fix

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

                    def tree(self, path, max_depth, full_path=False, include_stat=False):
                Severity: Minor
                Found in zk_shell/xclient.py - About 35 mins to fix

                  Function get_acls_recursive has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                      def get_acls_recursive(self, path, depth, include_ephemerals):
                          """A recursive generator wrapper for get_acls
                  
                          :param path: path from which to start
                          :param depth: depth of the recursion (-1 no recursion, 0 means no limit)
                  Severity: Minor
                  Found in zk_shell/xclient.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 sessions_info has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                      def sessions_info(self, hosts):
                          """Returns ClientInfo per session.
                  
                          :param hosts: comma separated lists of members of the ZK ensemble.
                          :returns: A dictionary of (session_id, ClientInfo).
                  Severity: Minor
                  Found in zk_shell/xclient.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 cmd has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                      def cmd(self, endpoints, cmd):
                          """endpoints is [(host1, port1), (host2, port), ...]"""
                          replies = []
                          for ep in endpoints:
                              try:
                  Severity: Minor
                  Found in zk_shell/xclient.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

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

                      def create_async(self, path, value=b"", acl=None, ephemeral=False, sequence=False, makepath=False):
                          """ wraps the default create() and handles encoding (Py3k) """
                          value = to_bytes(value)
                          return self._zk.create_async(path, value, acl, ephemeral, sequence, makepath)
                  Severity: Major
                  Found in zk_shell/xclient.py and 1 other location - About 1 hr to fix
                  zk_shell/xclient.py on lines 171..174

                  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 46.

                  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

                      def create(self, path, value=b"", acl=None, ephemeral=False, sequence=False, makepath=False):
                          """ wraps the default create() and handles encoding (Py3k) """
                          value = to_bytes(value)
                          return self._zk.create(path, value, acl, ephemeral, sequence, makepath)
                  Severity: Major
                  Found in zk_shell/xclient.py and 1 other location - About 1 hr to fix
                  zk_shell/xclient.py on lines 176..179

                  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 46.

                  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

                      @property
                      def client(self):
                          """ the (hostaddr, port) of the local endpoint (or "") """
                          conn = self._connection
                          return conn._socket.getsockname() if conn else ""
                  Severity: Minor
                  Found in zk_shell/xclient.py and 1 other location - About 35 mins to fix
                  zk_shell/xclient.py on lines 117..121

                  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 33.

                  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

                          try:
                              match = re.compile(match, flags)
                          except sre_constants.error as ex:
                              print("Bad regexp: %s" % (ex))
                              return
                  Severity: Minor
                  Found in zk_shell/xclient.py and 1 other location - About 35 mins to fix
                  zk_shell/xclient.py on lines 227..231

                  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 33.

                  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

                          try:
                              match = re.compile(content, flags)
                          except sre_constants.error as ex:
                              print("Bad regexp: %s" % (ex))
                              return
                  Severity: Minor
                  Found in zk_shell/xclient.py and 1 other location - About 35 mins to fix
                  zk_shell/xclient.py on lines 214..218

                  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 33.

                  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

                      @property
                      def server(self):
                          """ the (hostaddr, port) of the connected ZK server (or "") """
                          conn = self._connection
                          return conn._socket.getpeername() if conn else ""
                  Severity: Minor
                  Found in zk_shell/xclient.py and 1 other location - About 35 mins to fix
                  zk_shell/xclient.py on lines 123..127

                  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 33.

                  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