edgewall/trac

View on GitHub
trac/db/postgres_backend.py

Summary

Maintainability
D
2 days
Test Coverage

File postgres_backend.py has 353 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
#
# Copyright (C) 2005-2023 Edgewall Software
# Copyright (C) 2005 Christopher Lenz <cmlenz@gmx.de>
# All rights reserved.
Severity: Minor
Found in trac/db/postgres_backend.py - About 4 hrs to fix

    PostgreSQLConnection has 21 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class PostgreSQLConnection(ConnectionBase, ConnectionWrapper):
        """Connection wrapper for PostgreSQL."""
    
        poolable = True
    
    
    Severity: Minor
    Found in trac/db/postgres_backend.py - About 2 hrs to fix

      Function init_db has 8 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def init_db(self, path, schema=None, log=None, user=None, password=None,
      Severity: Major
      Found in trac/db/postgres_backend.py - About 1 hr to fix

        Function to_sql has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def to_sql(self, table):
                sql = ['CREATE TABLE %s (' % _quote(table.name)]
                coldefs = []
                for column in table.columns:
                    ctype = column.type
        Severity: Minor
        Found in trac/db/postgres_backend.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 db_exists has 7 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def db_exists(self, path, log=None, user=None, password=None, host=None,
        Severity: Major
        Found in trac/db/postgres_backend.py - About 50 mins to fix

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

              def get_connection(self, path, log=None, user=None, password=None,
          Severity: Major
          Found in trac/db/postgres_backend.py - About 50 mins to fix

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

                def __init__(self, path, log=None, user=None, password=None, host=None,
            Severity: Major
            Found in trac/db/postgres_backend.py - About 50 mins to fix

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

                  def destroy_db(self, path, log=None, user=None, password=None, host=None,
              Severity: Major
              Found in trac/db/postgres_backend.py - About 50 mins to fix

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

                    def backup(self, dest_file):
                        db_url = self.env.config.get('trac', 'database')
                        scheme, db_prop = parse_connection_uri(db_url)
                        db_params = db_prop.setdefault('params', {})
                        db_params.setdefault('schema', 'public')
                Severity: Minor
                Found in trac/db/postgres_backend.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 assemble_pg_dsn has 5 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                def assemble_pg_dsn(path, user=None, password=None, host=None, port=None):
                Severity: Minor
                Found in trac/db/postgres_backend.py - About 35 mins to fix

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

                          for name, (from_, to) in sorted(columns.items()):
                              to = _type_map.get(to, to)
                              if to != _type_map.get(from_, from_):
                                  alterations.append((name, to))
                  Severity: Major
                  Found in trac/db/postgres_backend.py and 1 other location - About 2 hrs to fix
                  trac/db/mysql_backend.py on lines 230..233

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

                  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:
                              p = Popen(args, env=environ, stderr=PIPE, close_fds=close_fds)
                          except OSError as e:
                              raise TracError(_("Unable to run %(path)s: %(msg)s",
                                                path=self.pg_dump_path,
                  Severity: Major
                  Found in trac/db/postgres_backend.py and 1 other location - About 2 hrs to fix
                  trac/db/mysql_backend.py on lines 269..274

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

                  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 len(table.key) == 1 and column.name in table.key:
                                  ctype += ' PRIMARY KEY'
                  Severity: Major
                  Found in trac/db/postgres_backend.py and 1 other location - About 1 hr to fix
                  trac/db/sqlite_backend.py on lines 130..133

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

                  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

                          if p.returncode != 0:
                              raise TracError(_("pg_dump failed: %(msg)s",
                                                msg=to_unicode(errmsg.strip())))
                  Severity: Minor
                  Found in trac/db/postgres_backend.py and 1 other location - About 45 mins to fix
                  trac/db/mysql_backend.py on lines 276..278

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

                  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 get_table_names(self):
                          rows = self.execute("""
                              SELECT table_name FROM information_schema.tables
                              WHERE table_schema=current_schema()""")
                          return [row[0] for row in rows]
                  Severity: Minor
                  Found in trac/db/postgres_backend.py and 1 other location - About 40 mins to fix
                  trac/db/sqlite_backend.py on lines 400..404

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

                  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