Passed
Pull Request — master (#3)
by Yang
05:59
created

Python.LORIS.candidates   A

Complexity

Total Complexity 41

Size/Duplication

Total Lines 293
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 41
eloc 166
dl 0
loc 293
rs 9.1199
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A LORIS_candidates.parse_PSCID() 0 27 5
A LORIS_candidates.check_instutitionID_compliance() 0 10 2
A LORIS_candidates.check_PSCID_compliance() 0 32 5
A LORIS_candidates.check_DCCID() 0 17 5
A LORIS_candidates.check_subjectID_compliance() 0 9 4
A LORIS_candidates.check_projectID_compliance() 0 15 2
A LORIS_candidates.deleteCandidateCNBP() 0 40 2
A LORIS_candidates.createCandidateCNBP() 0 36 4
B LORIS_candidates.checkDCCIDExist() 0 34 5
B LORIS_candidates.checkPSCIDExist() 0 45 7

How to fix   Complexity   

Complexity

Complex classes like Python.LORIS.candidates often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
import sys
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 os
3
import re
4
import json
5
import logging
6
from dotenv import load_dotenv
7
from LORIS.query import LORIS_query
0 ignored issues
show
introduced by
Unable to import 'LORIS.query'
Loading history...
8
from LORIS.helper import LORIS_helper
0 ignored issues
show
introduced by
Unable to import 'LORIS.helper'
Loading history...
9
from LocalDB.schema import CNBP_blueprint
0 ignored issues
show
Bug introduced by
The name schema does not seem to exist in module LocalDB.
Loading history...
introduced by
Unable to import 'LocalDB.schema'
Loading history...
10
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
11
logger = logging.getLogger(__name__)
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...
12
13
class LORIS_candidates:
0 ignored issues
show
Coding Style Naming introduced by
The name LORIS_candidates does not conform to the class naming conventions ([A-Z_][a-zA-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...
Coding Style introduced by
This class 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...
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
14
15
    @staticmethod
16
    def parse_PSCID(PSCID):
0 ignored issues
show
Coding Style Naming introduced by
The name parse_PSCID does not conform to the method 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...
Coding Style Naming introduced by
The name PSCID does not conform to the argument 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...
17
        """
18
        Return three parts of the PSCID: institution, project, subject
19
        :param PSCID:
20
        :return:
21
        """
22
        success = load_dotenv()
23
        if not success:
24
            raise ImportError("Credential .env NOT FOUND! Please ensure .env is set with all the necessary credentials!")
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (121/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
25
26
        # Loading regular expression
27
        re_institution = CNBP_blueprint.PSCID_schema_institution
28
        re_project = CNBP_blueprint.PSCID_schema_project
29
        re_subject = CNBP_blueprint.PSCID_schema_subject
30
31
        # Use expression to extract from the inputted PSCID
32
        input_institution = re.search(re_institution, PSCID).group(0)
33
        input_project = re.search(re_project, PSCID).group(0)
34
        input_subject = re.search(re_subject, PSCID).group(0)
35
36
        if input_subject is None or input_project is None or input_institution is None:
37
            success = False
38
        else:
39
            success = True
40
41
        return success, input_institution, input_project, input_subject
42
43
    @staticmethod
44
    def check_instutitionID_compliance(input_institutionID):
0 ignored issues
show
Coding Style Naming introduced by
The name check_instutitionID_compliance does not conform to the method 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...
Coding Style Naming introduced by
The name input_institutionID does not conform to the argument 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...
Coding Style introduced by
This method 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...
45
        # Parse from the .env standardization
46
        InsitituionID = os.getenv("institutionID")
0 ignored issues
show
Coding Style Naming introduced by
The name InsitituionID 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...
47
48
        # Check if institution ID matches
49
        if not (input_institutionID == InsitituionID):
0 ignored issues
show
Unused Code Coding Style introduced by
There is an unnecessary parenthesis after not.
Loading history...
unused-code introduced by
Unnecessary "else" after "return"
Loading history...
50
            return False
51
        else:
52
            return True
53
54
    @staticmethod
55
    def check_projectID_compliance(input_projectID):
0 ignored issues
show
Coding Style Naming introduced by
The name check_projectID_compliance does not conform to the method 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...
Coding Style Naming introduced by
The name input_projectID does not conform to the argument 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...
Coding Style introduced by
This method 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...
56
57
        # Load ProjectIDs from the environment.
58
        success = load_dotenv()
59
        if not success:
60
            raise ImportError("Credential .env NOT FOUND! Please ensure .env is set with all the necessary credentials!")
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (121/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
61
62
        projectID_dictionary_json: str = os.getenv("projectID_dictionary")
0 ignored issues
show
Coding Style Naming introduced by
The name projectID_dictionary_json 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...
63
        projectID_list = json.loads(projectID_dictionary_json)
0 ignored issues
show
Coding Style Naming introduced by
The name projectID_list 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...
64
65
        # check if project ID is in the projectID list.
66
        isRecognized = input_projectID in projectID_list
0 ignored issues
show
Coding Style Naming introduced by
The name isRecognized 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...
67
68
        return isRecognized
69
70
    @staticmethod
71
    def check_subjectID_compliance(input_subjectID):
0 ignored issues
show
Coding Style Naming introduced by
The name check_subjectID_compliance does not conform to the method 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...
Coding Style Naming introduced by
The name input_subjectID does not conform to the argument 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...
Coding Style introduced by
This method 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...
72
        if not input_subjectID.isdigit():
73
            return False
74
75
        if int(input_subjectID) < 9999 or int(input_subjectID) > 0:
0 ignored issues
show
Unused Code introduced by
The if statement can be replaced with 'return bool(test)'
Loading history...
unused-code introduced by
Unnecessary "else" after "return"
Loading history...
76
            return True
77
        else:
78
            return False
79
80
    @staticmethod
81
    def check_PSCID_compliance(PSCID):
0 ignored issues
show
Coding Style Naming introduced by
The name check_PSCID_compliance does not conform to the method 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...
Coding Style Naming introduced by
The name PSCID does not conform to the argument 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...
82
        """
83
        Checks PSCID inputed for 1) InstitionID format, 2) ProjectID format, 3) SubjectID format.
84
        :param PSCID:
85
        :return:
86
        """
87
        logger = logging.getLogger(__name__)
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 11).

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...
88
89
        # Parse from input PSCID
90
        success, input_institution, input_project, input_subject = LORIS_candidates.parse_PSCID(PSCID)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (102/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
91
92
        # Ensure parsing success
93
        if not success:
94
            return False
95
96
        # Check institution ID to ensure that
97
        if not LORIS_candidates.check_instutitionID_compliance(input_institution):
98
            logger.info("Institution not compliant")
99
            return False
100
101
        # Check if projectID already exist
102
        if not LORIS_candidates.check_projectID_compliance(input_project):
103
            logger.info("ProjectID not recognized")
104
            return False
105
106
        # Check last four digits: make sure the last four characters are digits.
107
        if not LORIS_candidates.check_subjectID_compliance(str(input_subject)):
108
            logger.info("SubjectID not standardized")
109
            return False
110
111
        return True
112
113
    @staticmethod
114
    def check_DCCID(DCCID):
0 ignored issues
show
Coding Style Naming introduced by
The name check_DCCID does not conform to the method 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...
Coding Style Naming introduced by
The name DCCID does not conform to the argument 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...
115
        """
116
        Check if DCCID id conform.
117
        :param DCCID:
118
        :return:
119
        """
120
        if not len(str(DCCID)) == 6:
0 ignored issues
show
unused-code introduced by
Unnecessary "else" after "return"
Loading history...
Unused Code introduced by
Consider changing "not len(str(DCCID)) == 6" to "len(str(DCCID)) != 6"
Loading history...
121
            return False
122
        elif not str(DCCID).isnumeric():
123
            return False
124
        elif DCCID > 999999:
125
            return False
126
        elif DCCID < 0:
127
            return False
128
        else:
129
            return True
130
131
    @staticmethod
132
    def deleteCandidateCNBP(DCCID, PSCID):
0 ignored issues
show
Coding Style Naming introduced by
The name deleteCandidateCNBP does not conform to the method 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...
Coding Style Naming introduced by
The name DCCID does not conform to the argument 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...
Coding Style Naming introduced by
The name PSCID does not conform to the argument 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...
Coding Style introduced by
This method 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...
133
        # todo: this should really be done through API. But Currently LORIS does not offer such API.
134
        # NOTE! If you EVER get NULL coalesce not recognized error, make sure that the PHP version being called from
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (116/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
135
        # the SSH session is 7+ or else. We had a major issue where the PHP version from SSH session being LOWER
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (112/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
136
        # than the bashrc profile imported edition. Also keep in mind that EVEN if .bashrc import this, it MOST LIKELY
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (118/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
137
        # will not apply to the SSH session!
138
139
        # Load the credential variables.
140
        success = load_dotenv()
141
        if not success:
142
            raise ImportError("Credential .env NOT FOUND! Please ensure .env is set with all the necessary credentials!")
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (121/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
143
        ProxyIP = os.getenv("ProxyIP")
0 ignored issues
show
Coding Style Naming introduced by
The name ProxyIP 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...
144
        ProxyUsername = os.getenv("ProxyUsername")
0 ignored issues
show
Coding Style Naming introduced by
The name ProxyUsername 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...
145
        ProxyPassword = os.getenv("ProxyPassword")
0 ignored issues
show
Coding Style Naming introduced by
The name ProxyPassword 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...
146
        LORISHostPassword = os.getenv("LORISHostPassword")
0 ignored issues
show
Coding Style Naming introduced by
The name LORISHostPassword 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...
147
        LORISHostUsername = os.getenv("LORISHostUsername")
0 ignored issues
show
Coding Style Naming introduced by
The name LORISHostUsername 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...
148
        LORISHostIP = os.getenv("LORISHostIP")
0 ignored issues
show
Coding Style Naming introduced by
The name LORISHostIP 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...
149
        DeletionScript = os.getenv("DeletionScript")
0 ignored issues
show
Coding Style Naming introduced by
The name DeletionScript 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...
150
151
        # NOTE! If you EVER get NULL coalesce not recognized error, make sure that the PHP version being called from
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (116/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
152
        # the SSH session is 7+ or else. We had a major issue where the PHP version from SSH session being LOWER
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (112/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
153
        # than the bashrc profile imported edition. Also keep in mind that EVEN if .bashrc import this, it MOST LIKELY
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (118/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
154
        # will not apply to the SSH session!
155
156
        command_string = "/opt/rh//rh-php70/root/usr/bin/php " + DeletionScript + " delete_candidate " + str(DCCID) + " " + PSCID + " confirm"
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (142/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
157
158
159
160
        logger.info(command_string)
161
162
        # Establish connection to client.
163
        Client = LORIS_helper.getProxySSHClient(ProxyIP, ProxyUsername, ProxyPassword, LORISHostIP, LORISHostUsername,
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (118/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
Coding Style Naming introduced by
The name Client 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...
164
                                                LORISHostPassword)
165
166
        # Execute the command
167
        LORIS_helper.triggerCommand(Client, command_string)
168
169
        # Close the client.
170
        Client.close()
171
172
173
    @staticmethod
174
    def createCandidateCNBP(token, proposed_PSCID):
0 ignored issues
show
Coding Style Naming introduced by
The name createCandidateCNBP does not conform to the method 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...
Coding Style Naming introduced by
The name proposed_PSCID does not conform to the argument 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...
175
        """
176
        Create a candidate using the given PSCID
177
        :param token
178
        :param proposed_PSCID:
179
        :return: DCCID
180
        """
181
        logger = logging.getLogger('LORIS_CreateCNBPCandidates')
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 11).

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...
182
        logger.info("Creating CNBP Candidates: " + proposed_PSCID)
183
184
        _, PSCID_exist = LORIS_candidates.checkPSCIDExist(token, proposed_PSCID)
0 ignored issues
show
Coding Style Naming introduced by
The name PSCID_exist 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...
185
        if PSCID_exist:
186
            logger.info("PSCID already exist. Quitting.")
187
            return False ,None
0 ignored issues
show
Coding Style introduced by
No space allowed before comma
Loading history...
Coding Style introduced by
Exactly one space required after comma
Loading history...
188
189
        Candidate = {}
0 ignored issues
show
Coding Style Naming introduced by
The name Candidate 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...
190
        Candidate['Project'] = 'loris'
191
        Candidate['PSCID'] = proposed_PSCID
192
        Candidate['DoB'] = '2018-05-04'
193
        Candidate['Gender'] = 'Female'
194
195
        data = {"Candidate":Candidate}
196
197
        data_json = json.dumps(data)
198
199
        response_code, response = LORIS_query.postCNBP(token, "candidates/", data_json)
200
        if not LORIS_helper.is_response_success(response_code, 201):
0 ignored issues
show
unused-code introduced by
Unnecessary "else" after "return"
Loading history...
201
            return False, None
202
        elif response is not None:  # only try to decode if response is not empty!
203
            response_json = response.json()
204
            meta = response_json.get('Meta')
205
            CandID = meta.get('CandID')
0 ignored issues
show
Coding Style Naming introduced by
The name CandID 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...
206
            return True, CandID
207
        else:
208
            return False, None
209
210
    @staticmethod
211
    def checkPSCIDExist(token, proposed_PSCID):
0 ignored issues
show
Coding Style Naming introduced by
The name checkPSCIDExist does not conform to the method 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...
Coding Style Naming introduced by
The name proposed_PSCID does not conform to the argument 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...
212
        """
213
        Check if Site/Study already contain the PSCID
214
        :param token:
215
        :param proposed_PSCID:
216
        :return: bool for connection, bool on if such PSCID (INSTITUTIONID + PROJECTID + SUBJECTID) exist already.
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (114/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
217
        """
218
        logger = logging.getLogger('LORIS_checkPSCIDExist')
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 11).

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...
219
        logger.info("Checking if PSCID exist: "+proposed_PSCID)
220
        success = load_dotenv()
221
        if not success:
222
            raise ImportError("Credential .env NOT FOUND! Please ensure .env is set with all the necessary credentials!")
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (121/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
223
        institution_check = os.getenv("institutionID")
224
225
226
        #Get list of projects
227
        response_success, loris_project = LORIS_query.getCNBP(token, r"projects/loris")
228
        if not response_success:
229
            return response_success, None
230
231
        #Get list of candidates (Candidates in v0.0.1)
232
        candidates = loris_project.get("Candidates")
233
        logger.info(candidates)
234
235
        for DCCID in candidates: #these candidates should really be only from the same ID regions.
0 ignored issues
show
Coding Style Naming introduced by
The name DCCID 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...
236
            response_success, candidate_json = LORIS_query.getCNBP(token, r"candidates/"+DCCID)
237
            if not response_success:
238
                return response_success, False
239
            # Each site following the naming convention should have SITE prefix and PI prefix and PROJECT prefix to avoid collision
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (131/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
240
241
            # A site check here.
242
            candidate_meta = candidate_json.get("Meta")
243
            candidate_pscID = candidate_meta.get("PSCID")
0 ignored issues
show
Coding Style Naming introduced by
The name candidate_pscID 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...
244
245
            # Not gonna check is institution ID doesn't even match.
246
            if candidate_pscID[0:3] != institution_check:
247
                continue
248
249
            elif candidate_pscID == proposed_PSCID:
250
                return response_success, True
251
252
                #latest_timepoint = findLatestTimePoint(DCCID)
253
254
        return True, False
255
256
    @staticmethod
257
    def checkDCCIDExist(token, proposed_DCCID):
0 ignored issues
show
Coding Style Naming introduced by
The name checkDCCIDExist does not conform to the method 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...
Coding Style Naming introduced by
The name proposed_DCCID does not conform to the argument 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...
258
        """
259
        Check if Site/Study already contain the PSCID
260
        :param token:
261
        :param proposed_DCCID:
262
        :return:
263
        """
264
        logger = logging.getLogger('LORIS_checkDCCIDExist')
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 11).

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...
265
        logger.info("Checking if DCCID exist: "+str(proposed_DCCID))
266
        success = load_dotenv()
267
        if not success:
268
            raise ImportError("Credential .env NOT FOUND! Please ensure .env is set with all the necessary credentials!")
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (121/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
269
270
        assert (LORIS_candidates.check_DCCID(proposed_DCCID))
0 ignored issues
show
Unused Code Coding Style introduced by
There is an unnecessary parenthesis after assert.
Loading history...
271
272
        #Get list of projects
273
        response, loris_project = LORIS_query.getCNBP(token, r"projects/loris")
274
        response_success = LORIS_helper.is_response_success(response, 200)
275
276
        if not response_success:
277
            logger.info("FAILED log response: " + str(response))
278
            return response_success, None
279
280
        #Get list of candidates (Candidates in v0.0.1)
281
        candidates = loris_project.get("Candidates")
282
        logger.info(candidates)
283
284
        for DCCID in candidates:
0 ignored issues
show
Coding Style Naming introduced by
The name DCCID 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...
285
            if str(proposed_DCCID) == DCCID:
286
                return response_success, True
287
            else:
288
                continue
289
        return response_success, False
290
291
if __name__ == "__main__":
292
    LORIS_candidates.deleteCandidateCNBP(958607, "CNBP8881234")
293
    #print(LORIS_candidates.check_projectID_compliance("GL01"))
0 ignored issues
show
Coding Style introduced by
Final newline missing
Loading history...