gamunu/cassandra_snap

View on GitHub
cassandra_snap/agent.py

Summary

Maintainability
D
2 days
Test Coverage

Function upload_file has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
Open

def upload_file(bucket, source, destination, s3_ssenc, bufsize, reduced_redundancy, rate_limit, quiet):
    mp = None
    retry_count = 0
    sleep_time = SLEEP_TIME
    while True:
Severity: Minor
Found in cassandra_snap/agent.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 create_upload_manifest has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
Open

def create_upload_manifest(
        snapshot_name, snapshot_keyspaces, snapshot_table,
        conf_path, manifest_path, exclude_tables, incremental_backups=False):
    if snapshot_keyspaces:
        keyspace_globs = snapshot_keyspaces.split(',')
Severity: Minor
Found in cassandra_snap/agent.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

File agent.py has 277 lines of code (exceeds 250 allowed). Consider refactoring.
Open

from __future__ import (absolute_import, print_function)

import boto
from boto.s3.connection import S3Connection
from yaml import load
Severity: Minor
Found in cassandra_snap/agent.py - About 2 hrs to fix

    Function put_from_manifest has 13 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def put_from_manifest(
    Severity: Major
    Found in cassandra_snap/agent.py - About 1 hr to fix

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

      def upload_file(bucket, source, destination, s3_ssenc, bufsize, reduced_redundancy, rate_limit, quiet):
      Severity: Major
      Found in cassandra_snap/agent.py - About 1 hr to fix

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

        def create_upload_manifest(
        Severity: Major
        Found in cassandra_snap/agent.py - About 50 mins to fix

          Avoid deeply nested control flow statements.
          Open

                              if f.split('/')[-4] not in exclude_tables_list:
                                  files.append(f.strip())
                      else:
          Severity: Major
          Found in cassandra_snap/agent.py - About 45 mins to fix

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

            def cancel_upload(bucket, mp, remote_path):
                """
                Safe way to cancel a multipart upload
                sleeps SLEEP_TIME seconds and then makes sure that there are not parts left
                in storage
            Severity: Minor
            Found in cassandra_snap/agent.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

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

                        try:
                            for i, chunk in enumerate(compressed_pipe(source, bufsize, rate_limit, quiet)):
                                mp.upload_part_from_file(
                                    chunk, i + 1, cb=s3_progress_update_callback)
                        except Exception as exc:
            Severity: Minor
            Found in cassandra_snap/agent.py and 1 other location - About 40 mins to fix
            cassandra_snap/agent.py on lines 72..81

            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

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

                            try:
                                mp = bucket.initiate_multipart_upload(
                                    destination, encrypt_key=s3_ssenc, reduced_redundancy=reduced_redundancy)
                                logger.info("Initialized multipart upload for file {!s} to {!s}".format(
                                    source, destination))
            Severity: Minor
            Found in cassandra_snap/agent.py and 1 other location - About 40 mins to fix
            cassandra_snap/agent.py on lines 83..91

            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

            Line too long (132 > 79 characters)
            Open

                                   ((bucket, f, destination_path(s3_base_path, f), s3_ssenc, buffer_size, reduced_redundancy, rate_limit, quiet)
            Severity: Minor
            Found in cassandra_snap/agent.py by pep8

            Limit all lines to a maximum of 79 characters.

            There are still many devices around that are limited to 80 character
            lines; plus, limiting windows to 80 characters makes it possible to
            have several windows side-by-side.  The default wrapping on such
            devices looks ugly.  Therefore, please limit all lines to a maximum
            of 79 characters. For flowing long blocks of text (docstrings or
            comments), limiting the length to 72 characters is recommended.
            
            Reports error E501.

            Line too long (80 > 79 characters)
            Open

                            # The multi-part object may be in a bad state.  Extract an error
            Severity: Minor
            Found in cassandra_snap/agent.py by pep8

            Limit all lines to a maximum of 79 characters.

            There are still many devices around that are limited to 80 character
            lines; plus, limiting windows to 80 characters makes it possible to
            have several windows side-by-side.  The default wrapping on such
            devices looks ugly.  Therefore, please limit all lines to a maximum
            of 79 characters. For flowing long blocks of text (docstrings or
            comments), limiting the length to 72 characters is recommended.
            
            Reports error E501.

            Line too long (97 > 79 characters)
            Open

                                    destination, encrypt_key=s3_ssenc, reduced_redundancy=reduced_redundancy)
            Severity: Minor
            Found in cassandra_snap/agent.py by pep8

            Limit all lines to a maximum of 79 characters.

            There are still many devices around that are limited to 80 character
            lines; plus, limiting windows to 80 characters makes it possible to
            have several windows side-by-side.  The default wrapping on such
            devices looks ugly.  Therefore, please limit all lines to a maximum
            of 79 characters. For flowing long blocks of text (docstrings or
            comments), limiting the length to 72 characters is recommended.
            
            Reports error E501.

            Line too long (92 > 79 characters)
            Open

                                logger.info("Initialized multipart upload for file {!s} to {!s}".format(
            Severity: Minor
            Found in cassandra_snap/agent.py by pep8

            Limit all lines to a maximum of 79 characters.

            There are still many devices around that are limited to 80 character
            lines; plus, limiting windows to 80 characters makes it possible to
            have several windows side-by-side.  The default wrapping on such
            devices looks ugly.  Therefore, please limit all lines to a maximum
            of 79 characters. For flowing long blocks of text (docstrings or
            comments), limiting the length to 72 characters is recommended.
            
            Reports error E501.

            Line too long (95 > 79 characters)
            Open

                            for i, chunk in enumerate(compressed_pipe(source, bufsize, rate_limit, quiet)):
            Severity: Minor
            Found in cassandra_snap/agent.py by pep8

            Limit all lines to a maximum of 79 characters.

            There are still many devices around that are limited to 80 character
            lines; plus, limiting windows to 80 characters makes it possible to
            have several windows side-by-side.  The default wrapping on such
            devices looks ugly.  Therefore, please limit all lines to a maximum
            of 79 characters. For flowing long blocks of text (docstrings or
            comments), limiting the length to 72 characters is recommended.
            
            Reports error E501.

            Line too long (98 > 79 characters)
            Open

                    help="Limit the upload speed to S3 (by using 'pv'). Value expressed in kilobytes (*1024)")
            Severity: Minor
            Found in cassandra_snap/agent.py by pep8

            Limit all lines to a maximum of 79 characters.

            There are still many devices around that are limited to 80 character
            lines; plus, limiting windows to 80 characters makes it possible to
            have several windows side-by-side.  The default wrapping on such
            devices looks ugly.  Therefore, please limit all lines to a maximum
            of 79 characters. For flowing long blocks of text (docstrings or
            comments), limiting the length to 72 characters is recommended.
            
            Reports error E501.

            Line too long (103 > 79 characters)
            Open

            def upload_file(bucket, source, destination, s3_ssenc, bufsize, reduced_redundancy, rate_limit, quiet):
            Severity: Minor
            Found in cassandra_snap/agent.py by pep8

            Limit all lines to a maximum of 79 characters.

            There are still many devices around that are limited to 80 character
            lines; plus, limiting windows to 80 characters makes it possible to
            have several windows side-by-side.  The default wrapping on such
            devices looks ugly.  Therefore, please limit all lines to a maximum
            of 79 characters. For flowing long blocks of text (docstrings or
            comments), limiting the length to 72 characters is recommended.
            
            Reports error E501.

            Line too long (106 > 79 characters)
            Open

                                logger.error("Error while initializing multipart upload for file {!s} to {!s}".format(
            Severity: Minor
            Found in cassandra_snap/agent.py by pep8

            Limit all lines to a maximum of 79 characters.

            There are still many devices around that are limited to 80 character
            lines; plus, limiting windows to 80 characters makes it possible to
            have several windows side-by-side.  The default wrapping on such
            devices looks ugly.  Therefore, please limit all lines to a maximum
            of 79 characters. For flowing long blocks of text (docstrings or
            comments), limiting the length to 72 characters is recommended.
            
            Reports error E501.

            Line too long (80 > 79 characters)
            Open

                                "Retried too many times uploading file {!s}".format(source))
            Severity: Minor
            Found in cassandra_snap/agent.py by pep8

            Limit all lines to a maximum of 79 characters.

            There are still many devices around that are limited to 80 character
            lines; plus, limiting windows to 80 characters makes it possible to
            have several windows side-by-side.  The default wrapping on such
            devices looks ugly.  Therefore, please limit all lines to a maximum
            of 79 characters. For flowing long blocks of text (docstrings or
            comments), limiting the length to 72 characters is recommended.
            
            Reports error E501.

            Line too long (99 > 79 characters)
            Open

                            logger.error("Error completing multipart file upload for file {!s} to {!s}".format(
            Severity: Minor
            Found in cassandra_snap/agent.py by pep8

            Limit all lines to a maximum of 79 characters.

            There are still many devices around that are limited to 80 character
            lines; plus, limiting windows to 80 characters makes it possible to
            have several windows side-by-side.  The default wrapping on such
            devices looks ugly.  Therefore, please limit all lines to a maximum
            of 79 characters. For flowing long blocks of text (docstrings or
            comments), limiting the length to 72 characters is recommended.
            
            Reports error E501.

            There are no issues that match your filters.

            Category
            Status