alot/db/manager.py

Summary

Maintainability
F
3 days
Test Coverage

Function flush has a Cognitive Complexity of 94 (exceeds 5 allowed). Consider refactoring.
Open

    def flush(self):
        """
        write out all queued write-commands in order, each one in a separate
        :meth:`atomic <notmuch2.Database.atomic>` transaction.

Severity: Minor
Found in alot/db/manager.py - About 1 day 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 manager.py has 342 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# Copyright (C) 2011-2012  Patrick Totzke <patricktotzke@gmail.com>
# Copyright © Dylan Baker
# This file is released under the GNU GPL, version 3 or a later revision.
# For further details see the COPYING file
from collections import deque
Severity: Minor
Found in alot/db/manager.py - About 4 hrs to fix

    Avoid deeply nested control flow statements.
    Open

                                for msg in db.messages(querystring):
                                    with msg.frozen():
                                        if cmd == 'toggle':
                                            for tag in to_remove:
                                                msg.tags.discard(tag)
    Severity: Major
    Found in alot/db/manager.py - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                                  if cmd == 'toggle':
                                      presenttags = self.collect_tags(querystring)
                                      to_remove = []
                                      to_add = []
                                      for tag in tags:
      Severity: Major
      Found in alot/db/manager.py - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                                    with msg.frozen():
                                        logging.debug('freeze')
                                        for tag in tags:
                                            msg.tags.add(tag)
                                        if sync:
        Severity: Major
        Found in alot/db/manager.py - About 45 mins to fix

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

              def count_messages(self, querystring):
                  """returns number of messages that match `querystring`"""
                  db = Database(path=self.path, mode=Database.MODE.READ_ONLY)
                  return db.count_messages(querystring,
                                           exclude_tags=self.exclude_tags)
          Severity: Major
          Found in alot/db/manager.py and 1 other location - About 1 hr to fix
          alot/db/manager.py on lines 266..270

          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 2 locations. Consider refactoring.
          Open

              def count_threads(self, querystring):
                  """returns number of threads that match `querystring`"""
                  db = Database(path=self.path, mode=Database.MODE.READ_ONLY)
                  return db.count_threads(querystring,
                                          exclude_tags=self.exclude_tags)
          Severity: Major
          Found in alot/db/manager.py and 1 other location - About 1 hr to fix
          alot/db/manager.py on lines 250..254

          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 2 locations. Consider refactoring.
          Open

              def toggle_tags(self, querystring, tags, afterwards=None):
                  """
                  toggles tags from messages that match `querystring`.
                  This appends a toggle operation to the write queue and raises
                  :exc:`~errors.DatabaseROError` if in read only mode.
          Severity: Major
          Found in alot/db/manager.py and 1 other location - About 1 hr to fix
          alot/db/manager.py on lines 204..225

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

          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 untag(self, querystring, tags, afterwards=None):
                  """
                  removes tags from messages that match `querystring`.
                  This appends an untag operation to the write queue and raises
                  :exc:`~errors.DatabaseROError` if in read only mode.
          Severity: Major
          Found in alot/db/manager.py and 1 other location - About 1 hr to fix
          alot/db/manager.py on lines 227..248

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

          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

          Continuation line over-indented for hanging indent
          Open

                                      exclude_tags=self.exclude_tags)]
          Severity: Minor
          Found in alot/db/manager.py by pep8

          Continuation lines indentation.

          Continuation lines should align wrapped elements either vertically
          using Python's implicit line joining inside parentheses, brackets
          and braces, or using a hanging indent.
          
          When using a hanging indent these considerations should be applied:
          - there should be no arguments on the first line, and
          - further indentation should be used to clearly distinguish itself
            as a continuation line.
          
          Okay: a = (\n)
          E123: a = (\n    )
          
          Okay: a = (\n    42)
          E121: a = (\n   42)
          E122: a = (\n42)
          E123: a = (\n    42\n    )
          E124: a = (24,\n     42\n)
          E125: if (\n    b):\n    pass
          E126: a = (\n        42)
          E127: a = (24,\n      42)
          E128: a = (24,\n    42)
          E129: if (a or\n    b):\n    pass
          E131: a = (\n    42\n 24)

          Continuation line under-indented for visual indent
          Open

                                      sort=self._sort_orders[sort],
          Severity: Minor
          Found in alot/db/manager.py by pep8

          Continuation lines indentation.

          Continuation lines should align wrapped elements either vertically
          using Python's implicit line joining inside parentheses, brackets
          and braces, or using a hanging indent.
          
          When using a hanging indent these considerations should be applied:
          - there should be no arguments on the first line, and
          - further indentation should be used to clearly distinguish itself
            as a continuation line.
          
          Okay: a = (\n)
          E123: a = (\n    )
          
          Okay: a = (\n    42)
          E121: a = (\n   42)
          E122: a = (\n42)
          E123: a = (\n    42\n    )
          E124: a = (24,\n     42\n)
          E125: if (\n    b):\n    pass
          E126: a = (\n        42)
          E127: a = (24,\n      42)
          E128: a = (24,\n    42)
          E129: if (a or\n    b):\n    pass
          E131: a = (\n    42\n 24)

          Do not use bare 'except'
          Open

                      except:
          Severity: Minor
          Found in alot/db/manager.py by pep8

          When catching exceptions, mention specific exceptions when possible.

          Okay: except Exception:
          Okay: except BaseException:
          E722: except:

          There are no issues that match your filters.

          Category
          Status