borgbackup/borg

View on GitHub
src/borg/archiver/__init__.py

Summary

Maintainability
F
3 days
Test Coverage

File __init__.py has 563 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# borg cli interface / toplevel archiver code

import sys
import traceback

Severity: Major
Found in src/borg/archiver/__init__.py - About 1 day to fix

    Function main has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
    Open

    def main():  # pragma: no cover
        # Make sure stdout and stderr have errors='replace' to avoid unicode
        # issues when print()-ing unicode file names
        sys.stdout = ErrorIgnoringTextIOWrapper(sys.stdout.buffer, sys.stdout.encoding, "replace", line_buffering=True)
        sys.stderr = ErrorIgnoringTextIOWrapper(sys.stderr.buffer, sys.stderr.encoding, "replace", line_buffering=True)
    Severity: Minor
    Found in src/borg/archiver/__init__.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 parse_args has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

        def parse_args(self, args=None):
            # We can't use argparse for "serve" since we don't want it to show up in "Available commands"
            if args:
                args = self.preprocess_args(args)
            parser = self.build_parser()
    Severity: Minor
    Found in src/borg/archiver/__init__.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 resolve has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

            def resolve(self, args: argparse.Namespace):  # Namespace has "in" but otherwise is not like a dict.
                """
                Resolve the multiple definitions of each common option to the final value.
                """
                for suffix in self.suffix_precedence:
    Severity: Minor
    Found in src/borg/archiver/__init__.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 build_parser has 42 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def build_parser(self):
            from ._common import define_common_options
    
            parser = argparse.ArgumentParser(prog=self.prog, description="Borg - Deduplicated Backups", add_help=False)
            # paths and patterns must have an empty list as default everywhere
    Severity: Minor
    Found in src/borg/archiver/__init__.py - About 1 hr to fix

      Function add_common_group has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

              def add_common_group(self, parser, suffix, provide_defaults=False):
                  """
                  Add common options to *parser*.
      
                  *provide_defaults* must only be True exactly once in a parser hierarchy,
      Severity: Minor
      Found in src/borg/archiver/__init__.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 get_args has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_args(self, argv, cmd):
              """usually, just returns argv, except if we deal with a ssh forced command for borg serve."""
              result = self.parse_args(argv[1:])
              if cmd is not None and result.func == self.do_serve:
                  # borg serve case:
      Severity: Minor
      Found in src/borg/archiver/__init__.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 sig_info_handler has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

      def sig_info_handler(sig_no, stack):  # pragma: no cover
          """search the stack for infos about the currently processed file and print them"""
          with signal_handler(sig_no, signal.SIG_IGN):
              for frame in inspect.getouterframes(stack):
                  func, loc = frame[3], frame[0].f_locals
      Severity: Minor
      Found in src/borg/archiver/__init__.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 preprocess_args has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def preprocess_args(self, args):
              deprecations = [
                  # ('--old', '--new' or None, 'Warning: "--old" has been deprecated. Use "--new" instead.'),
              ]
              for i, arg in enumerate(args[:]):
      Severity: Minor
      Found in src/borg/archiver/__init__.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 run has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          def run(self, args):
              os.umask(args.umask)  # early, before opening files
              self.lock_wait = args.lock_wait
              func = get_func(args)
              # do not use loggers before this!
      Severity: Minor
      Found in src/borg/archiver/__init__.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 print_warning has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def print_warning(self, msg, *args, **kw):
              warning_code = kw.get("wc", EXIT_WARNING)  # note: wc=None can be used to not influence exit code
              warning_type = kw.get("wt", "percent")
              assert warning_type in ("percent", "curly")
              warning_msgid = kw.get("msgid")
      Severity: Minor
      Found in src/borg/archiver/__init__.py - About 45 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 maybe_checkpoint has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def maybe_checkpoint(self, *, checkpoint_func, checkpoint_interval):
              checkpointed = False
              sig_int_triggered = sig_int and sig_int.action_triggered()
              if sig_int_triggered or checkpoint_interval and time.monotonic() - self.last_checkpoint > checkpoint_interval:
                  if sig_int_triggered:
      Severity: Minor
      Found in src/borg/archiver/__init__.py - About 45 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 print_file_status has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def print_file_status(self, status, path):
              # if we get called with status == None, the final file status was already printed
              if self.output_list and status is not None and (self.output_filter is None or status in self.output_filter):
                  if self.log_json:
                      json_data = {"type": "file_status", "status": status}
      Severity: Minor
      Found in src/borg/archiver/__init__.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