houtianze/bypy

View on GitHub

Showing 218 of 218 total issues

Function limit_unit has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

def limit_unit(timestr, num = 2):
    ''' DocTests:
    >>> limit_unit('1m2s', 1) == '1m'
    True
    >>> limit_unit('1m2s') == '1m2s'
Severity: Minor
Found in bypy/printer_util.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

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

            if i < tries:
                # algo changed: delay more after each failure
                delay = const.RetryDelayInSec * i
                perr("Waiting {} seconds before retrying...".format(delay))
                time.sleep(delay)
Severity: Major
Found in bypy/bypy.py and 1 other location - About 2 hrs to fix
bypy/bypy.py on lines 887..892

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

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 getfilemtime(path):
    mtime = -1
    try:
        mtime = os.path.getmtime(path)
    except os.error as ex:
Severity: Major
Found in bypy/util.py and 1 other location - About 2 hrs to fix
bypy/util.py on lines 183..191

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

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 i < tries:
                    # algo changed: delay more after each failure
                    delay = const.RetryDelayInSec * i
                    perr("Waiting {} seconds before retrying...".format(delay))
                    time.sleep(delay)
Severity: Major
Found in bypy/bypy.py and 1 other location - About 2 hrs to fix
bypy/bypy.py on lines 2068..2073

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

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 getfilesize(path):
    size = -1
    try:
        size = os.path.getsize(path)
    except os.error as ex:
Severity: Major
Found in bypy/util.py and 1 other location - About 2 hrs to fix
bypy/util.py on lines 194..202

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

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

File util.py has 270 lines of code (exceeds 250 allowed). Consider refactoring.
Open

#!/usr/bin/env python
# encoding: utf-8
# PYTHON_ARGCOMPLETE_OK

# from __future__ imports must occur at the beginning of the file
Severity: Minor
Found in bypy/util.py - About 2 hrs to fix

    Function check_requirements has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

    def check_requirements():
        result = CheckResult.Pass
        if iswindows():
            bannerwarn("You are running Python on Windows, which doesn't support Unicode so well.\n"
                "Files with non-ASCII names may not be handled correctly.")
    Severity: Minor
    Found in bypy/chkreq.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 migratesettings has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

        def migratesettings():
            result = const.ENoError
    
            if os.path.exists(const.OldByPyCertsPath):
                removefile(const.OldByPyCertsPath)
    Severity: Minor
    Found in bypy/bypy.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 _walk_remote_dir has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

        def _walk_remote_dir(self, remotepath, remoterootpath, args = None, skip_remote_only_dirs = False, recursive = True):
            dirjs = []
            filejs = []
            listStart = 0
            # https://github.com/houtianze/bypy/issues/285
    Severity: Minor
    Found in bypy/bypy.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 _upload_file has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

        def _upload_file(self, localpath, remotepath, ondup = 'overwrite'):
            # TODO: this is a quick patch
            if not self._shallinclude(localpath, remotepath, True):
                # since we are not going to upload it, there is no error
                #return const.ENoError
    Severity: Minor
    Found in bypy/bypy.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 Select has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

        def Select(self, event):
            if event.widget == self.wOK:
                self.Bye(self.rpath[len(const.AppPcsPath):])
            elif event.widget == self.wList:
                selected = ''
    Severity: Minor
    Found in bypy/gui.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 CreateWidgets has 60 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def CreateWidgets(self):
            self.master.grid_columnconfigure(0, weight = 1)
            self.master.grid_rowconfigure(1, weight = 1)
            self.grid_columnconfigure(1, weight = 1)
            self.grid_rowconfigure(4, weight = 1)
    Severity: Major
    Found in bypy/gui.py - About 2 hrs to fix

      Function __init__ has 59 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def __init__(self,
              slice_size = const.DefaultSliceSize,
              dl_chunk_size = const.DefaultDlChunkSize,
              verify = True,
              retry = 5, timeout = const.DefaultTimeOutInSeconds,
      Severity: Major
      Found in bypy/bypy.py - About 2 hrs to fix

        Function getparser has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
        Open

        def getparser():
            #name = os.path.basename(sys.argv[0])
            version = "v%s" % const.__version__
            version_message = '%%(prog)s %s' % (version)
            desc = "{} - {}".format(version_message, const.__desc__)
        Severity: Minor
        Found in bypy/bypy.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 _auth has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
        Open

            def _auth(self):
                params = {
                    'client_id' : self._apikey,
                    'response_type' : 'code',
                    'redirect_uri' : 'oob',
        Severity: Minor
        Found in bypy/bypy.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 _verify_current_file has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
        Open

            def _verify_current_file(self, j, gotlmd5):
                # if we really don't want to verify
                if self._current_file == '/dev/null' and not self._verify:
                    return const.ENoError
        
        
        Severity: Minor
        Found in bypy/bypy.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 upload has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
        Open

            def upload(self, localpath = '', remotepath = '', ondup = "overwrite"):
                ''' Usage: upload [localpath] [remotepath] [ondup] - \
        upload a file or directory (recursively)
            localpath - local path, is the current directory '.' if not specified
            remotepath - remote path at Baidu Yun (after app root directory at Baidu Yun)
        Severity: Minor
        Found in bypy/bypy.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 _cdl_addmon has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

            def _cdl_addmon(self, source_url, rpath, timeout = 3600):
                pars = self._prepare_cdl_add(source_url, rpath, timeout)
                jc = [{}] # out param
                result = self._post(pcsurl + 'services/cloud_dl',
                    pars, self._cdl_addmon_act, jc)
        Severity: Minor
        Found in bypy/bypy.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 combine has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

            def combine(self, remotefile, localfile = '*', *args):
                ''' Usage: combine <remotefile> [localfile] [md5s] - \
        try to create a file at PCS by combining slices, having MD5s specified
          remotefile - remote file at Baidu Yun (after app root directory at Baidu Yun)
          localfile - local file to verify against, passing in a star '*' or '/dev/null' means no verification
        Severity: Minor
        Found in bypy/bypy.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 _request has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

            def _request(self, url, pars, act, method, actargs = None, retry = True, addtoken = True, dumpex = True, **kwargs):
                tries = 1
                if retry:
                    tries = self._retry
        
        
        Severity: Minor
        Found in bypy/bypy.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

        Severity
        Category
        Status
        Source
        Language