attic/repository.py

Summary

Maintainability
F
3 days
Test Coverage

File repository.py has 518 lines of code (exceeds 250 allowed). Consider refactoring.
Open

from configparser import RawConfigParser
from binascii import hexlify
from itertools import islice
import errno
import os
Severity: Major
Found in attic/repository.py - About 1 day to fix

    Function check has a Cognitive Complexity of 42 (exceeds 5 allowed). Consider refactoring.
    Open

        def check(self, repair=False):
            """Check repository consistency
    
            This method verifies all segment checksums and makes sure
            the index is consistent with the data stored in the segments.
    Severity: Minor
    Found in attic/repository.py - About 6 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 replay_segments has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

        def replay_segments(self, index_transaction_id, segments_transaction_id):
            self.prepare_txn(index_transaction_id, do_cleanup=False)
            for segment, filename in self.io.segment_iterator():
                if index_transaction_id is not None and segment <= index_transaction_id:
                    continue
    Severity: Minor
    Found in attic/repository.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 compact_segments has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

        def compact_segments(self):
            """Compact sparse segments by copying data into new segments
            """
            if not self.compact:
                return
    Severity: Minor
    Found in attic/repository.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

    Repository has 22 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Repository(object):
        """Filesystem based transactional key value store
    
        On disk layout:
        dir/README
    Severity: Minor
    Found in attic/repository.py - About 2 hrs to fix

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

          def iter_objects(self, segment, include_data=False):
              fd = self.get_fd(segment)
              fd.seek(0)
              if fd.read(8) != MAGIC:
                  raise IntegrityError('Invalid segment header')
      Severity: Minor
      Found in attic/repository.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 index_transaction_id is None or segment > index_transaction_id:
                                  self.io.write_delete(key)
                      assert segments[segment] == 0
      Severity: Major
      Found in attic/repository.py - About 45 mins to fix

        Function get_write_fd has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def get_write_fd(self, no_new=False):
                if not no_new and self.offset and self.offset > self.limit:
                    self.close_segment()
                if not self._write_fd:
                    if self.segment % self.segments_per_dir == 0:
        Severity: Minor
        Found in attic/repository.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 prepare_txn has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def prepare_txn(self, transaction_id, do_cleanup=True):
                self._active_txn = True
                self.lock.upgrade()
                if not self.index:
                    self.index = self.open_index(transaction_id)
        Severity: Minor
        Found in attic/repository.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 read has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def read(self, segment, offset, id):
                if segment == self.segment and self._write_fd:
                    self._write_fd.flush()
                fd = self.get_fd(segment)
                fd.seek(offset)
        Severity: Minor
        Found in attic/repository.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 recover_segment has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def recover_segment(self, segment, filename):
                self.fds.pop(segment).close()
                # FIXME: save a copy of the original file
                with open(filename, 'rb') as fd:
                    data = memoryview(fd.read())
        Severity: Minor
        Found in attic/repository.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 write_index has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def write_index(self):
                hints = {b'version': 1,
                         b'segments': self.segments,
                         b'compact': list(self.compact)}
                transaction_id = self.io.get_segments_transaction_id()
        Severity: Minor
        Found in attic/repository.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