Passed
Push — master ( 9e6838...cf264a )
by Yang
27s
created

Python.orthanc.query   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 71
Duplicated Lines 77.46 %

Importance

Changes 0
Metric Value
wmc 6
eloc 42
dl 55
loc 71
rs 10
c 0
b 0
f 0

3 Functions

Rating   Name   Duplication   Size   Complexity  
A deleteOrthanc() 18 18 2
A postOrthanc() 19 19 2
A getOrthanc() 18 18 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
import requests
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
2
import logging
0 ignored issues
show
introduced by
standard import "import logging" should be placed before "import requests"
Loading history...
3
import os
0 ignored issues
show
introduced by
standard import "import os" should be placed before "import requests"
Loading history...
4
import sys
0 ignored issues
show
introduced by
standard import "import sys" should be placed before "import requests"
Loading history...
5
from dotenv import load_dotenv
6
7
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
8
logger = logging.getLogger('Orthanc Query:')
0 ignored issues
show
Coding Style Naming introduced by
The name logger does not conform to the constant naming conventions ((([A-Z_][A-Z0-9_]*)|(__.*__))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
9
10
11 View Code Duplication
def getOrthanc(endpoint):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
Coding Style Naming introduced by
The name getOrthanc does not conform to the function naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
12
    """
13
    Get from a Orthanc endpoint
14
    :param endpoint:
15
    :return: bool on if such PSCID (INSTITUTIONID + PROJECTID + SUBJECTID) exist already.
16
    """
17
    logger = logging.getLogger('Orthanc_get')
0 ignored issues
show
Comprehensibility Bug introduced by
logger is re-defining a name which is already available in the outer-scope (previously defined on line 8).

It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
18
    logger.info("Getting Orthanc endpoint: "+ endpoint + "at")
19
    load_dotenv()
20
    url = os.getenv("OrthancURL")
21
    updatedurl = url + endpoint
22
    logger.info(updatedurl)
23
24
    with requests.Session() as s:
0 ignored issues
show
Coding Style Naming introduced by
The name s does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
25
        r = s.get(updatedurl)
0 ignored issues
show
Coding Style Naming introduced by
The name r does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
26
        logger.info("Get Result:" + str(r.status_code) + r.reason)
27
28
        return r.status_code, r.json()
29
30 View Code Duplication
def postOrthanc(endpoint, data):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
Coding Style Naming introduced by
The name postOrthanc does not conform to the function naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
31
    """
32
    Get from a Orthanc endpoint
33
    :param endpoint:
34
    :return: bool on if such PSCID (INSTITUTIONID + PROJECTID + SUBJECTID) exist already.
35
    """
36
    logger = logging.getLogger('Orthanc_post')
0 ignored issues
show
Comprehensibility Bug introduced by
logger is re-defining a name which is already available in the outer-scope (previously defined on line 8).

It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
37
    logger.info("Post Orthanc endpoint: "+ endpoint + "at")
38
    load_dotenv()
39
    url = os.getenv("OrthancURL")
40
    updatedurl = url + endpoint
41
    logger.info(updatedurl)
42
43
    with requests.Session() as s:
0 ignored issues
show
Coding Style Naming introduced by
The name s does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
44
        r = s.post(updatedurl, files=data)
0 ignored issues
show
Coding Style Naming introduced by
The name r does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
45
46
        logger.info("Post Result:" + str(r.status_code) + r.reason)
47
48
        return r.status_code, r
49
50
51 View Code Duplication
def deleteOrthanc(endpoint):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
Coding Style Naming introduced by
The name deleteOrthanc does not conform to the function naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
52
    """
53
    Delete from a Orthanc endpoint
54
    :param endpoint:
55
    :return: bool on if such PSCID (INSTITUTIONID + PROJECTID + SUBJECTID) exist already.
56
    """
57
    logger = logging.getLogger('Orthanc_delete')
0 ignored issues
show
Comprehensibility Bug introduced by
logger is re-defining a name which is already available in the outer-scope (previously defined on line 8).

It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
58
    logger.info("Deleting Orthanc endpoint: "+ endpoint + "at")
59
    load_dotenv()
60
    url = os.getenv("OrthancURL")
61
    updatedurl = url + endpoint
62
    logger.info(updatedurl)
63
64
    with requests.Session() as s:
0 ignored issues
show
Coding Style Naming introduced by
The name s does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
65
        r = s.delete(updatedurl)
0 ignored issues
show
Coding Style Naming introduced by
The name r does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
66
        logger.info("Deletion Result:" + str(r.status_code) + r.reason)
67
68
        return r.status_code, r.json()
69
70
"""
71
def zipOrthanc(endpoint):
72
    query = orthanc_url + '/studies/' + orthanc_study_id + '/archive'
73
    response_study = requests.get(query, verify=False, \
74
                                  auth=(orthanc_user, orthanc_password))
75
    if response_study.status_code != 200:
76
        print
77
        'Problem retrieving study: ' + orthanc_study_id
78
        print
79
        response_study.status, response_study.reason
80
        continue
81
    print
82
    '   Retrieved: %s' % orthanc_study_id
83
    zip_content = response_study.content
84
85
    file_like_object = io.BytesIO(zip_content)
86
    zip_object = zipfile.ZipFile(file_like_object)
87
    for zip_name in zip_object.namelist():
88
        zip_object.extract(zip_name, some_destination_dir)
89
"""
0 ignored issues
show
Unused Code introduced by
This string statement has no effect and could be removed.
Loading history...